一、测试步骤
- 方式1:测试用例内部加步骤
- 方式2:测试用例字方法上加步骤(装饰器@allure.step('描述')
二、测试用例内加步骤
def test_sign_up(self,i_user_name,i_pwd,i_repwd,i_phone,o_code,o_userId,o_msg):
with allure.step('第1步:取地址'):
url = conf.gy_api + '/signup'
with allure.step('第2步:替换用例数据'):
if i_user_name=='自动生成':
i_user_name = gen_data_tool.get_name_pinyin()+
str(gen_data_tool.get_number(1,10))
if i_pwd == '自动生成':
i_pwd = gen_data_tool.get_pwd()
i_repwd = i_pwd
if i_phone == '自动生成':
i_phone = gen_data_tool.get_tell()
request = {
"phone": i_phone,
"pwd": i_pwd,
"rePwd": i_repwd,
"userName": i_user_name
}
print(request)
with allure.step('第3步:发送请求'):
response = request_tool.post_request(url=url, json=request)
print(response.json())
print(response.request)
with allure.step('第4步:判断结果'):
assert_tool.assert_code(response.status_code, 200)
if o_code != '':
assert_tool.assert_text(response.json()['code'], o_code)
if o_userId == 'not null':
assert_tool.assert_not_null(response.json()['data']['userId'])
二、示例
class TestSignUp:
def login(self):
url = ''
req = {
"pwd": "string",
"userName": "string"
}
allure.attach(req, '请求', allure.attachment_type.TEXT)
resp = requests.post(url, json=req)
allure.attach(resp.text, '响应', allure.attachment_type.TEXT)
三、查看报告