I'm creating test scripts in Playwright and Node.js for an old, buggy web application run by a vendor. I don't have access to the code for the application, my tests run on the vendor's website.
I continually find issues that are solved by adding hard waits. For reasons I don't understand (because I don't have access to the code) the website seems to have trouble with the speed that Playwright performs actions.
I'm wondering if there's a way to add a hard wait between each action? Is it possible to wrap the page
object in a wrapper that calls waitForTimeout
, then whatever function was called?
There is 2 fold answer to it:
to increase timeout for every action including navigations.
import { defineConfig } from '@playwright/test';
export default defineConfig({
use: {
actionTimeout: 10 * 1000,
navigationTimeout: 30 * 1000,
},
});
This can be further overridden on step level if needed:
locator.click({ timeout: 10000 })
to find out exactly what steps are taking more time and which don't and you can go from there to further explore the root cause as needed
import { defineConfig } from '@playwright/test';
export default defineConfig({
retries: process.env.CI ? 2 : 0, // set to 2 when running on CI
...
use: {
trace: 'on-first-retry', // record traces on first retry of each test
},
});
One may tempt to use hard wait as standard approach in automation to get rid of all sync issues but this is NOT recommended. I would suggest to use it to confirm functionality is working and measure performance of specific steps to pinpoint to dev team so that they can address the underlying issues.
In general , playwright's auto-waiting feature is good enough for most of the healthy applications out there.