I'm getting an error: Timeout of 30000ms exceeded.
How can I work with playwright so that this doesn't time out? If possible I don't want to increase the timeout period. The code loops over a large list of <a href making sure that there are no dead-links and other undesirable content. It's working as expected except that after the first 30 seconds of link checking it crashes. I can only check the first 15 links or so.
--snip--
test("Test all links do not 404", async ({ page }) => {
const genericTests = new GenericTests(page);
//await page.setDefaultTimeout( 1000 * 60 * 5 ); (changing the timeout here did not work)
await genericTests.testAllLinks()
});
export class GenericTests {
--snip--
async testAllLinks() {
let context = await this.page.context();
//await context.setDefaultTimeout( 1000 * 60 * 5 ); (changing the timeout here did not work)
let allLinks = this.page.locator("a[href]");
let allLinksCount = await allLinks.count();
for(var i=0; i<allLinksCount; i++) {
let nthLink = await this.allLinks.nth(i);
//snip logic to verify the link, deal with duplicates etc..
let [newPage] = await Promise.all([
context.waitForEvent("page"),
nthLink.click({"modifiers": ["Control"], "force": true})
]);
//await newPage.setDefaultTimeout( 1000 * 60 * 5 ); (changing the timeout here did not work)
await newPage.waitForLoadState();
await newPage.bringToFront();
const page404 = new Page404(newPage);
page404.testPageForVariousProblems();
//snip logic to check for 404s
}
}
}
There are two timeouts at play here.. The timeouts shown in the example are not relevant as each browser instance and each navigation is executing quickly and is not timing out, the overall test and the overall suite of tests are timing out.
There is a per-test timeout which can be altered in the first code block:
test("Test all links do not 404", async ({ page }) => {
test.setTimeout(0); // <-- here
--snip--
This can also be changed globally (see below) in this particular situation this makes the most sense.
And there is a global setting for all tests in playwright.config.ts:
// playwright.config.ts
import { PlaywrightTestConfig } from '@playwright/test';
const config: PlaywrightTestConfig = {
timeout: 30000
,globalTimeout: 600000 // <-- entire test suite
--snip--
};
export default config;
The code was executing fine there was no additional need to indicate that the code is "working as expected" well as indicated in the question.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With