【问题标题】:karate - Can we fetch data from excel file in karate? if yes then can we set the fetch data in examples in scenario outline?karate - 我们可以从空手道的 excel 文件中获取数据吗?如果是,那么我们可以在场景大纲的示例中设置获取数据吗?
【发布时间】:2019-02-14 17:47:32
【问题描述】:
 Examples:
      |sku_code |property_code |sale_price |override_source|persistent_override | stay_date|
      |'48'     | '0001661'    |  2000     |'DASHBOARD'    | 'true'             |   2      |

就像我对这些数据进行了硬编码一样,我希望从 Excel 表中获取这些数据!

【问题讨论】:

    标签: karate


    【解决方案1】:

    是的,您可以使用csv 在空手道中使用动态场景大纲来完成

    空手道演示示例:

    Scenario Outline: cat name: <name>      
     Given url demoBaseUrl 
     And path 'cats' 
     And request { name: '<name>', age: <age> } 
     When method post 
     Then status 200 
     And match response == { id: '#number', name: '<name>' } 
     Examples: 
     | read('kittens.csv') |
    

    链接:

    Dynamic csv demo

    Dynamic scenario outline doc

    【讨论】:

    • 非常感谢您的回答,但我还有一个查询,如果我想访问 csv 文件中的选定列(比如它有 10 列,我只能访问 2 和 3 列),那么有可能吗?
    • 从技术上讲,您的 csv 将被转换为 json 数组。所以你可以使用 jsonpath 来提取你想要的任何数据。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-05
    • 1970-01-01
    • 1970-01-01
    • 2016-04-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多