karate - 如何自动化一个 API,它采用不同的查询参数组合并给出相应的结果(使用空手道)
问题描述
我有一个通用的 get API,它接受多个查询参数并为每个查询参数组合提供相应的响应。组合的集合被定义。我需要自动化 API,以便涵盖每个案例并使用空手道验证响应。我希望使用最少数量的功能文件。请提出一种解决方法。
解决方案
您真的应该阅读文档并查看演示并节省大量时间。
请注意,您可以params
为此用例使用关键字,并且null
值将被忽略(不会设置查询参数)。
Scenario Outline:
* def query = { name: <name>, country: <country>, active: <active>, limit: <limit> }
Given path 'search'
And params query
When method get
Then status 200
# response should NOT contain a key expected to be missing
And match response !contains <missing>
# observe how strings are enclosed in quotes, and we set null-s here below
# and you can get creative by stuffing json into table cells !
Examples:
| name | country | active | limit | missing |
| 'foo' | 'IN' | true | 1 | {} |
| 'bar' | null | null | 5 | { country: '#notnull', active: '#notnull' } |
| 'baz' | 'JP' | null | null | { active: '#notnull', limit: '#notnull' } |
| null | 'US' | null | 3 | { name: '#notnull', active: '#notnull' } |
| null | null | false | null | { name: '#notnull', country: '#notnull', limit: '#notnull' } |
推荐阅读
- python - Dockerfile,如何将文件修改为Docker内部的pip包
- javascript - 我是否需要分解声明以使用 d3.js 中的侦听器更新图表?
- python-3.x - 继承类中的方法
- nginx - 使用 nginx 生成文件内容
- python - 如何在 Conda 上添加显式 pip 依赖项
- reactjs - 如何为我的 react 项目创建一个全局 CSS 文件以应用于所有组件?
- authentication - Blazor WebAssembly 用于在标头中自动发送 Google 身份验证信息(即 id 令牌和访问令牌),但现在不
- azure - 如何在 Azure 数据工厂中编写筛选条件
- hadoop - 尽管使用 EJ001 运行 oozie-setup.sh sharelib,但 Oozie 工作流示例失败
- javascript - 如何在 nodeJS 中进行适当的导出