Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize automatic testing of data-driven Interface with Python

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly explains "how to use Python to achieve data-driven interface automation testing", the content of the article is simple and clear, easy to learn and understand, now please follow the editor's ideas slowly in depth, together to study and learn "how to use Python to achieve data-driven interface automation testing"!

In the process of interface testing, the read operation of CSV is often used. This paper mainly describes the writing and reading of CSV by Python3.

1. Demand

An API,GET method, token,mobile,email three parameters

Token is required

One of the required items for mobile,email

Mobile is the mobile number, and email is in email format.

two。 Scheme

For the above API, when doing interface testing, you need as many test cases as possible, so it may be more appropriate to write common content to the configuration file in a data-driven way.

Here, consider storing the API, parameters, and expected results in advance in the formatted CSV, using the csv component to read the URL, parameters and expected results from the CSV, and the Requests component to initiate a request to compare the response results with the expected results, and * write the comparison results to the result CSV.

The flow chart is as follows

3. Realize

(1) before going to the code, install the following components:

Csv reads and writes CSV files

Json

Requests initiates a request to get the response result

Unittest test case scheduling

(2) data.csv (selected partial use cases in this example)

(3) reader_CSV function code example

(4) example of request_URL function (including two methods of GET request and POST request)

(5) example of assert_Result function

(6) example of write_CSV function

(7) example of test_interface1 function

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

4. Summary

Python encapsulates many methods, and the development speed is relatively fast for testing. If the interface automation test adopts the data-driven mode managed by CSV, using csv+requests is one of the sharp tools that should not be missed in test development.

Thank you for reading, the above is the content of "how to use Python to achieve data-driven interface automation testing". After the study of this article, I believe you have a deeper understanding of how to use Python to achieve data-driven interface automation testing, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report