Friday, May 16, 2014

Shaping the perfect Page Object Model for your Automation Framework

Let's talk about the implementation details that we're going to be use when we actually go ahead and create our Automation Framework.

Within your application UI there are areas that your tests interact with. A Page Object Model simply models these as objects within the test code. This reduces the amount of duplicated code and means that if the UI changes, the fix need only be applied in one place.

You may have heard the term Page Object ModelThis is a common term in the automation community which basically refers to idea of mapping your Automation Framework model to the model of your application pages.
So your application you may have a series of different pages and those pages are going to be modeled in our framework the same way.



So as an example, if you have a login page, we are going to create a class inside of our test framework called LoginPage and it's gonna have some of the same functionality that your login page has. It's gonna be responsible to get the elements that exist on that login page. 

For example, the username field, the password field and the login button. It will manipulate those elements at the highest level possible. That's what makes a good Automation Framework.

Instead of having a method in the LoginPage class called getUsernameField or insertTextInUsernameField. We are gonna have a Login method on the LoginPage class and we'll pass the username, the password and automatically it's going to know how to insert the username and password into the correct fields and push the login button.

This is going to aid in our automation. It's where that coffee maker example comes into play. Part of this idea of the page object model is to design this high level API. You are thinking about designing your framework for your test in the same way that the user might use the real page.

You can see also that the objects of your Page Object Model don't have to necessarily map to exact pages in your application. In this diagram we have a Navigation Menu example. And maybe you have this Navigation Menu in every single page. It's a section of you application. So it's gonna map to it's own logical object in your framework and you'll have methods that your tests can call and use it just like a real user would.

And by doing it this, you make it very simple to write your tests and understand your tests.


No comments:

Post a Comment