Tuesday, May 17, 2016

WebDriver Page Object Model

WebDriver Page Object Model

The basic idea of page object model is that you will have a class for each page in the application. This class contains methods which represent the functionality on that page. So the tests do not directly interact with the page, they use page class which in turn knows how to do the requested functionality on a page using an automation tool like WebDriver.

In the example (below) you can see a login page and it’s represented in our framework (above) using LoginPage class. This class has methods that map to a functionality that the login page would expose to a user. The methods in a LoginPage class should correspond to the actions a user would do on the page.

Take another example, suppose we have this below page of Gmail which we want to model. Here do not try to blindly model every user interface element (e.g. every button, text box, link etc) on this page. Instead, try and think what user, using this page, will try to do on this page like search emails. We can write a method named Search_Emails which takes the search criteria, types the criteria in the search box and clicks the Search button. So it’s better to have it combined rather than having separate methods/properties etc. to type into the box and clicking Search button and so on.

Also see:
Selenium WebDriver Page Objects