Get interface testing under multiple environments (interface testing framework actual combat)

In actual work, most companies have at least 3 environments for testing and R&D personnel to use. It is impossible for testers to prepare an automated test step for each environment, because such maintenance costs are too huge. Therefore, to solve this problem, it is necessary to design a set of scripts that can be run in various environments.

Actual demonstration

In the previous article, on the basis of the dictionary structure mentioned, the URL was changed from a hard-coded IP address to a domain name.

 req_data={
            "schema": "http",
            "method": "get",
            "url": "http://docker.testing-studio.com:10000/demo64.txt",
            "headers":
            {"Host":None}
        }

Then, we need another dictionary structure to store the configuration of the environment.

envVariables are used here to store the environment configuration of a dictionary structure. Then replace the URL in the request structure with the URL envof your personal choice in the configuration file. First use to env["docker.testing-studio.com"]read all the environment configuration options, and then use the changing [env["default"]]selection to switch between different environments.

#把host修改为ip,并附加host header
env={
    "docker.testing-studio.com": {
        "dev": "127.0.0.1",
        "test": "1.1.1.2"
    },
    "default": "dev"
}
data["url"]=str(data["url"]).replace(
    "docker.testing-studio.com",
    env["docker.testing-studio.com"][env["default"]]
)
data["headers"]["Host"]="docker.testing-studio.com"

From the above two steps, the environment switch can be regarded as a configurable option, and it is very convenient to switch between different use environments according to the needs. However, the current solution is still written in the code, which is not elegant enough. Later, we will explain how to convert envthe configuration information in the variable into a configuration file in YAML format.

Above, more advanced content of interface testing framework actual combat, we will share in follow-up articles. Pay attention to the " Programmer Two Black " official account to get more test and development dry goods content.

Guess you like

Origin blog.csdn.net/m0_52650621/article/details/112788465