debug Playwright driver
November 6, 2024
We may encounter the following errors when running Playwright tests:
If the error can be reproduce locally but no obvious issues can be identified, you can follow this article to debug the InjectedScript in the browser that drives by Playwright.
The main working principle of Playwright is to inject JavaScript code into the browser, communicate with the Node layer (test code + Playwright server driver) to drive the browser, and simulate user behavior.
We can debug the server side code like debugging a normal Node process. For the injected code in the browser, please follow the following steps:
-
Run Playwright tests with headless mode off and env var
PWTEST_UNDER_TEST = 1
-
In the browser that brought by playwright, open devtools / console,print & show function definition of
__injectedScript.constructor
-
Set break point that you wishes to debug, like
checkElementStates
: