pdx Selenium & Test Automation Users Group Message Board › A page object using a "Fluent API" design pattern

A page object using a "Fluent API" design pattern

Jon A.
user 61898832
Portland, OR
Post #: 8
Martin Fowler coined the term "Fluent API" and I heard it would work well with Selenium2 WebDriver and so tonight I took a stab and creating a page object with a fluent API interface. Here is what I came up with. Feel free to fork my code and contribute your own version! :-)

https://github.com/dj...­

Specifically, here is what a fluent page-object test might look like:

@Test
public void testFluentPageObject() {
driver.get("http://www.google.com...­
GoogleSearchPage gs = new GoogleSearchPage();
gs.withFluent()
.clickSearchField()
.setSearchString("iphone app")
.waitForTime(3, 1000)
.selectItem( "development" )
.clickSearchButton()
.waitForTime(5, 1000)
.clickLogo( "gbqlt" ); //click Google logo
System.out.println("Done with fluent test.");
}
Jon A.
user 61898832
Portland, OR
Post #: 9
I fixed a few bugs and improved the fluent page object in my test project (see the previous link in this thread).

NOTE: The reason why I chose to use a non-object-oriented approach with a static WebDriver instance is because I needed the browser to remain open between unit tests: not sure how to do this otherwise since objects get cleaned up between tests (when you are running from Parameterized input).
Powered by mvnForum

Our Sponsors

People in this
Meetup are also in:

Sign up

Meetup members, Log in

By clicking "Sign up" or "Sign up using Facebook", you confirm that you accept our Terms of Service & Privacy Policy