New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] custom selector engines throw when running tests with --debug flag #20424
Comments
I can repro. |
Custom selector engines should be registered before the page is created, otherwise the behavior is racy. In this particular example they happen to be pushed into the page in non-debug mode quite late (when click is executed) but in the debug mode the order changes and registered selectors are propagated into the page earlier (before you register the custom one). Recommended solution in this case is to register the selector in beforeAll: import { test } from '@playwright/test';
const createTagNameEngine = () => ({
query(root, selector) {
return root.querySelector(selector);
},
queryAll(root, selector) {
return Array.from(root.querySelectorAll(selector));
},
});
test.beforeAll(({ playwright }) => playwright.selectors.register("tag", createTagNameEngine));
test("selector engine test", async ({ page }) => {
await page.setContent(`<div><button>Click me</button></div>`);
await page.locator("tag=button").click();
}); Does this work for you? |
This works great! Thank you very much :) |
System:
Binaries:
Languages:
npmPackages:
Code Snippet
npx playwright test ./bug.spec.js --debug
Description
Running the command above and continuing the test in the debugger yields the following error:
A similar problem was described in #16665 so this might be considered a regression
The text was updated successfully, but these errors were encountered: