Playwright debug test to not close browser

Har*_*rry 7 visual-studio-code playwright

I'm using playwright and vscode, especially the "debug test" function which pops up a real browser window to run the test. When it fails the test auto closes, how can I make it not auto close so that I can modify the test and also visually see what the state of the test is?

小智 2

我发现在这种情况下有两件事很有帮助:

  1. 在失败的测试之前立即放置一个page.pause()将导致调试器在那里中断,以便您可以检查应用程序的状态;

  2. Playwright 的跟踪功能非常可爱,可以让您在每个阶段、之前/之后看到应用程序的快照,包括屏幕图像、突出显示失败的测试以及许多其他有用的数据……所以如果您不期待测试如果失败,或者可能只是间歇性失败,您可以使用跟踪来查看失败精确时刻的状态。