-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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]: error TS2339: Property 'waitForEvent' does not exist on type 'SuiteFunction' #7857
Comments
There is something strange with your |
Hey @dgozman I'm doing the following with the context: describe('My Tests', () => {
let page: Page;
let pageTabOne: Page;
beforeAll(async () => {
const context = await browser.newContext({
ignoreHTTPSErrors: true,
bypassCSP: true,
recordVideo: recordVideo,
});
await getContext.contextUtil(context);
page = await context.newPage();
pageTabOne = await context.newPage();
}
); and async function contextUtil(context:any) {
const cookies = process.env.COOKIES;
const localStorage = process.env.LOCALSTORAGE;
await context.addCookies(JSON.parse(cookies));
await context.addInitScript(([storageDump]) => {
if (window.location.hostname === 'mysite.com') {
console.log(window.location.hostname);
console.log(storageDump.length);
const entries = JSON.parse(storageDump);
Object.keys(entries).forEach(k => {
window.localStorage.setItem(k, entries[k]);
});
}
}, [localStorage]);
}
module.exports = {contextUtil}; This was all working fine until recently. |
I'm trying the '@playwright/test' runner for the first time now and I'm not running into those issues with it. So it seems related to jest-playwright? |
If you are using jest-playwright, then you can pass the context options in the config, see here: https://github.com/playwright-community/jest-playwright#options Also a browser, context, and page instance is available in every file, since its on the global scope. Its also persistent through the tests per file, so a single page instance gets shared between the tests. In comparison to @playwright/test where a new context and by that a new page gets created for each test. For Playwright Test, you can pass the options also in the config, see here: https://playwright.dev/docs/test-configuration#more-browser-and-context-options. I saw you are migrating, so please let us know if you are still facing the issues, my guess would be that your manual created context conflicts with the global context, so I would either recommend renaming or using the context from Playwright Test. Another nit: instead of using (Feel free to mention me in a migration PR, then I can also review it and give recommendations if you are interested) |
@mxschmitt thanks for those insights, now I have a couple things to try. Will let you know how it goes. However I'm a bit confused with @playwright/test creating a new context / page for each test. I do not see a config option to change that behavior. I asked that here: #7882. |
You can do that with Playwright Test too, this would mean:
You can't disable it currently. Keep in mind, that when doing that, you will loose all the Playwright Test goodies, which means, no video, no screenshot on failure, no tracing out of the box etc. (We are working on providing support for that too.) If you want to do it at more a larger scale, I would recommend to use a worker fixture for your page instance instead, see here. |
@mxschmitt right right, that's actually what I did already and it works, test #1 and #2 can run after each other and share the same page. However the problem is that if any test fails the page closes (even though it's a However this is sidetracking us, it's really #7882 (: |
@mxschmitt & @dgozman it's really the new page pattern that doesn't work for me (back to jest-playwright)... everything else does. const [newPage] = await Promise.all([
context.waitForEvent('page'),
page.click('css=[aria-label*="XXX"] >> css=[title="Open in Browser"]'),
]) It's not a problem with @playwright/test. I tried following your advice so now I set the context config in const context = await browser.newContext(browserContextOptions);
await getContext.contextUtil(context);
page = await context.newPage(); Yet whenever playwright gets to my file with the Is there another pattern to get the page of a new tab opened from the main Page of the tests? |
@mxschmitt Ok so with @playwright/test I'm getting the error at runtime (
|
@VincentDondain so the issues are resolved and we can close it if I understood it correctly? (In the future we might add page per file to support your use-case better) |
@mxschmitt correct, I verified it and it works. Only #7857 (comment) remains but that's what #7882 is all about (; Thank for the help and valuable info you provided ❤️ |
Playwright version
1.13.0
Operating system
MacOS
What browsers are you seeing the problem on?
Chromium
Other information
What happened? / Describe the bug
When running the tests locally I'm getting these error TS2339: Property 'waitForEvent' does not exist on type 'SuiteFunction' whenever there is this
context.waitForEvent('page'),
in thePromise.All
.This used to work and is the documented way of handling new pages: https://playwright.dev/docs/multi-pages/#handling-new-pages.
Not sure what's wrong (:
Code snippet to reproduce your bug
Relevant log output
The text was updated successfully, but these errors were encountered: