How to set Google IAP Header in Artillery Playwright test?

166 Views Asked by At

I have an Artillery test script for a Playwright browser test:

config:
  target: https://website.dev
  # Load the Playwright engine:
  engines:
    playwright:
      launchOptions:
        headless: false
  processor: "./test.js"
scenarios:
  - engine: playwright
    testFunction: "test"

Based on docs they suggest setting headers in the script but I need to fetch Google IAP details first so that won't work.

I have tried two different Playwright functions to set headers but the test always fails unless I comment out the header logic. So how am I supposed to apply headers? I have two functions for setting headers here just to show what I used, tried them both separately.

The test:

module.exports = { test };
const { getIAPToken } = require('./IAP.js');

async function test(page) {

    const token = await getIAPToken('client_id')


    await page.setExtraHTTPHeaders({
        'Proxy-Authorization': token,
    });

       // Intercept and modify network requests
       await page.route('**', (route) => {
        const headers = {
            'Proxy-Authorization': `${token}`,
        };
        route.continue({ headers });
    });


    await page.goto("https://website.dev/");
}

Test error:

page.goto: net::ERR_INVALID_ARGUMENT at https://website.dev/
=========================== logs ===========================
navigating to "https://website.dev/", waiting until "load"
1

There are 1 best solutions below

2
bernardobridge On

This is actually a Playwright/Chrome issue, and Playwright hasn't really addressed it yet: https://github.com/microsoft/playwright/issues/11967

The workaround mentioned here: https://github.com/microsoft/playwright/issues/11967#issuecomment-1646275086 might work, but you'll have to use page instead of context as Artillery doesn't expose context.

So:

  • don't use page.setExtraHTTPHeaders but page.route instead;
  • use route.fulfill instead of route.continue, as I don't think route.continue is working well, from what I tested;
  • I'd also recommend screening to only setting the headers to the URLs that actually need it.

Again, just setting expectations - it's a workaround and might not fully work, depending on how your Playwright code actually works.