The PO mode in automated testing, let you understand it hand in hand

Automated testing plays an important role in the software testing project team. At the same time, reasonable implementation of automated testing can effectively reduce the cost of error repair and improve work efficiency.

Let's take web automation testing as an example to illustrate the POM mode: under the framework of python+Selenium+pytest, it seems to be a very simple work process to complete the writing, management, running and reporting of automated test cases. As the project progresses, Especially in the agile project development method with frequent iterations, the low-quality test scripts implemented by some automated testers often lead to high code maintenance costs in the later stage. As time goes by, the so-called automated testing seems to have forgotten its original intention.

A very practical way to solve the poor quality of test scripts in POM mode. Let me introduce the thinking of POM separation mode to you:
pom separation:
POM separation page-object-module--is a kind of thinking
The purpose of adopting POM: In order to solve the frequent changes of UI in the front end, which causes the cost of test automation script maintenance to increase Come to the big
POM idea: separate the page elements and business logic and test scripts into two different class files. Class A only writes page element positioning and encapsulation of business logic code operations, and class B only writes test scripts.
POM has the following advantages:
1. Separate the web ui object warehouse from test scripts, and separate business codes from test scripts.
2. Each page corresponds to a page class, and the elements of the page are written in this page class.
3. The page class mainly includes the element positioning of the page, and the method of encapsulating the business operation code related to these elements.
4. Code reuse, thereby reducing the amount of test script code.
5. The hierarchy is clear, and it supports the development of multiple automated scripts at the same time, such as which pages each person writes, without affecting others.
6. It is recommended to give a meaningful name to both the page class and the business logic method, so that others can quickly write and maintain scripts.
Examples are as follows:
1. Test script

 

2. Business logic

 

3. Interface elements

 4. Repackage

5. Use the latest package content

It is said that a good start is half the success, and the same is true for the implementation of the automated testing framework. Before the implementation of the testing framework, we need to design a good framework for unavoidable UI element changes after all-round examination and filtering. Sometimes the first thing we think about is how to automate those functional modules that do not change frequently, and how can we reduce the high cost of code adjustments in the future for those functional modules that change frequently? It is necessary to achieve "the child falls and the whole body is revitalized", rather than "the whole body is affected by a single hair". Can we limit the change to one place and make it available to every test script associated with it? The answer must be absolutely unanimously yes-------POM mode can help us achieve it.

If the web page element changes, we only need to modify it in its corresponding class file, instead of searching and updating in multiple different scripts. This approach is the Page Object Model (POM), which helps to improve code readability, maintainability, and reusability.

All friends who want to learn to test, now is a very good time, friends who want to switch to the IT industry can also leave a message or discuss in the comment area. If you want relevant information, you can also leave a message.

Guess you like

Origin blog.csdn.net/GUDUzhongliang/article/details/131932487