You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the "Testing" editor panel under the "Playwright" heading, make sure the "Show browser" option is checked.
Using the "Testing" editor panel, run all tests in the "withoutFixture.spec.js" file, and verify that the tests pass and that the browser used by the test is visible.
Using the same panel, run all tests in the "withFixture.spec.js" file.
Expected behavior
"test with extended browser fixture" should pass, as it is an identical copy of "test with no custom fixtures" which already passed.
Actual behavior
The error TypeError: browser._newContextForReuse is not a function is outputted to the console when trying to run the tests in the "withFixture.spec.js" file while "Show browser" is enabled.
Additional context
This is a minimal reproduction of a test suite in our company, which recently started taking advantage of custom Playwright fixtures. One of the custom fixtures intercepts requests by calling context.route(...), and to make sure this happens globally, the base browser fixture is extended so any newly created browser contexts also call context.route(...). However, after implementing this fixture, it was no longer possible to use the "Show browser" option when running tests via VSCode. Running tests via the command line using the --headed option seems to be unaffected.
In your fixture, you're doing { ...browser } to create a copy of the browser object. This doesn't work as you expect it to work. The resulting object has all the instance properties of browser, but it doesn't have the same prototype so the class functions aren't available.
You could fix this by mangling with the prototypes, but I think the easier solution is to override the context and page fixtures directly:
import{testasbaseTest}from"@playwright/test";/** The Playwright test function but with the context and page objects extended. */exportconsttest=baseTest.extend({asynccontext({ context },use){// Do stuff on the contextawaituse(context);},asyncpage({ page },use){// Do stuff on the pageawaituse(page);},});
Version
1.49.1
Steps to reproduce
npm install
in the terminal.Expected behavior
"test with extended browser fixture" should pass, as it is an identical copy of "test with no custom fixtures" which already passed.
Actual behavior
The error
TypeError: browser._newContextForReuse is not a function
is outputted to the console when trying to run the tests in the "withFixture.spec.js" file while "Show browser" is enabled.Additional context
This is a minimal reproduction of a test suite in our company, which recently started taking advantage of custom Playwright fixtures. One of the custom fixtures intercepts requests by calling
context.route(...)
, and to make sure this happens globally, the basebrowser
fixture is extended so any newly created browser contexts also callcontext.route(...)
. However, after implementing this fixture, it was no longer possible to use the "Show browser" option when running tests via VSCode. Running tests via the command line using the--headed
option seems to be unaffected.Environment
The text was updated successfully, but these errors were encountered: