SeleniumLibrary icon indicating copy to clipboard operation
SeleniumLibrary copied to clipboard

Add "Wait for DOM inactivity" keyword which waits until page is fully loaded/rendered

Open nick-grout1 opened this issue 3 years ago • 4 comments

Prerequisites

  • I have searched for similar issues in open tickets and cannot find a duplicate.
  • The issue still exists against the latest released version of SeleniumLibrary.
  • This is not a usage question or support request. For those, see more details in README.rst: https://github.com/robotframework/SeleniumLibrary#support
  • You are not using the Java Selenium2Library: https://github.com/MarketSquare/robotframework-seleniumlibrary-java
  • Remember that this is a public forum, so remember to remove all sensitive information, like username and password.

For issues

Steps to reproduce the issue

N/A

Error messages and additional information

N/A

Expected behavior and actual behavior

N/A

Environment

N/A

Feature Request Background

In an effort to improve page performance, modern web apps load initial content, then load the rest of the data on the page via XHR requests. The page continues to mutate until all additional data is loaded. This is a major problem for old frameworks like Selenium, which simply wait until the initial page loads but do not wait until the content on the page fully loads.

Examples of this loading style can be found on sites like: airbnb.com amazon.com buzzfeed.com yahoo.com

A workaround we've found extremely useful at my company is to leverage the relatively new Mutation Observer api (docs here).

This mutation observer can be configured to fire a callback every time a node on the DOM is added or mutated. This can be used to detect when the page finally calms down and is ready for the automated test to continue.

Feature Request

My feature request, which I will implement, is to leverage this mutation observer in a new keyword "Wait for DOM Inactivity", which the user can call to wait on the XHR requests on dynamic pages (like those listed above) to finish.

Some key scenarios where this can be used are:

  • pretty much any automated test which tests against a single page app
  • whenever a button click opens & loads a modal
  • on highly performant, dynamic pages which heavily leverage XHR requests (like those listed above)

Let me know if this interests you, I would be more than happy to implement this. I have used SeleniumLibrary extensively and love the library, and would love to contribute to it in any way.

Thank you for reading my request!

nick-grout1 avatar Dec 21 '21 04:12 nick-grout1

Wow! This looks very interesting and if it works, promising! Is the Mutation Observer API something new?

humbienri avatar Dec 21 '21 04:12 humbienri

Hi @humbienri, I'm not sure exactly when it came about - but it is has been well supported on most major browsers for a while now (see the compatibility section of the MDN documentation):

image

nick-grout1 avatar Dec 21 '21 05:12 nick-grout1

It is an interesting idea and I do not know will work or now. If you want to implement this, I think that this is little bit out of the scope of the SeleniumLibrary, because SeleniumLibrary uses (mainly) Selenium API to provide functionality. But SeleniumLibrary offers wide range of possibilities to build on top the SeleniumLibrary, for more details please see our extending docs. Most likely the plugin API is the way to go, because it offers best route to the SeleniumLibrary internals.

aaltat avatar Dec 21 '21 09:12 aaltat

Gotcha that makes sense @aaltat - thanks for taking a look!

nick-grout1 avatar Dec 21 '21 18:12 nick-grout1