Comments (6)
DOM load event listeners have proven to be unreliable over the last years, so end-to-end testing frameworks tend to do polling instead. In your scenario, it should work without any explicit waits at all, since Playwright will automatically wait until the element is on the page, clickable etc. see here.
Looking e.g. at this code:
await page.goto();
await page.getByRole('textbox', ...).fill()
await page.getByRole('textbox', ...).fill()
await page.getByRole('button', { name: 'Profile' }).click()
await page.getByRole('button', { name: 'Save' }).click()
So this would always wait for a navigation to complete, element to appear, etc.
In your 3rd step, if you would immediately click, Playwright would wait for the click element to be appear on the page etc. like a real user and then click it once its there not moving anymore etc.
If you have concrete examples which don't work, let us know!
from playwright.
I'm encountering an issue and require assistance regarding implementing an event listener that consistently monitors page load events. Here's an example scenario to illustrate the problem:
Navigate to a specific URL.
-
Input the username and password.
-
Click on the login button. (At this point, an API call is made, and upon successful authentication, the user is redirected to the dashboard page.)
-
Click on the profile icon from the dashboard page.
-
Proceed to click on the save button from the profile page.
The issue arises when a user clicks on a button that redirects to a new page. At such moments, I encounter difficulties. I'm in need of an event listener that can automatically handle this situation by waiting for a designated period.
What I'm seeking is something along the lines of:
page.on('load', async data => {
await page.wait(2000);
});
This code ideally waits for 2000 milliseconds whenever a new page loads.
could you please provide a solution or direct me to an article that explains how to achieve this functionality?
from playwright.
Image being a user - does the user every time wait for 2 seconds before clicking somewhere? Some users are very fast and click immediately somewhere on the page. So it looks like a bug in the application rather than something Playwright should fix by waiting for 2 seconds.
from playwright.
@ChintanVasoya if you really need this, why not write a wrapper method that first navigates and then await page.waitForTimeout(2000)
so you can have this behavior everywhere you navigate.
from playwright.
As Max mentioned above, Playwright's recommended approach is to test the user visible behavior, i.e. wait for a UI change that would be observable by a human, rather than waiting for a timeout after some internal load event.
The issue arises when a user clicks on a button that redirects to a new page. At such moments, I encounter difficulties.
Why can't you wait for an expected state of the page's UI by using one of the web assertions or Playwright actions that auto-wait internally?
from playwright.
Closing per the responses above, feel free to open a new issue if it doesn't work.
from playwright.
Related Issues (20)
- [Bug]: Action pointer rendered for each iframe in trace viewer snapshot HOT 1
- [Bug]: viewport from playwright.config.js is not honored. HOT 1
- [Bug]: Memory Consumption Issue with Playwright 1.44.1- Assistance Required HOT 1
- [Feature]: Unable to Disable Screenshot took and Attachment for Certain Tests HOT 4
- Error: duplicate test title HOT 1
- [Bug]: VSCode extension Watch mode not working (MacOS) HOT 3
- [Feature]: I pass the json and it automatically generates request & response HOT 4
- [Regression]: `tsconfig.json`'s `compilerOptions.paths` no longer working in 1.47 HOT 4
- [Bug]: React select input click step fails on safari, but passes on chrome HOT 2
- [Bug]: 'latest' tag is pointing to "v1.46.1-jammy" docker image HOT 10
- [Bug]: @playwright/test 1.47.0 broken for tsconfig alias imports HOT 3
- [Feature]: clock feature inside tests HOT 1
- [Bug]: logPolitely logs on stdout HOT 6
- [internal]: Screenshots instead of Snapshots improvements
- [Feature]: Passing variables from playwright.config to test.spec HOT 5
- [Bug]: Trace report doesn't show up on report - Inconsistent behaviour. HOT 1
- [Bug]: VSCode Playwright extension "Error loading webview: Error: Could not register service worker: InvalidStateError: Failed to register a ServiceWorker" HOT 1
- [Bug]: Default GitHub Action says ERR_PNPM_RECURSIVE_EXEC_FIRST_FAIL Command "playwright" not found HOT 2
- [Docs]: NOTE in the Introduction / Clock page
- [Bug]: Recorder doesn't work when `Array.prototype.toJSON` is declared HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from playwright.