H01_HttpRunner 重复执行用例指定步骤:times
在测试用例中,通过 times 关键字可以设置每个测试步骤的执行次数。
设置方法:
- test:
times: <执行的次数>
编写用例如下
- config:
name: testcase01
base_url: http://localhost/myweb/jxc
- test:
name: login_invalid1
# 本步骤重复执行 3 次
times: 3
request:
url: /index.asp?action=login
method: POST
data:
username: admin
pwd: 1234
extract:
- info: window\.(.*)\.go
validate:
- eq: [$info, history]
执行该测试用例:
查看测试报告
再多想一步,如果 times 设置为 0 会怎样? 做个试验:
- config:
name: testcase01
base_url: http://localhost/myweb/jxc
- test:
name: login_invalid1
# 设置执行次数为 0 次
times: 0
request:
url: /index.asp?action=login
method: POST
data:
username: admin
pwd: 1234
extract:
- info: window\.(.*)\.go
validate:
- eq: [$info, history]
可以看到执行结果,被执行了 0 次,这也相当于该步骤的执行被跳过了
综上,可以通过 times 关键字,控制测试步骤的执行:
- 执行指定的次数: times: 3
- 跳过步骤的执行: times: 0