Time for action – changing our Page Object to use Loadable Component - Selenium

Now that we have learnt about LoadableComponents, we should have a look at seeing it in action. We need to make changes to our Java Class.

  1. The following is how the code should look so far:

  2. If we have a look at our Chapter (Locators) Java class, we can see that we need to extend LoadableComponent. Since this takes generics we will have to pass in our PageObject class. It should look like:

    public class Chapter(Locators) extends LoadableComponent<Chapter2> {
  3. In our constructor, we will have to initialize our page factory. We can remove the rest of the code in there since that will be moved to load(). It should look like the following:

  4. We now need to add our override methods. These will allow us to check that we are on the right page when we load this component:

  5. Now we need to have a look at updating our test to load everything for us. To do this we need to change:

  6. To look like this:

  7. Run your test. Everything should look like the following:

What just happened?

We have just converted our page object to use the Loadable Component class that comes with the Selenium Project. We saw how we simplified on constructors and then just moved this into somewhere easy to maintain.We have seen that we can move a lot of the boiler plate code out of our class and rely on it being pulled in via Loadable Component. This means that we no longer need to maintain it or we add those items.

Have a go hero - Loadable Component

magine how you have to work with a flow that takes you through a number of pages. LoadableComponent allows us to set up a workflow.To get this right we need to pass one in like the following when doing your test setup:


All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Selenium Topics