空手道:dynamic-csv.feature是否可以用于“获取请求”,如何从CSV传递动态路径参数?

问题描述

尝试为GET方法从CSV传递动态路径参数。

引用Karate: how to pass dynamic path parameters?

我们正在尝试从CSV文件的路径中传递动态参数,但是当方法为GET时,它不能很好地工作,尽管对于POST,使用CSV时没有问题。

此处借助开放的API进行详细说明

Feature: Get users details based on valid and invalid inputs from csv file

  Background:

  * url 'https://reqres.in'

    Scenario Outline: Get single user based on id value - Valid & invalid
      Given path '/api/users/<id>'

      When method <method>
      Then status <status>

      * print response
      ##* match response.data.id contains <id>

      Examples:
        |id|status|method|Scenario|
        |2|200|GET|Valid id as input|
        |4|200|GET|Valid id as input|
        |5|200|GET|Valid id as input|
        |&|404|GET|Special character as Input|
        | |404|GET|Empty space as Input|
        |A|404|GET|Alphabet as input|
        |999|404|GET|Invalid Number as input|
        |-1|404|GET|Invalid Number as input|

这很好用,但是当我尝试跟着传递相同的数据时不起作用

  |read('../../Data/users.csv')|

这是此CSV的外观 users data csv file

解决方法

根据给出的数据很难说,it doesn't work没有帮助。也许特殊字符会引起问题。最好的方法是遵循以下过程:https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue

通常,我不建议在不利情况下使用Scenario Outline。一些指导可以在这里找到:https://stackoverflow.com/a/54126724/143475

要对CSV进行故障排除,您可以尝试* print __row查看每一行中的值。

这对我有用:

Scenario Outline:
* url 'https://httpbin.org'
* path 'post'
* request __row
* method post

Examples:
| read('test.csv') |

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...