如何自动化一个 API ,它采用不同的查询参数组合并给出相应的结果(使用空手道)

How to automate an API which takes different combinations of query params and gives corresponding result (Using Karate)

我有一个通用的 get API,它接受多个查询参数并为每个查询参数组合给出相应的响应。定义了一组组合。我需要使 API 自动化,以便涵盖每个案例并使用空手道验证响应。我希望使用最少数量的功能文件。请提出解决方法。

你真的应该阅读文档并查看 demos 并节省很多时间。

请注意,您可以针对此用例使用 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' } |