Hi all, in the previous article, I explained how to implement loadablecomponent pattern and in this article, I will explain how to implement the slowloadablecomponent pattern. The loadablecomponent pattern is convenient for the pages which load not so slowly. However, when a site loads very slow, then we should consider using slowloadablecomponent rather than loadablecomponent. Slowloadablecomponent verifies the page is loaded until the given maximum timeout.

In order to implement this pattern, first we need to extend our page classes with SlowLoadableComponent class as shown below:

SlowLoadableComponent class implementation is shown below. It extends LoadableComponent class and implements the get() method. By using SlowLoadableComponent, we wait the page is loaded until given timeout period. We should implement load() and isLoaded() methods in page classes and use get() method to obtain loaded page class. load() and isLoaded() method definitions are in the LoadableComponent class.

It extends the LoadableComponent class:

It has two constructor parameters:

It implements the get() method by using given timeout period. The full implementation is shown below:

Now, I want to share with you the project architecture:

I will go on with page and test implementations.

BasePage Class:

I declared common methods such as click, sendText, getText, etc. in BasePage Class.

HomePage Class:

Here, I extended SlowLoadableComponent class and I implemented load() and isLoaded() methods which belong to LoadableComponent abstract class. SlowLoadableComponent class extents LoadableComponent class so it also has these methods and we need to implement them. I also instantiate BasePage class’s object in the constructor to use its methods via basePage object.  The most critical part is to set the clock and timeout period of page load. I did this in the constructor with below code:

super(new SystemClock(), 20);

LoginPage Class:

  • First, I extended SlowLoadableComponent class.
  • Set values to clock and timeout period in the constructor by using super keyword.
  • Instantiated BasePage class to use its methods.
  • Set Parent with parent parameter of the constructor. We can also use LoadableComponent<?> instead of LoadableComponent<HomePage> to make it more generic.
  • Then, I implemented load() and isLoaded() methods.
  • Finally, I added page classes which are related to the login operations.

BaseTest Class:

I implemented class level setup and teardown.

LoginTests Class:

For method level setup, I used @BeforeMethod annotation and instantiated pages and get the login page via login.get() line. When we call login.get() method, it first, load the parent class which is HomePage and then load the LoginPage class.

This method, firsts call’s LoginPage class’s load() method. In this method, parent.get() part calls HomePage class’s load() method and gets the HomePage class then calls its goToLoginPage() method to load LoginPage(). It is shown below:

@Override
protected void load() {
parent.get().goToLoginPage();
}

In @Test blocks we can only call LoginTest page’s methods to fulfill login operation and test scenarios. In this way, we don’t need to explicity call HomePage class’s methods to go/open/load LoginPage.

I do not want to share here ExtentManager and TestListener classes. They are not related to the SlowLoadable Component pattern. You can find the project here: https://github.com/swtestacademy/SlowLoadableComponentExample

Thanks.
Onur Baskirt