Changing our Page Object to use LoadableComponent
Now that we have learned about LoadableComponents, we should have a look at it in action. We need to make changes to our Java class.
The following is how the code should look so far:
public class Chapter2 { WebDriver selenium; @FindBy(how= How.NAME, using="verifybutton") WebElement verifybutton; public Chapter2(WebDriver selenium){ this.selenium = selenium; if (!"Chapter 2".equalsIgnoreCase(this.selenium.getTitle())){ selenium.get("http://book.theautomatedtester.co.uk/chapter2"); } } public boolean isButtonPresent(String button){ return selenium.findElements(By.xpath("//input[@id='"+button+"']")).size()>0; } }If we have a look at our
Chapter2Java class, we can see that we need to extendLoadableComponent. As this takes generics, we will have to pass it in ourPageObjectclass. It should look like the following line of code:public class Chapter2 extends LoadableComponent<Chapter2> {In our constructor...