httprunner3.x 参数化数据驱动
发布日期:2021-05-13 21:49:02 浏览次数:23 分类:精选文章

本文共 4380 字,大约阅读时间需要 14 分钟。

httprunner3.x ���������������������

��� httprunner3.x ������������������������������������������������������������ reuseability��������������������������������������������������� pytest ���������������������������

������������������������

parameters ��������� httprunner ���������������������������������������������������������������������������

  • ������������������������

    ������������������������������������������ ['iOS/10.1', 'iOS/10.2', 'iOS/10.3']���������������������������������������������������������

  • ������������ parameterize ������

    ������������������������������ CSV ������������������������������������ parameterize ������������������(${parameterize(parameter.csv)}) ��������������� CSV ������������������������������������

  • ���������������������

    ��������������������������������������������������������������������������������������������������� debugtalk.py ������������������ ${get_data()}���������������������������������������������


  • ������������������������������

    1. ������ pytest ��� @parametrize ���������

    ������ pytest ��� @pytest.mark.parametrize ��������������� httprunner ��� Parameters ���������������������������������������������������������������

    @pytest.mark.parametrize('param', Parameters({'number': [1, 2], 'token_length': [32]}))
    def test_start(self, param):
    super().test_start(param)

    2. ���������������variables������������������������

    ��� config ������������������������ ${ENV(USERNAME)} ��� ${ENV(PASSWORD)} ������������������������������������������������������������������������������������������������

    config = (
    Config("login")
    .variables({
    "username": "${ENV(USERNAME)}",
    "password": "${ENV(PASSWORD)}"
    })
    .base_url("${ENV(HOSTURL)}")
    .verify(False)
    )

    3. ������������������������������������

    ���������������������������������������������������������������������������������������������������

    Step(
    RunRequest('login')
    .post('/client/user/auth')
    .with_headers({
    "Content-Type": "application/json"
    })
    .with_json({
    "scenario": "client",
    "company_id": 5940,
    "user_name": "$username",
    "password": "$password",
    "device_type": "$device_type",
    "device": ""
    })
    .extract()
    .with_jmespath("body.data.token", "token")
    .validate()
    )

    ������������������������

    ������������������������������������������������������

    import pytest
    from httprunner import (HttpRunner, Config, Step, RunRequest, Parameters, RunTestCase)
    class TestCaseLogin(HttpRunner):
    @pytest.mark.parametrize('param', Parameters({
    "device_type": "${get_data()}"
    }))
    def test_start(self, param):
    print(param)
    super().test_start(param)
    config = (
    Config("login")
    .base_url("${ENV(HOSTURL)}")
    .variables({
    "username": "${ENV(USERNAME)}",
    "password": "${ENV(PASSWORD)}"
    })
    .verify(False)
    )
    teststeps = [
    Step(
    RunRequest('login')
    .with_variables({
    'token_length': 32,
    'status_code': 201,
    'status': 1
    })
    .post('/client/user/auth')
    .with_headers({
    "Content-Type": "application/json"
    })
    .with_json({
    "scenario": "client",
    "company_id": 5940,
    "user_name": "$username",
    "password": "$password",
    "device_type": "$device_type",
    "device": ""
    })
    .extract()
    .with_jmespath("body.data.token", "token")
    .validate()
    .assert_equal('status_code', '$status_code', '������������')
    .assert_equal('body.status', '$status', '������������')
    .assert_length_equal('body.data.token', '$token_length', '������������')
    )
    ]

    ������������

  • ���������������������������������

    • ������������������������������������ "$���������" ��������������� "$number"������
    • ��������������������������� ${���������} ��������������� ${parameterize(parameter.csv)}������
  • ���������������������������

    ���������������������������������������������������csv������������������������������������������������

  • ���������������������������

    ������������������������������������������������������������������������������������������

  • 上一篇:httprunner3.x hook机制
    下一篇:httprunner3.x python语言编写测试用例

    发表评论

    最新留言

    留言是一种美德,欢迎回访!
    [***.207.175.100]2025年04月28日 13时59分57秒

    关于作者

        喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
    -- 愿君每日到此一游!

    推荐文章