O'Reilly logo

Mastering Selenium WebDriver 3.0 by Mark Collin

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

Turning your page objects into a readable DSL

Well it's actually not that hard to make things better. Earlier in this chapter, we moved our page object initialization into the constructor and had a look at a way of initializing page objects without passing in any parameters. Let's use this simplicity to start turning our page objects into a fluent, readable DSL.

We will start off by taking our index page object and creating a reference to the header and footer page objects inside it:

package com.masteringselenium.query_page_objects;import com.lazerycode.selenium.util.Query;import org.openqa.selenium.By;public class IndexPage extends BasePage {    private Query heading = new Query(By.cssSelector("h1"), driver);    private Query mainText = new 

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