The Page Object Framework in Less than 3 minutes (Hopefully)

If you want to work in test automation, you have to understand the page object model. This model provides the advantages of sorting out your test code in a clear manner as well as not having to fix test code whenever UI changes are made.

What is a Page Object?
An object, as Zed Shaw explains it, is essentially a noun. In terms of computer science, it is a noun that represents a specific thing. For instance, an object could represent a car or a house. This object has attached to it certain properties and it can do certain things (methods it can perform). For automated testing, when we are testing a page, we can a page into an object by assigning it to a class. For instance, let's say we have a login page with two fields for a username and a password. These fields are properties of the login page. Additionally, there are certain actions you can perform on this page. For the purposes of testing, you could say that you can login correctly, login incorrectly (wrong username, wrong password, or both items wrong, etc.), or any other actions you may need to test. With a page object our login page becomes a class with HTML code as its properties and testing methods as its methods. So what would this look like?

















Our LoginPage class has three HTML elements and we have identified each element by the ID (the best way to select an element in testing). We have created a method that can take any username or password we give it and login. We can then user this method in our step definition and more importantly use it in more than one step definition.

I haven't had much time to write blog posts lately, but I wanted to get one out there! Stay tuned for a larger explanation of the page object format as well as things I've learned about machine learning!

No comments:

Post a Comment