httprunner 4.x學習 - 12 測試用例引用另一個測試用例

测栈云發表於2024-04-28

前言

把登入用例變 export 匯出變數,變成全域性變數,這樣其它用例可以引用

登入用例

config:
  name: 登入
  variables:
    username: "admin1"
    password: "123456"

teststeps:
-
  name: post
  request:
    method: POST
    url: ${ENV(base_url)}/login
    json:
      username: ${username}
      password: ${password}

  validate:
    - eq: [status_code, 200]
    - eq: [headers."Content-Type", "application/json"]

在其它用例中引用登入用例

config:
    name: "檢視測試平臺imos任務列表"
    headers:
        User-Agent: ${get_user_agent()}
    verify: False

teststeps:
-
    name: "1.登入測試平臺imos"
    testcase: testcases/login_imos.yml
-
    name: "2.檢視任務列表"
    request:
        method: GET
        url: ${ENV(base_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", "操作成功"]

相關文章