-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
[Question] Any way to pass playwright.config.js configuration to custom context, page worker fixtures? #7267
Comments
@radekBednarik I did not follow this. Can you please explain in more details? |
@aslushnikov hello, ofc. Now, let's say, that I want to do two tests on the page. These tests are not dependent whatsoever, and I want therefore use beforeAll hook to set the state (open context, page, goto url) and then do these tests WITHOUT unnecessary repeating those steps twice. Default context and page fixtures will not help me, since they cannot be used in beforeAll hook. Since I do not know how to override their scope, I created my custom context and page fixtures with worker scope. However, they do not use the settings from global configuration file. Is it maybe due to naming , because context and page are reserved and I cannot redefine the fixture? |
@radekBednarik Thank you for the explanation, this makes sense. Your custom fixtures will not pick up context options because these options are used manually in the const test = base.test.extend({
myContextOptions: [ {}, { scope: "worker" } ],
myContext: [
async ({ browser, myContextOptions }, use) => {
const myContext = await browser.newContext(myContextOptions);
await use(myContext);
},
{ scope: "worker", auto: true },
],
}); Then set module.exports = {
use: {
myContextOptions: {
// Any context options work here, since this object is passed directly to myContext fixture
hasTouch: true,
ignoreHTTPSErrors: true,
},
},
}; Does this help? |
@dgozman thank you, yes, that is, what I needed. I would suggest, that maybe this should be mentioned in the documentation? Thanks again. |
I am glad this helps! We are working on the documentation indeed 😄 |
@dgozman Would you please post a simple config file and spec file to demonstrate how I can have "page" in beforeAll that takes all the config values from the config file? This will be much appreciated! |
Hello,
is it possible to pass configuration from
playwright.config.js
to custom context and page worker fixtures? Or do I have to manually specify properties of those in the fixture definition (which is a bit cumbersome?).The use case behind this is to have the page loaded only once for tests, since there is no need to create context, page for each test.
Code example:
The text was updated successfully, but these errors were encountered: