Coder Social home page Coder Social logo

Comments (6)

mxschmitt avatar mxschmitt commented on September 27, 2024

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.

ChintanVasoya avatar ChintanVasoya commented on September 27, 2024

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.

  1. Input the username and password.

  2. 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.)

  3. Click on the profile icon from the dashboard page.

  4. 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.

mxschmitt avatar mxschmitt commented on September 27, 2024

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.

Exoow avatar Exoow commented on September 27, 2024

@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.

yury-s avatar yury-s commented on September 27, 2024

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.

yury-s avatar yury-s commented on September 27, 2024

Closing per the responses above, feel free to open a new issue if it doesn't work.

from playwright.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.