How to use proxy configuration to quickly locate interface test script problems?

In the process of debugging interface use cases, if the response result is inconsistent with the expected result, you need to check the request information. Obtain the request response information in the automated test through the proxy, and compare the difference with the normal request response, so that you can more intuitively troubleshoot request errors, which is equivalent to the debug function when writing code.

Combat practice

In automated testing, regardless of the Java version or the Python version, a proxy can be set to monitor the request response information of the automated test script.

Python version

Monitor request and response information through  proxies parameters.

import requests

# 1. 定义一个代理的配置信息,分别需要设定http协议与https协议的代理地址。

proxy = {

    "http": "http://127.0.0.1:8000",

    "https": "http://127.0.0.1:8080"

}

2. Pass the proxy configuration through proxies.


requests.post(url="https://httpbin.ceshiren.com", proxies=proxy, verify=False)

Proxy information is set through proxies, and the proxy format is required to be a dictionary type. By default, verify is set to True. By setting verify to False, Requests can ignore the verification of SSL certificates when sending HTTPS requests.

java version

import io.restassured.RestAssured;

import static io.restassured.RestAssured.*;

import static io.restassured.specification.ProxySpecification.host;

import static org.hamcrest.core.IsEqual.equalTo;

public class Requests {

    public static void main(String[] args) {

        RestAssured.proxy = host("127.0.0.1").withPort(8080);

        given().relaxedHTTPSValidation().when().get("https://httpbin.ceshiren.com/get").

                then().log().all();

    }

}

Verify the results using proxy tools

In actual work, using proxy tools (refer to the chapter on commonly used proxy tools) combined with proxy configuration can clearly view the information of each request. The actual operation steps are as follows:

  • The port set by the packet capture tool is consistent with the proxy address port of the code, as shown in the following figure:

As shown in the figure below, a normal request is initiated on the page. In the post request, the key value of the request data is school, and the value is Hogwarts Testing Society

 

  • Use the automated test script to initiate the same request as in step 2, except that the value is changed to the second request.

Python version

import requests

def test_proxy():

    # 1. 定义一个代理的配置信息

    proxy = {

        "http": "http://127.0.0.1:8888",

        "https": "http://127.0.0.1:8000"

    }


    # 2. 通过proxies 传递代理配置

    requests.post(url="https://httpbin.ceshiren.com/post",

                  data={'school': "第二次请求"},

                  verify=False)

 java version

import io.restassured.RestAssured;

import static io.restassured.RestAssured.*;

import static io.restassured.specification.ProxySpecification.host;

public class Requests {

    public static void main(String[] args) {

        RestAssured.proxy = host("127.0.0.1").withPort(8080);

        given().

                contentType("application/x-www-form-urlencoded;charset=utf-8").

                formParam("school", "第二次请求").relaxedHTTPSValidation().

                when().

                post("https://httpbin.ceshiren.com/post").

                then()

                .log().all();

    }

}

The result of packet capture by the packet capture tool is shown in the figure below:

Through the above cases, it can be seen that the combination of proxy configuration and proxy tools can intuitively see the difference between the two interface requests, thereby improving the efficiency of locating interface test script problems.

Finally: The following are the supporting learning materials. For friends who do [software testing], it should be the most comprehensive and complete preparation warehouse. This warehouse also accompanied me through the most difficult journey. I hope it can help you too!

Software testing interview applet

The software test question bank maxed out by millions of people! ! ! Who is who knows! ! ! The most comprehensive quiz mini program on the whole network, you can use your mobile phone to do the quizzes, on the subway or on the bus, roll it up!

The following interview question sections are covered:

1. Basic theory of software testing, 2. web, app, interface function testing, 3. network, 4. database, 5. linux

6. web, app, interface automation, 7. performance testing, 8. programming basics, 9. hr interview questions, 10. open test questions, 11. security testing, 12. computer basics

  How to obtain the full set of materials: Click the small card below to get it yourself

 

Guess you like

Origin blog.csdn.net/weixin_57794111/article/details/132690623