0

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?

Divyanshu Rawat
  • 4,421
  • 2
  • 37
  • 53
  • What timeout error are you getting? Also, requestURL is defined in the beforeEach there, and thus wouldn’t be accessible by the tests, so I’m confused as to how those tests were passing. Can you verify that is the code that passes or whether there’s anything missing? – David R Mar 09 '23 at 05:24
  • Hi @DavidR thanks for writing, requestURL is working fine its accessible within the variables declared as a part of beforeEach are accessible in test. – Divyanshu Rawat Mar 09 '23 at 09:12
  • is this JavaScript? As based off the code you provided, because of scope, it’s not possible for the test callback function to have access to a variable declared with let inside the beforeEach callback, which is why I was confused and asked But either way, could you provide the timeout error you’re getting? – David R Mar 09 '23 at 09:34
  • @DavidR thanks for helping out it is resolved by increasing the no. of re-tries in playwright component testing configuration file. – Divyanshu Rawat Mar 10 '23 at 15:54

0 Answers0