PlaywrightException:连接已关闭(System.Threading.ThreadAbortException:系统错误 - 仅在调试时

Lie*_*ero 5 .net c# playwright .net-6.0 visual-studio-2022

我有一些用 MS Test 2 框架编写的 UI 测试。

\n

当我从 Visual Studio 2022 的测试资源管理器运行测试时,测试运行良好。

\n

当我尝试调试测试时,我得到:

\n
Microsoft.Playwright.PlaywrightException: Connection closed (System.Threading.ThreadAbortException: System error.\n   at System.IO.Strategies.BufferedFileStreamStrategy.WriteToNonSeekableAsync(ReadOnlyMemory`1 source, CancellationToken cancellationToken)\n   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)\n   at System.IO.Strategies.BufferedFileStreamStrategy.WriteToNonSeekableAsync(ReadOnlyMemory`1 source, CancellationToken cancellationToken)\n   at System.IO.Strategies.BufferedFileStreamStrategy.WriteAsync(ReadOnlyMemory`1 buffer, CancellationToken cancellationToken)\n   at System.IO.FileStream.WriteAsync(ReadOnlyMemory`1 buffer, CancellationToken cancellationToken)\n   at Microsoft.Playwright.Transport.StdIOTransport.SendAsync(String message))\n\n  Stack Trace:\xe2\x80\x89\nConnection.SendMessageToServerAsync[T](String guid, String method, Object args)\nFrame.WaitForFunctionAsync(String expression, Object arg, FrameWaitForFunctionOptions options)\nMyTest.MyAsyncMethod()\xe2\x80\x89line\xe2\x80\x8923\nThreadOperations.ExecuteWithAbortSafety(Action action)\n
Run Code Online (Sandbox Code Playgroud)\n

在以下对 WaitForFunctionAsync 的调用中:

\n
Microsoft.Playwright.PlaywrightException: Connection closed (System.Threading.ThreadAbortException: System error.\n   at System.IO.Strategies.BufferedFileStreamStrategy.WriteToNonSeekableAsync(ReadOnlyMemory`1 source, CancellationToken cancellationToken)\n   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)\n   at System.IO.Strategies.BufferedFileStreamStrategy.WriteToNonSeekableAsync(ReadOnlyMemory`1 source, CancellationToken cancellationToken)\n   at System.IO.Strategies.BufferedFileStreamStrategy.WriteAsync(ReadOnlyMemory`1 buffer, CancellationToken cancellationToken)\n   at System.IO.FileStream.WriteAsync(ReadOnlyMemory`1 buffer, CancellationToken cancellationToken)\n   at Microsoft.Playwright.Transport.StdIOTransport.SendAsync(String message))\n\n  Stack Trace:\xe2\x80\x89\nConnection.SendMessageToServerAsync[T](String guid, String method, Object args)\nFrame.WaitForFunctionAsync(String expression, Object arg, FrameWaitForFunctionOptions options)\nMyTest.MyAsyncMethod()\xe2\x80\x89line\xe2\x80\x8923\nThreadOperations.ExecuteWithAbortSafety(Action action)\n
Run Code Online (Sandbox Code Playgroud)\n

仅当在调用之前命中断点时才会发生该错误。

\n

我在 QuerySelectorAsync() 中遇到了类似的行为。

\n

如何调试剧作家测试?!

\n