-
一.入门
-
- pip安装
- 直接安装
pip install httprunner - gitbub仓库安装
pip install git+https://github.com/HttpRunner/HttpRunner.git@master
- 直接安装
- 版本升级
- -U参数
$ pip install -U HttpRunner$ pip install -U git+https://github.com/HttpRunner/HttpRunner.git@master
- -U参数
- 安装校验 hrun
- hrun -V
- 参数指令
- hrun -h
- hrun --startproject tests_cgala
- hrun ./api/user_login.yml --log-level debug
- hrun xxx.yml
- pip安装
-
二.编写测试用例
- 结构
- 层层嵌套
testsuites套 testcases套 api - api
- testcases
- testsuits
- 层层嵌套
- 字段
- 变量
- 局部变量
- teststep
- api
- variable
- json
实际上就是传参的具体值
- 全局变量(文件)
testcases中的config- 如果要设置一个全局变量,需把变量声明(variables)放到config下,这样就在整个.yml文件生效了
- 环境变量
- ${ENV(keyname)
- 局部变量
- extract
- content.data.list.0.subAccountUuid
- 也可以使用正则表达式
- 断言
- 可以使用正则表达式
- 断言里面不可以使用函数,但是可以在变量里面使用函数再在断言里面引用这个变量
- 源码
- 在hhttprunner>buitin>comparators里面
- validate各种比较方法
- eq
validate:- eq: [status_code,200]- eq: [content.message,SUCCESS]- eq: [content.data.total,0] - contains
- eq
- hooks
- setup_hook
- $request
request中有header也有json
- $request
- teardown_hooks
- $response
- 测试用例层面(testcase)
- 测试步骤层面(teststep)
- setup_hook
- 其他
- times
- 在 test 下加个 times 参数即可实现该teststep的重复运行
- output
output: - id_0- report没看到,可以用来调试
- times
- 变量
- 其他
- 测试用例合并
比如有些test经常是合并连续使用的,可以用这个- 在testcases中的test下引用testcase
- 参数化与数据驱动
- parameter
- csv
- 条件执行测试用例
- skip
- skipIf 条件值为true,则跳过测试用例
- skipUnless
- 测试用例合并
- 结构
-
-
三.执行与调试
-
- 测试执行
- cli.main()
- runner = HttpRunner() runner.run('./api/user_login.yml')
- 执行
- hrun filepath/testcase.yml
- hrun filepath
- hrun testcase --failfast
- hrun ./api/user_login.yml --log-level debug
- 保存为bat或sh执行
- 调试
- 执行逻辑
- cli.main
- summary = runner.run(path, dot_env_path=args.dot_env_path)
生成测试报告数据- self.run_path(path_or_tests, dot_env_path, mapping)
run testcase/testsuite file or folder. - 或
- self.run_tests(path_or_tests)
run testcase/testsuite data- parsed_testcases = parser.parse_tests(tests_mapping)
读取测试用例- parsed_testcase = _parse_testcase(testcase, project_mapping)
elif test_type == "testcases":- prepared_config = __prepare_config(...)
- raw_config_variables = config.pop("variables", {})
- prepared_testcase_tests = __prepare_testcase_tests(...)
- config_variables = config.get("variables", {})
- session_variables_set |= set(test_dict["extract"])
move extracted variable to session variables - ..........
- prepared_config = __prepare_config(...)
- parsed_testcase = _parse_testcase(testcase, project_mapping)
- results = self._run_suite(test_suite)
执行测试用例,生成结果- result = self.unittest_runner.run(testcase)
一个一个执行测试用例,生成结果
- result = self.unittest_runner.run(testcase)
- self._summary = self._aggregate(results)
汇总测试用例结果 - report.stringify_summary(self._summary)
生成测试报告
- parsed_testcases = parser.parse_tests(tests_mapping)
- self.run_path(path_or_tests, dot_env_path, mapping)
- gen_html_report(...)
生成测试报告report
- summary = runner.run(path, dot_env_path=args.dot_env_path)
- cli.main
- 执行逻辑
- 测试执行
- 其他
- 关联
- name
- api和teststep关联
- testcases和用例关联(xlsx)
- id
- testcases和用例关联(xlsx)
- teststep(操作)
- teststep-传值
- name
- 关联
-
httprunner--使用
猜你喜欢
转载自www.cnblogs.com/margot921/p/12669379.html
今日推荐
周排行