PAGE OBJECT MODEL (POM) IN SELENIUM

PAGE OBJECT MODEL (POM) IN SELENIUM

What is the Page Object Model (POM) in Selenium?

Page Object Model (POM) is a Design Pattern for automating web applications and it has become popular because it let us allow to create an Object Repository for Web Elements that translates into enhancing test maintenance and reducing code duplication.

The following is an example of a sample Page Object Model approach. Here I have created a package with the name “apppages” that contains all page classes of the application and a separate “tests” package that will contain all the tests for automating the web application. The project structure of the POM project looks like the following image.

Aucun texte alternatif pour cette image

The Page Object Model in Selenium makes the code more readable, maintainable, reusable, and scalable.

Aucun texte alternatif pour cette image

Advantages of Page Object Model in Selenium:

1-Maintainable Code –?The major benefit of the Page Object Model is that if the GUI changes for any of the pages, the tests themselves don’t need to change, only the code within the page object needs to change. This makes automation scripts easier to maintain and highly optimized.

2-Readable Code –?Automation Test Scripts and Page-specific code are cleanly separated from each other. The code becomes less and more readable.

3-Reusable Code –?If multiple test scripts have to use the same web elements, there is no need to write code to handle the web element in the individual test scripts. Having a separate page class makes it reusable by making it accessible by any test script.

4-Logical Method Name –?The approach enforces us to give self-explanatory method names for page object elements that can be easily mapped with the operation to be performed on the GUI. i.e. if a have to click on a Login button, the method name could be clickOnLoginButton().

要查看或添加评论,请登录

Raouand L.的更多文章

社区洞察

其他会员也浏览了