Continuous Test Orchestration And Execution Platform Online

Perform automated and live-interactive testing on 3000+ real desktop and mobile devices online.

Loadable Components In Selenium: Make Your Test Robust For Slow Loading Web Pages

Nishant Kashyap

Posted On: December 4, 2017

view count23170 Views

Read time2 Min Read

Being in automation testing for the last 10 years I have faced a lot of problems. Recently I was working on a selenium automation project and in that project everything was going fine until I faced a most common but difficult problem. How to make sure that my selenium automation testing work fine even for slow loading web pages. A quick google and browsing through forums highlighted that this is a problem that testers are facing for many past years. If you too have faced it then yes, this article is there to help you from my personal experience.
Well, this problem is majorly observed in the case when the web application uses a javascript heavy framework.

The component that’s gonna help us in page loading is an extended version of PageObject pattern called Loadable component.In the selenium library, Loadable Component class helps the automation test engineers to make sure that the page or its component is loaded successfully. This hack should greatly reduce the efforts that you put in debugging your test cases.

To start with, we would first have to make sure that all the PageObject classes extends the abstract LoadableComponent class and in turn provide implementation for the following two methods:

  • protected abstract void load()
  • protected abstract void isLoaded() throws java.lang.Error

Code to ensure whether the page or component inside the page is completely loaded in given in isLoaded(). If the page is not completely loaded, java.lang.Error is thrown

Fallback or mitigation code is given load(), if isLoaded() fails to load the complete page successfully.

Let’s take an example on how it works :

Suppose, we have a LoginPage with username, password and submit button.

Now, the above PageObject can be transformed using LoadableCompenent like below.

The get() method from the LoadableComponent class will ensure sure the page or the component is loaded by invoking the isLoaded() method. If the assertion fails there, load() method is called, followed by isLoaded().

Hope this article helps in stabilizing UI tests !!!

Author’s Profile

Nishant Kashyap

Blogs: 2


Test your websites, web-apps or mobile apps seamlessly with LambdaTest.

  • Selenium, Cypress, Playwright & Puppeteer Testing
  • Real Devices Cloud
  • Native App Testing
  • Appium Testing
  • Live Interactive Testing
  • Smart Visual UI Testing
Book a Demo