Simple use python+selenium+pytest Carry out the actual combat of the project
**** One 、 The previous test report uses pytest.html Relatively simple and simple , Next, change to a nice report file Allure
1、 stay PyCharm Choose from File->Settings
2、 Select project directory ( Such as Project:PythonWorkSpace)->Project Interpreter-> Click the plus sign on the right “+”
3、 Input allure-pytest, Select and click Install Package
4、 Prompt that the problem will be solved after the installation is successful
perhaps pip install pytest-allure-adaptor
Two 、 Create a new one project
The structure level can be as shown in the figure above , It can also be established according to specific requirements of specific projects
1.common layer , Put the configuration file , Put all the project related configurations here , use Python Support good configuration file formats such as ini or yaml Wait for configuration . Realize the separation of configuration and code .
2.data layer , Put the data file , Can put all of testcase The parameterization related files are put here , Generally xlsx、csv、xml Equiform . Separate data from code .
3.drivers layer , Place the required drive , Such as Chromedriver、IEDriverServer etc. .
4.logs layer , All generated logs are stored here , The logs can be classified , Such as runtime log test log, Error log error log etc. .
5.report layer , Release the report generated by the program , Generally, there can be html The report 、excel Reports, etc. .
6.testcases Use case layer , Put all test related files :
7.utils layer , All the supporting code is here , Including reading config Class 、 Write log Class 、 Read excel、xml Class 、 Classes that generate reports ( Such as HTMLTestRunner) And other classes and methods , Both here and at the secondary packaging of the frame .
8.cache cache , Temporary storage 、 Associate test data or cookie、token Wait for the documents
9.files Test file class
10. Test data-driven files such as yaml、csv、excel etc.
11.ReadMe.md, Illustrative documents , Tell team members the context and usage of the framework
3、 ... and 、 encapsulation ( Follow up to add slowly )
The approximate directory structure is recorded in Utils Preliminary encapsulation of the code
(1) Encapsulation of assertions
(2) Cache storage and read encapsulation
(3) Log reading and encapsulation
(4) Database read and assert encapsulation
(5) Send wechat automatically 、 Enterprise WeChat 、 mailbox 、 nailing 、 Flying books and other software
(6) Data driven file read case encapsulation (yaml、swagger、excel、csv、excel、 file )
(7) Use case templates automatically generate use cases and print reports through data driving
(8)request、json encapsulation , Where common libraries are used
(9) Automatically generate test data encapsulation ( Time 、 Gender 、 Age 、 Date of birth 、 Province 、 Date and so on )
Four 、 Through data-driven files yaml Read the use case
5、 ... and 、 Automatically generate test reports and send them to e-mail and enterprise wechat , Subsequent use cases need to be supplemented and improved by themselves Utils Block details how to implement , You can also ask me for the specific code , You can reuse any project