如何自动化采用不同查询参数组合并给出相应结果的API(使用空手道) [英] How to automate an API which takes different combinations of query params and gives corresponding result (Using Karate)

查看:27
本文介绍了如何自动化采用不同查询参数组合并给出相应结果的API(使用空手道)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a versatile get API which takes multiple query params and gives a corresponding response for each combination of query params. The set of combinations is defined. I need to automate the API so that each case is covered and the response is verified using Karate. I wish to use minimum number of feature files. Please suggest a way to go about it.

推荐答案

您应该真正阅读文档并查看演示,并节省了很多时间.

You should really read the docs and look at the demos and save yourself a lot of time.

请注意,您可以使用

Note that you can use the params keyword for this use-case, and null values will be ignored (no query param will be set).

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' } |

这篇关于如何自动化采用不同查询参数组合并给出相应结果的API(使用空手道)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆