I. Understanding requirements and what is the core business of the systemtwo. Writing test cases: use case names, preconditions, test data, test steps, desired resultsthree. Initial construction of the Automation code: all element positioning, element manipulation, test cases are written in one module
Problem:
1. Level confusion, once the page element is adjusted, it is necessary to find the corresponding test module, test class, test case function, not convenient for post maintenance
2. Not easy to reuse code
Four. Introduction of PO mode, layered Design: implementation of test Cases and Page object separation
Benefits:
1. Clear level, independent, easy to maintain
2. The Page object can be called multiple times, which improves the reusability of the code.
Five. Introduction of unit Test framework UnitTestSix. Optimize the layered design
The common properties and methods of each page are extracted, encapsulated into a BasePage class under the BasePage module, each page only needs to inherit it, so that all the properties and methods of the parent class can be obtained, which not only simplifies the code, but also improves the reuse degree.
Seven. Introduction of Pytest: Based on UnitTest, more "intelligent" than unittest
Benefits:
1. You can run a specific test case by marking it
2. Use contest.py to define common fixture, which can be called in multiple test classes, without requiring each test case class to define the environment preparation and environment cleanup, simplifying the code
3. Pytest can automatically discover test cases according to certain rules, while UnitTest needs to add test cases to the specified test suite
4. With the pytest-html library, you can generate your own HTML reports and XML files, while the benefits of XML files are easy to integrate and display with other platforms, making it easy to develop two times
eight. Attention points
1. Before you automate, you should have a separate account to avoid interference from the outside environment .
2. The page order is entirely determined by the business logic and is determined by the test case. So when the page is packaged without considering who calls it, regardless of which page operation to use it (or which function to use it later), it should be considered that no matter what the previous operation, who will use it, any step to invoke it, it will be normal operation ( This is also why some page elements need scrolling operations)
3. Do not consider what is meant in the use case in the packaging function, only need to consider what this page is the function (such as: the label details page to get the balance function of the package, do not need to name the function get_user_left_money_before_invest, Instead, it is named Get_user_left_money when it is only considered for its functionality)
4. In the selection process, do not specify a specific name, but to randomly select, because the label on the page will change. Therefore, the selection of test data, use case design to follow the principle of not relying on the system as far as possible, which also improves the stability of the Code
5. The precondition of investment operation is: The available balance is greater than the investment amount, how to guarantee this condition, there are two ways:
1) Recharge enough money in the background
2) judge the current user balance enough, not enough to recharge, you can call the query interface to query the user balance, call the top-up interface to recharge-because the API operation is very fast, which also improves the efficiency of test cases
6. Ensure the independence of use cases: each test case should reopen the browser
Nine. Layered design structure diagram
10. Web Automation Flowchart
Web Automation Process Summary