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

Using Page Factories with Page Objects

The code that we have learnt to write earlier can be quite verbose. To clean up our code, we can start to use Page Factories. This allows us to annotate variables in our page objects with how to search the page. This means that we don't have to have full WebElement element = driver.findElement( ...); code all over the file. We can change it to:

@FindBy(how=How.ID, using="foo")
WebElement foo;

As you can see this can make our code slightly easier to read and therefore more maintainable. If you regularly use other languages like Ruby or Python, you will notice that they don't have the PageFactory support project. This is because those languages don't have Factory constructs in the language. They are not idiomatic ...

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