
本文共 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 pytestfrom 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���������������������������������������������������������������������������
������������������������������������������������������������������������������������������发表评论
最新留言
关于作者
