The page.waitForTimeout() method in Playwright is deprecated because it relies on hardcoded delays, which can lead to flaky tests. Playwright recommends using more reliable, condition-based waiting methods that adapt to the page's state. Below, I’ll guide you through identifying and replacing page.waitForTimeout() usage with appropriate alternatives.
Better Alternatives:
Playwright offers methods like waitForSelector, waitForFunction, or waitForResponse to wait for specific conditions, making tests more robust.
Replace with a Delay Utility Function
if you need to sleep to help debug code temporarily, or you're writing a quick and dirty script which doesn't need to be reliable, you can use a plain Node wait:
test.only('set timeout using node', async ({ page }) => { // ... await setTimeout(3000); console.log("print log after that..."); });
Also possible is promisifying setTimeout yourself, which is useful if you're sleeping in the browser context:
test.only('set timeout using promise', async ({ page }) => { const sleep = (time) => new Promise(resolve => setTimeout(resolve, time)); // ... await sleep(29000); console.log("print log after that..."); });
This is all about page timeout in playwright.
No comments:
Post a Comment