前言
base_url是把所有接口的公共url提取出来,如我两个接口地址如下:
imos登录接口:http://120.25.121.168:19001/api/login
任务列表接口:http://120.25.121.168:19001/api/task
这时,base_url:http://120.25.121.168:19001/api
案例
在.evn中设置环境变量base_url
# .env base_url=http://120.25.121.168:19001/api
在测试用例中,引用环境变量base_url
config: name: "查看测试平台imos任务列表" variables: username: admin password: quxue2023 headers: User-Agent: ${get_user_agent()} verify: False export: [ "foo3" ] teststeps: - name: "登录测试平台imos" request: method: POST url: /login headers: Content-Type: application/json User-Agent: HttpRunner/${get_user_agent()} json: username: ${username} password: ${password} extract: token: "body.data.token" validate: - eq: ["status_code", 200] - name: "查看任务列表" request: method: GET url: /task headers: Accept: application/json, text/plain, */* Authorization: Bearer ${token} params: page: 1 size: 10 search: "" validate: - eq: ["status_code", 200] - eq: ["body.code", 200] - eq: ["body.message", "操作成功"]
执行:hrp run testcases\get_imos_task_list.yml --gen-html-report 查看报告,成功:
标签:httprunner,api,url,imos,121.168,base,08base,eq From: https://www.cnblogs.com/quxue/p/18133536