Pure Python self-developed interface automation script update version, so that xiaobai can also achieve 0 to 10,000 + interface automation use cases

Are you still using Postman \ JMeter for interface automation? Use Python’s open source framework [UnitTest \pytest] to move interface code code by interface code? Online surveys of both entry-level and advanced levels of most people, training institutions’ courses, and interfaces to do so are automated.

This is a python interface automation framework with a top three, of course, is also using Excel reading as a driver and storage test data to complete the interface automation, please read this article you will know the magic of script! Excited hearts, trembling hands, pick up your little bench and sit ready to lead you into the ranks of the lazy! Finally completed internal test, solve the BUG, such as there is a BUG that is natural! The python interface automation script is designed to automate thousands of interface use cases with ease. In fact, there are more than thousands of interfaces. Tens of thousands of interfaces can be easily managed. And the interface of the new project is directly used, not only for regression testing, which can greatly improve work efficiency. Are promotions and salary increases far behind?

What features does this release have?

1. All the status codes, response values and expected results of previous versions were judged by Excel functions. Now it is written into Excel 2 after unified judgment. Previous version of response value assertion, can only judge a certain field, now can judge multiple fields 3. The previous version of the test results were in excel table statistics, excel results also retain the previous format, added all statistics after the code statistics are displayed in HTML page 4. Add email sending function, support excel table [Test Environment Configuration] table control whether to send email function 5. Optimize parameters in the first line of Excel 6. Write exceptions into the corresponding Interface cases of Excel for easy troubleshooting 7. 8. Prepare a series of script usage ideas for youCopy the code

Fully functional content for script implementation

Basic operations for interface automation 1. HTTP interface requests are supported: POST, GET, PUT, HEAD, and DELETE 2. 3. Support status code, response value multiple parameter assertion judgment [expected status code and response value Excel table control, code directly using the regular judgment] 4. Support constants: constants are generally used globally, parameterization is very important in automated testing, the same type of test, only need to maintain different data can 5. Support variables: if the response value returns a parameter, return multiple different values, can be distinguished assigned to the corresponding variable, extract a single value not to mention definitely also support advanced application 6 interface automation. Dynamic parameters: for example, dynamic parameters [Upper and lower interface parameter association] can be configured. Dynamic parameters can be extracted from response values in different JSON formats. Batch interface execution will not stop because of an interface error, throw exceptions into the Excel table 8. Detailed log output and log saving function 9. Support automatic generation of two test reports after the test is completed: detailed Excel report and statistical data: HTML test report display 10. Support in excel control whether E-mail, mailing function due to intercept web images should be installed in the PhantomJS is an unbounded, but its browser scripting engine, the official download: http://phantomjs.org/download 11. Can be extended according to business development, such as the common functions, interface requires the MD5 parameter calibration note: pytestreport HTML display test report is for reference: https://github.com/five3/PyTestReport, use API embedded script USES directlyCopy the code

The overall flow of the script

Description of the meaning of each column in excel



Dynamic parameter flow

Interface test case thinking

Intercepts internal interfaces to request partial log printing

Sample Excel test report


Test reports showing all interface tests passedAn abnormal interface returns a report

Example Of automatically sending emails successfullyContent is subject to change


Above, is today’s content, “forward” or click “in view” can scan the top two-dimensional code to obtain the latest source code, thank you!

Baidu really have very few direct to give you the whole framework can run up, so really script design is not easy, feel the content is worth, quick click below “like the author” reward return it “look forward to”!

This article is formatted using MDNICE