We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
分层机制强调定义好一个API用例后交给另外一个用例来引用,而不是每个用例都全部再写一遍。
为了能让API用例满足不同的场景,需要在早期就尽可能的对API用例考虑周全并设计足够通用的能力。 比如说要预留足够多的断言变量,向上暴露足够多的响应数据,场景举例:
登录接口用例设计: 站在API用例的角度来讲,它其实不应该关心断言, 但是为了足够通用,这里就需要设计一些变量来传递给validate来完成断言.
login-api.yml
config: name: "module variable" desc: "这里定义的是当前API要求必填的参数" variables: host: "" username: "" password: "" status_code: "" body_status: "" body_msg: "" teststeps: - name: login request: method: POST url: "${host}/login" headers: User-Agent: HttpRunner/${get_httprunner_version()} Content-Type: "application/x-www-form-urlencoded" data: "username=${username}&password=${password}" validate: - eq: ["status_code", "${status_code}"] - eq: ["body.status", "${body_status}"] - eq: ["body.msg", "${body_msg}"]
如果能对API用例进行扩展断言,那么就意味着可以对场景进行封装,例如: 将登录接口封装成登录成功场景、登录失败场景。
登录成功场景
登录失败场景
config: name: "module variable" desc: "这里定义的是当前API要求必填的参数" variables: host: "" username: "" password: "" teststeps: - name: login request: method: POST url: "${host}/login" headers: User-Agent: HttpRunner/${get_httprunner_version()} Content-Type: "application/x-www-form-urlencoded" data: "username=${username}&password=${password}"
login-success.yml
config: name: "module variable" teststeps: - name: login testcase: apis/login-api.yml variables: host: "http://127.0.0.1:8888" username: "zhangsan" password: "zhangsan123" validate: - eq: ["status_code", 200] - eq: ["body.status", 200] - eq: ["body.msg", "login success"]
login-fail.yml
config: name: "module variable" teststeps: - name: login testcase: apis/login-api.yml variables: host: "http://127.0.0.1:8888" username: "zhangsan" password: "lisi123" validate: - eq: ["status_code", 200] - eq: ["body.status", 400] - eq: ["body.msg", "login failed"]
通过这种扩展方式,在后续写用例中只对登录成功、登录失败进行引用。
登录成功
登录失败
The text was updated successfully, but these errors were encountered:
feature: httprunner#1142 extend the last one of the step in sub-testcase
5534492
feature: httprunner#1142 extend validate for the last one of the step…
e75f1b0
… in sub-testcase
debugtalk
No branches or pull requests
背景描述
分层机制强调定义好一个API用例后交给另外一个用例来引用,而不是每个用例都全部再写一遍。
为了能让API用例满足不同的场景,需要在早期就尽可能的对API用例考虑周全并设计足够通用的能力。
比如说要预留足够多的断言变量,向上暴露足够多的响应数据,场景举例:
登录接口用例设计:
站在API用例的角度来讲,它其实不应该关心断言,
但是为了足够通用,这里就需要设计一些变量来传递给validate来完成断言.
login-api.yml
期望的功能特性
如果能对API用例进行扩展断言,那么就意味着可以对场景进行封装,例如: 将登录接口封装成
登录成功场景
、登录失败场景
。login-api.yml
login-success.yml
login-fail.yml
通过这种扩展方式,在后续写用例中只对
登录成功
、登录失败
进行引用。The text was updated successfully, but these errors were encountered: