O'Reilly logo

Selenium 2 Testing Tools Beginner's Guide by David Burns

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action – using PageFactory

In this example we are going to be cleaning up the previous examples by using the PageFactory. This will allow us to create more succinct code than the previous verbose examples.

  1. Open the previous example and go to Chapter2.java. It should look like the following example:

    Chapter2.java

    import org.openqa.selenium; import junit.framework.Assert; public class Chapter2 { WebDriver selenium; WebElement verifybutton; public Chapter2(WebDriver selenium){ this.selenium = selenium; verifybutton = selenium.findElement(By.id("verifybutton")); if (!"Chapter 2".equalsIgnoreCase(this.selenium.getTitle())){ selenium.get("http://book.theautomatedtester.co.uk/chapter2"); } } public boolean isButtonPresent(String button){ return ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required