playwright icon indicating copy to clipboard operation
playwright copied to clipboard

[Question] Global setup API request context can use the browser.cotext.setHTTPHeaders?

Open ValorHeart opened this issue 3 years ago • 0 comments

Hello! So I'm enriching browser HTTP headers using fixture override like so:

context: async ({ context }, use) => {
      await context.setExtraHTTPHeaders(headers);
    await use(context);
},

This also creates a new APIRequestContext for use with the page.request API, but it doesn't affect the global { request } imported from @playwright/test which I'm not sure where it initializes from, right?

I want to create a Global Setup to store storageState.json and share it between my isolated tests.

Following this guide: https://playwright.dev/docs/auth#sign-in-via-api-request importing { request } imported from @playwright/test won't use my HTTP headers enrichment of the browser.context previously made, right?

I'll be glad to have assistance regarding if is it possible to use the same extraHttpHeaders with the global setup file that i've used during the fixture override.

More information about how i receive my headers: the fixture override get it's headers from custom option defintion that extends at the playwright.config.ts. , like so: fixture.ts: headersForMyCase: [{ use: false, headers: {} }, { option: true }], playwright.config.ts:

const globalConfig: PlaywrightTestConfig<CustomOptions> = {
use {
headersForMyCase = {
        use: true,
        headers: {
          'x-riskified-dynamicenv': process.env.DYNAMIC_ENV_HEADER,
        },
      };
}

ValorHeart avatar Dec 08 '22 11:12 ValorHeart