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 ...

Get Selenium 2 Testing Tools Beginner's Guide now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.