httprunner 3.X (8)笛卡尔参数化

2022-01-15  本文已影响0人  Sandra_liu
import pytest
from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase
from httprunner import Parameters

"""测试数据参数化-笛卡尔积"""
class TestCaseLogin(HttpRunner):
    @pytest.mark.parametrize(
        "param",
        Parameters(
            {

                "username": ["134287505XX", "134287505XX", "134287505XX", ""],
                "password": ["a123456", "111111", "", "a123456"],

            }

        )
    )
    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()

上一篇下一篇

猜你喜欢

热点阅读