美文网首页
httprunner 3.X (10)debugtalk参数化

httprunner 3.X (10)debugtalk参数化

作者: Sandra_liu | 来源:发表于2022-01-16 15:01 被阅读0次

    debugtalk:添加get_users()方法

    def get_users(num):
        users = []
        for i in range(1,num):
            users.append({"username": "1342875058%s" %i, "password": "a123456"},)
        return users
    

    用例:调用debugtalk中添加的get_users()方法

    import pytest
    from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase
    from httprunner import Parameters
    
    from debugtalk import get_user
    from debugtalk import get_users
    """测试数据参数化"""
    class TestCaseLogin(HttpRunner):
        @pytest.mark.parametrize(
        "param",
        Parameters(
            {
                "username-password":"${get_users(5)}"
            }
    
        )
    )
    
        def test_start(self, param):
            super().test_start(param)
    
        config = Config("登录") \
            .base_url("https://api.testing.net") \
            .variables(
            **{
    
            }
        ) \
            .verify(False)
    
        teststeps = [
            Step(
                RunRequest("/account/v1/login")
                .post("/account/v1/login")
                .with_headers(
                    **{
                        "content-type": "application/json; charset=utf-8",
                        "x-hb-client-type": "android"
                    }
                )
                .with_json({"account": "$username", "password": "$password"})
                .extract()
                .with_jmespath("body.user_id", "user_id")
                .with_jmespath("body.token", "token")
                .validate()
                .assert_equal("status_code", 200, "断言成功")
                .assert_equal("body.continue_url", "https://api.testing.net")
    
            )
        ]
    
    
    if __name__ == "__main__":
        TestCaseLogin().test_start()
    

    相关文章

      网友评论

          本文标题:httprunner 3.X (10)debugtalk参数化

          本文链接:https://www.haomeiwen.com/subject/uwpfhrtx.html