【问题标题】:Is there a way in Karate to call a Feature multiple time using karate.repeat or any other way?空手道有没有办法使用 karate.repeat 或任何其他方式多次调用功能?
【发布时间】:2019-07-30 22:42:00
【问题描述】:

我正在尝试测试需要发布 100 次请求的场景(这不是性能测试)。我可以通过设置每 100 行来使用表格功能,其中每行代表一个请求。然而,这将是冗长乏味的。

所以我找到了 Karate.repeat 并希望这可以解决问题。我只是想知道是否有其他方法可以实现我的目标。

* def users = function(i){ call read("classpath:v1/createCustomer.feature") { "firstName": '#(firstName)', "lastName": '#(lastName)' }
* def usersResult = karate.repeat(2, users )
* match usersResult [*].responseStatus == [204, 204]

我希望该功能会被调用两次。

【问题讨论】:

    标签: karate


    【解决方案1】:

    您应该可以为此使用repeat,但不要在DSL 中使用call,而是使用karate.call

    * def users = function(i){ return karate.call("classpath:v1/createCustomer.feature", { "firstName": '#(firstName)', "lastName": '#(lastName)' }) 
    * def usersResult = karate.repeat(2, users ) 
    * match each usersResult[*].responseStatus == 204
    

    如果您希望每次通话使用不同的数据,还建议您检查空手道中的data drivendynamic scenario outline 选项。正如您在问题中提到的,而不是 100 行数据的表格,您可以使用 json 数组或 csv 来实现相同的目的。

    【讨论】:

    • 谢谢巴布,上面的代码有效。我更喜欢这种技术,而不是必须创建一个外部 csv 文件。这种技术简洁易懂
    猜你喜欢
    • 2021-07-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-18
    • 2010-12-24
    • 2017-05-19
    • 1970-01-01
    相关资源
    最近更新 更多