httprunner4学习总结4 – 录制生成测试用例

本文介绍了一种通过录制来自动化生成多种格式测试用例的方法,包括JSON、pytest及yaml等,并详细说明了如何指定输出路径及使用yaml配置文件自定义请求头和cookie。

1、生成测试用例

  • 生成json用例【默认生成】:hrp convert xxx.har or hrp convert xxx.har --to-json
  • 生成pytest用例:hrp convert xxx.har --to-pytest
  • 生成yaml用例:hrp convert xxx.har --to-yaml
  • 生成gotest用例【待实现】:hrp convert xxx.har --to-gotest

2、生成测试用例 + 指定用例的路径 + pytest格式的测试用例

hrp convert add_case.har --to-pytest --output-dir ../testcases/project1

  • –to-pytest:生成pytest格式测试用例
  • –output-dir:生成的测试用例放在哪里

3、生成测试用例 + 指定用例的header + 指定用例的路径

(1)替换header和cookie中某个字段的值,用yaml中的内容

hrp convert add_case.har --to-pytest --output-dir ../testcases/project1 --profile ../profile/profile.yaml

  • –profile …/profile/profile.yaml:使用profile.yaml中的header信息替换生成的测试用例中整个header
# profile.yaml
headers:
    token: "this header will be created or updated"
cookies:
    Cookie1: "this cookie will be created or updated"

(2)覆盖header和cookie的内容,用yaml中的内容

hrp convert add_case.har --to-pytest --output-dir ../testcases/project1 --profile ../profile/profile_override.yaml

  • –profile …/profile/profile_override.yaml: 只会替换pytest格式用例中header某个字段的值
# profile_override.yaml
override: true
headers:
    accept-language: "this header will be created or updated"
cookies:
    Cookie1: "this cookie will be created or updated"
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

阿_焦

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值