Start United States USA — software Everything You Need To Know About Page Object Model and Page Factory...

Everything You Need To Know About Page Object Model and Page Factory in Selenium

103
0
TEILEN

Knowing how to use Page Object Model and Page Factory in Selenium can benefit developers and automation engineers who struggle with the duplicity of test cases.
Join the DZone community and get the full member experience. As we continue to automate the test cases on a daily basis using Selenium automation, the maintenance of the growing test suite parallelly becomes complicated. While automating the test cases on Selenium, there would be an instance where we use the same web element in multiple test scripts. For example, while automating an E-Commerce application, in every test case we have to search for a particular item from a search field using Selenium locator i.e. using XPath or ID. For such scenarios, we add the search field locator in every test script which would eventually increase code duplication. Moreover, if there is any change in the locator, we have to change the locator in every test script where a particular web element is used. To overcome such challenges, we would be further looking at the Page Object Model that would help build a framework that is easy to use and maintain. Page Object Model is a design pattern commonly used in test automation for creating an Object Repository of web elements. The primary advantage of adopting POM is to reduce code duplication and reduce maintenance efforts. To start with, in a Page Object Model framework development, we create different classes for different web pages. Each class file contains a web element locator for the elements present on a particular web page. Multiple test scripts can further use these element locators to perform various web actions. Since a separate class file is created for each web page and the common locators can be used by multiple test classes, this reduces the code duplicity and improves code maintenance. Now since we are aware of the Page Object Model design pattern, let’s implement a basic structure of the Page Object Model with the Selenium framework where all the web elements of the web page and the method to perform web actions will be maintained in a class file.

Continue reading...