Hi all, in this article I will explain you the loadable component pattern in Page Object Model architecture. In our test automation projects generally, we are doing some prerequisite actions to test some scenarios. For example, when we are testing the login, first we need to open the homepage and go to login page, then start to do login actions. Without the loadable component pattern, we do this test as follows:

When we apply the loadable component pattern in our Page Object Model framework, our test class will become like this:

As you see above, now we do not need to specify prerequisite actions explicitly. I mean, we do not need to write HomePage class’s methods which opens the login page:

So, how can we use Loadable Component Pattern? Let’s start to learn.

First, we need to extend our page classes with LoadableComponent abstract class.

LoadableComponent class’s structure is shown below:

It is an abstract class with load(), isLoaded(), and get() methods. When we extend this class, we have to implement load(), and isLoaded() methods and we can use get() method to obtain our class when it is loaded based on our implementations.

After extending LoadableComponent class, now we need to implement load() and isLoaded() methods in HomePage and LoginPage classes. In load () method, we need to declare the actions which load the page and in isLoaded() method, we need to check that the page has been loaded or not. Before this, let’s look at the project structure:

BasePage is our common Page class which comprises of the common functions of all pages.
HomePage is home page class.
LoginPage is login page class.
TestListener is our test listener Class for taking action when test and suite started, finished, failed, skipped, passed.
BaseTest is the common test class.
LoginTest is login test class.
ExtentManager is for ExtentReports.

Let’s look at some classes’ details. First, let’s start with BasePage. We declared common methods such as click, sendText, getText, etc.

HomePage Class:

Here, I implemented load() and isLoaded() methods which belong to LoadableComponent abstract class. I also instantiate BasePage class’s object in the constructor to use its methods via basePage object.

LoginPage Class:

Here, I implemented load() and isLoaded() methods which belong to LoadableComponent abstract class. I also instantiate BasePage class’s object in the constructor to use its methods via basePage object. I also use HomePage class’s goToLoginPage() method at load() block. In order to reach that method, I need to get that class as parent. I assigned the parent object in the constructor and use it at load() method.

parent.get() -> gets the HomePage class

and then, I used its goToLoginPage() method as -> parent.get().goToLoginPage()

In this way, I can go to LoginPage() class.

After, going to LoginPage, we need to check that the page is loaded? We can check this at isLoaded() method.

assertTrue(“LoginPage is not loaded!”, driver.getCurrentUrl().contains(loginURL));

Now, let’s go on BaseTest class. In this class, we can declare the before and after operations at class level.

BaseTest Class:

and now, it is time to write a test method.

LoginTest Class:

Here, I did comon prerequisites for each test in @BeforeMethod block. I can reach the loginPage with below line:

loginPage.get();

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

@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 Loadable Component pattern. But, you can find the full implemented project here: https://github.com/swtestacademy/loadablecomponentexample

You can also learn the SlowLoadableComponent Pattern via this article: http://www.swtestacademy.com/slowloadablecomponent-pattern/

Thanks.
Onur Baskirt