httprunner 3.x--variables变量和声明
2021-01-16 17:14
                         标签:base   code   数值   params   run   mic   conf   pch   style      在 HttpRunner 中,支持变量声明(variables)和引用($var)的机制。调用函数(${func($var)}) 在 config 和 test 中均可以通过 variables 关键字定义变量,然后在测试步骤中可以通过 $ + 变量名称 的方式引用变量。 在 config 中定义的变量为全局的,整个测试用例(testcase)的所有地方均可以引用; 在 test 中定义的变量作用域仅局限于当前测试步骤(teststep)   一般写用例的时候,最好把可能会变的参数单独写个变量。做到测试数据和代码的分离,以便后续维护。 如果step和config中variables声明的参数名相同,在运行测试用例的时候会取step里面的参数值 如果要设置一个全局变量,需把变量声明(variables)放到config下 引用uid和choujiang_id/username变量用       如果在steps下声明的变量,作用域只在当前steps下有效。声明变量用with_ 完整代码如下:    运行结果如下:   httprunner 3.x--variables变量和声明 标签:base   code   数值   params   run   mic   conf   pch   style    原文地址:https://www.cnblogs.com/may18/p/13375540.html
区别在于:全局变量
config = (
        Config("test /lotter*****st.php")
        .base_url("https://lotter****.com")
        .verify(False)
        .variables(
            **{"uid": "14**7",
               "choujiang_id": "*9",
               "username": "**"}
        )
    )
$uid,$pchoujiang_id,$username 完整的脚本如下:
局部变量
variables,变量和对应值用键值对,如Step(
            RunRequest("get with params")
            .with_variables(
                **{"uid": "14**7",
                   "choujiang_id": "**",
                   "username": "**"}
            )
            .get("/lotteryTest.php")
            .with_params(**{"uid": "$uid", "choujiang_id": "$choujiang_id", "username": "$username"})
            .validate()
            .assert_equal("status_code", 200)
        ),


上一篇:web字体图标
文章标题:httprunner 3.x--variables变量和声明
文章链接:http://soscw.com/essay/42811.html