httprunner中的变量优先级

variables priority

变量有几种不同的类型,优先级(priory) 可能会让人感到困惑。避免混淆的最好方法是使用不同的变量名。

但是,如果必须使用相同的变量名,则应该理解优先级策略。

testcase

config:
    name: xxx
    variables:              # config variables
        varA: "configA"
        varB: "configB"
        varC: "configC"
    parameters:             # parameter variables
        varA: ["paramA1"]
        varB: ["paramB1"]

teststeps:
-
    name: step 1
    variables:              # step variables
        varA: "step1A"
    request:
        url: /$varA/$varB/$varC # varA="step1A", varB="paramB1", varC="configC"
        method: GET
    extract:                # extracted variables
        varA: body.data.A   # suppose varA="extractVarA"
        varB: body.data.B   # suppose varB="extractVarB"
-
    name: step 2
    varialbes:
        varA: "step2A"
    request:
        url: /$varA/$varB/$varC # varA="step2A", varB="extractVarB", varC="configC"
        method: GET

在测试用例中,变量的优先级顺序如下:

  • step variables > extracted variables, e.g. step 2, varA="step2A"
  • parameter variables > config variables, e.g. step 1, varB="paramB1"
  • extracted variables > parameter variables > config variables, e.g. step 2, varB="extractVarB"
  • config variables are in the lowest priority, e.g. step 1/2, varC="configC"

testsuite

config:
    name: xxx
    variables:                  # testsuite config variables
        varA: "configA"
        varB: "configB"
        varC: "configC"

testcases:
-
    name: case 1
    variables:                  # testcase variables
        varA: "case1A"
    testcase: /path/to/testcase1
    export: ["varA", "varB"]    # export variables
-
    name: case 2
    varialbes:                  # testcase variables
        varA: "case2A"
    testcase: /path/to/testcase2

在测试套件中,变量的优先级顺序如下:

  • testcase variables > export variables > testsuite config variables > referenced testcase config variables

参考资料:

https://docs.httprunner.org/user/concepts/#variables-priority

posted @ 2021-11-02 13:39  Marlon康  阅读(55)  评论(0编辑  收藏  举报