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"
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
pageinstead ofcontextas Artillery doesn't exposecontext.So:
page.setExtraHTTPHeadersbutpage.routeinstead;route.fulfillinstead ofroute.continue, as I don't thinkroute.continueis working well, from what I tested;Again, just setting expectations - it's a workaround and might not fully work, depending on how your Playwright code actually works.