Book Image

Learning Selenium Testing Tools - Third Edition

Book Image

Learning Selenium Testing Tools - Third Edition

Overview of this book

Table of Contents (22 chapters)
Learning Selenium Testing Tools Third Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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.

  1. 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;
      }
    }
  2. If we have a look at our Chapter2 Java class, we can see that we need to extend LoadableComponent. As this takes generics, we will have to pass it in our PageObject class. It should look like the following line of code:

    public class Chapter2 extends LoadableComponent<Chapter2> {
  3. In our constructor...