I am intercepting a network request beforeEach
test while doing playwright component testing.
Here are my 2 test cases they run fine but if I put like 8 cases ( btn1, btn2, btn3, btn4 ... btn8) it gets timeout until 6 test cases it works but not 8 of them work without getting a timeout exceeded error, each button click event here fires an api request.
Here is what I am doing after each api call I am waiting for network to be idle before I fire another call.
test.beforeEach(async ({ page }) => {
let requestURL;
await page.route('/abcd/sax/**', async (route) => {
requestURL = route.request().url();
route.continue();
});
await page.waitForLoadState('networkidle');
});
test('PRODUCT SHARE CLICK EVENT', async ({ page }) => {
await page.locator('[data-auto-id="btn1"]').click();
expect(requestURL).toContain('SHARE');
});
test('SIZE CHANGE EVENT', async ({ page }) => {
await page.locator('[data-auto-id="BTN2"]').click();
await expect(requestURL).toContain('SIZE');
});
Approaches I have tried already here are updating the playwright config to increase the timeout property to timeout: 10 * 3000,
also by passing additional parameter to
await page.waitForLoadState('networkidle',{ timeout: 40000 });
None of them seems to work I still get timeout, maybe the approach I am using to intercept the network call while on button click in each test can be optimised but I am not sure how?