欢迎回来
没有账号?
前往注册
HttpRunner框架的初体验(五)文章摘要
继续:
2.自动生成httprunner的python代码:
运行完成yaml/json文件后,会在当前目录中,看到自动生成的httprunner的python文件login_test.py
# NOTE: Generated By HttpRunner v3.1.4
# FROM: login.yml
from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase
class TestCaseLogin(HttpRunner):
config = Config("testcase description")
teststeps = [
Step(
RunRequest("/agileone/index.php/common/login")
.post("http://localhost/agileone/index.php/common/login")
.with_headers(
**{
"Content-Type": "application/x-www-form-urlencoded",
"Sec-Fetch-Dest": "empty",
"Sec-Fetch-Mode": "cors",
"Sec-Fetch-Site": "same-origin",
"User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36",
"X-Requested-With": "XMLHttpRequest",
}
)
.with_data({"password": "admin", "savelogin": "true", "username": "admin"})
.extract()
.with_jmespath("body", "msg")
.with_jmespath('headers."Set-Cookie"', "cookie")
.validate()
.assert_equal("status_code", 200)
.assert_equal('headers."Content-Type"', "text/html")
.assert_equal("$msg", "successful")
),
]
if __name__ == "__main__":
TestCaseLogin().test_start()所以,可以通过python的方式直接运行当前的测试脚本,完成测试并生成与前面一致的日志文件。
3. 生成测试报告
httprunner封装的pytest.所以可以直接使用命令的方式生成pytest风格的报告。
通过命令:hrun login.yml --html=report.html
生成报告

第一个分享就到这,目前遗留问题。正文断言如何实现、接口如何关联、参数如何传递
版权所有,转载本站文章请注明出处:蜗牛学院在线课堂, http://www.woniuxy.com/note/676