Why It’s Useless To Check For Page Load In UI Automation?

I recently had an excellent conversation with my bud Titus Fortner and realized that it’s actually pointless to check whether a page has loaded. Since all automated browsers tests aim to mimic user behavior, at some point we will be making a UI interaction. At this point, the UI interaction can tell us if something went wrong. Doing any page rendering validation before hand is actually redundant and a waste of time.

Let’s take a look at how I used to write my UI automation. I would start with a simple test and then expand to a more complicated one. Something like this.

So what happens when the first test fails?

I get the following exception

OpenQA.Selenium.WebDriverTimeoutException : Timed out after 5 seconds
----> OpenQA.Selenium.NoSuchElementException : no such element: Unable to locate element: {"method":"class name","selector":"btn_action"}

What happens when the 2nd test fails?

I get the following exception

OpenQA.Selenium.WebDriverTimeoutException : Timed out after 5 seconds
----> OpenQA.Selenium.NoSuchElementException : no such element: Unable to locate element: {"method":"id","selector":"user-name"}

Btw, if you want to see tips in code, as well as dozens of others, check out the Complete Selenium WebDriver with Java Bootcamp.

What’s the difference?

They’re the same exact exception!

The only difference is the element that wasn’t located. But that doesn’t matter because the end result is the same.

When a page doesn’t render, what does that mean?

First, it can mean that your server is down. In which case, driver.get("www.url.com") will fail for both scenarios.

Second, it can mean that the page didn’t render because of an HTML, CSS, JS issue. So, when we try to interact with any element on that page, we will get a NoSuchElementException. Doesn’t matter which element because the root cause of the problem is exactly the same.

Conclusion

So, as you can see, checking that the page has loaded is actually a pointless activity and a pointless test. The action that we take immediately after the page load will reveal if the page has rendered successfully.

Let me know if you agree that it’s unnecessary to check for a page load.

Nikolay Advolodkin is a self-driven SDET on a lifelong mission to create profound change in the IT world and ultimately leave a legacy for his loved ones

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store