httprunner4.x学习5 - 抓取测试脚本
目录:
1. 抓包工具比如fiddler导出har文件 login.har
2. har2case -2y login.har转成yml格式生成login.yml文件
3. hrun login.yml生成login_test.py文件
4. 最后用pytest login_test.py执行脚本文件
详细内容:
1. 导出har文件 login.har
点击File---Export Sessions--Selected Sessions..
选择下图HTTPARCHIVE V1.1 ,点击Next
保存
2.har2case -2y login.har转成yml格式生成login.yml文件
C:\Automation\Demo\learnhr\har>har2case -2y login.har INFO:root:Start to generate testcase. INFO:root:dump testcase to YAML format. INFO:root:Generate YAML testcase successfully: login.yml
3. hrun login.yml生成login_test.py文件
C:\Automation\Demo\learnhr\har>hrun login.yml 2023-05-21 11:32:29.576 | INFO | make path: C:\Automation\Demo\learnhr\har\login.yml 2023-05-21 11:32:29.591 | INFO | ensure compatibility with testcase format v2/v3 2023-05-21 11:32:29.597 | INFO | start to make testcase: C:\Automation\Demo\learnhr\har\login.yml 2023-05-21 11:32:29.603 | INFO | generated testcase: C:\Automation\Demo\learnhr\har\login_test.py 2023-05-21 11:32:29.608 | INFO | format pytest cases with black ... reformatted C:\Automation\Demo\learnhr\har\login_test.py All done! ✨ 🍰 ✨ 1 file reformatted. 2023-05-21 11:32:30.338 | INFO | start to run tests with pytest. HttpRunner version: v4.3.0 =================================================================== test session starts ==================================================================== platform win32 -- Python 3.11.0, pytest-7.2.0, pluggy-1.0.0 rootdir: C:\Automation\Demo\learnhr\har plugins: allure-pytest-2.8.6, abq-1.0.1, html-3.2.0, metadata-2.0.4, repeat-0.9.1 collected 1 item login_test.py . [100%] ===================================================================== warnings summary ===================================================================== login_test.py::TestCaseLogin::test_start C:\Speech\Python-3.11.0\Lib\site-packages\_pytest\python.py:199: PytestReturnNotNoneWarning: Expected None, but login_test.py::TestCaseLogin::test_start returned <har.login_test.TestCaseLogin object at 0x0000026495F47A10>, which will be an error in a future version of pytest. Did you mean to use `assert` instead of `return`? warnings.warn( -- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html =============================================================== 1 passed, 1 warning in 0.67s =============================================================== 2023-05-21 11:32:30.9792023-05-21 11:32:30.9842023-05-21 11:32:31.3232023-05-21 11:32:31.3282023-05-21 11:32:31.3312023-05-21 11:32:31.3352023-05-21 11:32:31.3382023-05-21 11:32:31.3412023-05-21 11:32:31.3452023-05-21 11:32:31.348
4. 执行login_test.py文件
.3382023-05-21 11:32:31.3412023-05-21 11:32:31.3452023-05-21 11:32:31.348 C:\Automation\Demo\learnhr\har>pytest login_test.py =================================================================== test session starts ==================================================================== platform win32 -- Python 3.11.0, pytest-7.2.0, pluggy-1.0.0 rootdir: C:\Automation\Demo\learnhr\har plugins: allure-pytest-2.8.6, abq-1.0.1, html-3.2.0, metadata-2.0.4, repeat-0.9.1 collected 1 item login_test.py . [100%] ===================================================================== warnings summary ===================================================================== login_test.py::TestCaseLogin::test_start C:\Speech\Python-3.11.0\Lib\site-packages\_pytest\python.py:199: PytestReturnNotNoneWarning: Expected None, but login_test.py::TestCaseLogin::test_start returned <har.login_test.TestCaseLogin object at 0x0000016854FE3F90>, which will be an error in a future version of pytest. Did you mean to use `assert` instead of `return`? warnings.warn( -- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html =============================================================== 1 passed, 1 warning in 1.27s ===============================================================
总结: 这一套流程走下来,so easy。