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 the Page Object Pattern to design tests

Imagine that you have a site that has a number of different pages that you need to test. This is quite common for a number of sites. We can create an object that represents the page and then pass the Selenium object in the programming language. So let us now create our first Page Object against the home page.

  1. Create a new Java class in IDEA called HomePage.
  2. Import the relevant packages for the tests to run.
  3. We will now need a constructor to handle Selenium. You may want to make it go to the home page when it is instantiated too. An example of this can be seen as follows:

    HomePage.java

    import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; public class HomePage{ WebDriver ...

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