Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] Intermittent waitForResponse timeouts when looping #4806

Closed
LA1CH3 opened this issue Dec 22, 2020 · 1 comment
Closed

[Question] Intermittent waitForResponse timeouts when looping #4806

LA1CH3 opened this issue Dec 22, 2020 · 1 comment

Comments

@LA1CH3
Copy link

LA1CH3 commented Dec 22, 2020

Hi, I am trying to use Playwright to automate visiting some webpages and validate that certain analytics files are loaded and contain proper values in their URLs. It is working somewhat- every time I run, I am getting several of the following error, though it seems to happen at random:

(node:1485) UnhandledPromiseRejectionWarning: TimeoutError: Timeout while waiting for event "response"
Note: use DEBUG=pw:api environment variable and rerun to capture Playwright logs.

Sometimes it will work successfully, other times it will work successfully for all but one of the tags. Here is my code for reference. Let me know if there is something I am doing wrong here that could be causing this.

import { chromium } from "playwright";

import pages from "./pages";

(async () => {
  pages.forEach(async (pageConfig) => {
    pageConfig.tags.forEach(async ({ name, pattern, ...rest }) => {
      const browser = await chromium.launch();
      const context = await browser.newContext();
      const page = await context.newPage();
      await page.goto(pageConfig.path);

      const response = await page.waitForResponse(pattern, { timeout: 20000 });

      if (Object.keys(rest).length) {
        const tagsMet = Object.values(rest).every((tagValue) => {
          return response.url().includes(tagValue);
        });

        if (tagsMet) {
          console.log(`${pageConfig.path}:${name}:PASSED`);
        } else {
          console.log(`${pageConfig.path}:${name}:FAILED`);
        }
      } else {
        console.log(`${pageConfig.path}:${name}:PASSED`);
      }

      await browser.close();
    });
  });
})();
@yury-s
Copy link
Member

yury-s commented Dec 23, 2020

Sounds like the server is throttling your requests every once in a while or just slow and waitForResponse times out (as expected) after 20s.

Feel free to reopen if there is an evidence that there is a problem on Playwright side.

@yury-s yury-s closed this as completed Dec 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants