Senior programmers use Python for data-driven interface automation testing!

Source: Internet
Author: User

2. The programme

For the above API, when doing interface testing, the test cases need to be up to 10 +, this time in a data-driven way to write the common content of the configuration file may be more appropriate.

Here consider the API, parameters, and expected results preprint in the formatted CSV, using the CSV component to read the URL, parameters, and expected results from the CSV, requests component initiates the request, compare the response result with the expected result, and then write the result to the result CSV.

Processes such as

3. Implement

(1) Before the code, install the following several components:

    • CSV read/write CSV file

    • Json

    • Requests initiating a request to get response results

    • UnitTest test Case Scheduling

(2) Data.csv (This example selects some use cases)

(3) Reader_csv function code example

(4) Example of Request_url function (2 methods with GET request and POST request)

(5) Assert_result Function Example

(6) Write_csv Function Example

(7) Test_interface1 Function Example

8result_1523956055.csv (the test results in this example are ignored)

4. Summary

Requires 0 basic primer books, Python core programming and other information in the group: 125240963 files to download their own

Senior programmers use Python for data-driven interface automation testing!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.