A Fluent Page Object Approach - return this - EvilTester.com
Another simple tip, but I use this a lot.
Return ‘this’ from your Page Object methods
e.g.
QueNessSlowLoadingExamplePage page4 = new QueNessSlowLoadingExamplePage(driver); page4.get(); page4. setName("Bob Dobbs"). setEmail("b.dobbs@mailinator.com"). setMessage("Hello There"). sendMessage(); In the above code I have a Page Object called QueNessSlowLoadingExamplePage which handles this example over at QueNess.com
And you can see that the setName, setEmail and setMessage are all ‘fluent’ in the sense that they return ‘this’ so I can chain them when using the Page Object.
A Fluent Page Object Approach - return this - EvilTester.com
Another simple tip, but I use this a lot. Return ‘this’ from your Page Object methods e.g. QueNessSlowLoadingExamplePage page4 = new QueNessSlowLoadingExamplePage(driver); page4.get(); page4. setName("Bob Dobbs"). setEmail("b.dobbs@mailinator.com"). setMessage("Hello There"). sendMessage(); In the above code I have a Page Object called QueNessSlowLoadingExamplePage which handles this example over at QueNess.com And you can see that the setName, setEmail and setMessage are all ‘fluent’ in the sense that they return ‘this’ so I can chain them when using the Page Object.
https://eviltester.com/blog/seleniumsimplified/2013-08-17-a-fluent-page-object-approach-return-this/