如何从场景大纲中获取一列的值作为空手道中的数组

Posted

技术标签:

【中文标题】如何从场景大纲中获取一列的值作为空手道中的数组【英文标题】:How to get values for one column from scenario outline as an array in Karate 【发布时间】:2021-09-12 00:03:26 【问题描述】:

我有一个如下的 request.json

    
    "country":"#(country)",
    "states":["#(states)"]
    

我的功能文件

    Scenario outline: test

    *def req = call('request.json')
    And request req
    When method post

    Examples:
    |country|states|
    |India|delhi,goa|

使用上面的代码,我得到了

    
    "country":"India",
    "states":["delhi,goa"]
    

但我希望我的请求如下所示

    
    "country":"India",
    "states":["delhi","goa"]
    

是否有任何直接的方式来获得上述要求。

【问题讨论】:

【参考方案1】:

进行此更改:

Examples:
|country|states!|
|India|['delhi','goa']|

参考:https://github.com/intuit/karate#scenario-outline-enhancements

【讨论】:

它工作得很好,谢谢唯一的变化是在 request.json 我必须删除状态“states”的 []:“#(states)”

以上是关于如何从场景大纲中获取一列的值作为空手道中的数组的主要内容,如果未能解决你的问题,请参考以下文章