从csv列A中读取请求,并将响应与空手道中同一CSV中的列B(json)进行比较

时间:2019-10-02 18:24:09

标签: karate

我坚持进行以下验证:将csv中的JSON与API的实际响应进行比较

Feature: Regression
Background:
        * url demoBaseUrl       
        * configure headers = read('classpath:headers.js')

Scenario Outline: Compare results id: <id>
    Given path '/v1/emp/'+id+'/path'
    When method get
    Then status 200
    * def actual = response         
    And match actual== <Response>
    # And match response == <Response> -- did not work  
    #read('expected.json')
Examples:
    | read('data.csv') |

我的data.csv具有以下内容:

data.csv

我正在尝试创建一个回归套件,将API的实际JSON响应与csv中的列进行比较。 但出现definition method match not found for: match例外!

1 个答案:

答案 0 :(得分:0)

我让它正常工作(但是带有硬编码索引!)

Feature: Regression
Background:
            * url demoBaseUrl
            * configure headers = read('classpath:headers.js')
            * def jsonFromCsv =  read('data.csv')
            * def counter1 = function(count) {var x = [], i = 0;while (i <= count) {  x.push(i);  i++;} return x}
            * def size = karate.sizeOf(jsonFromCsv)
            * def x1 = call counter1 size
Scenario Outline: empid: eid
        Given path '/v1/emp/'+jsonFromCsv[x1[0]].eid+'/path' #something like this
        When method get
        Then status 200
        And match response == jsonFromCsv[x1[1]].Response  #something like this
      Examples: 
      | read('data.csv') |

但是我在使用* def jsonFromCsv = read('data.csv')时有一个疑问 也必须强制使用Examples: | read('data.csv') |吗?由于删除Examples时出现以下异常: line 17:23 extraneous input '<EOF>' expecting {EXAMPLES, STAR, GIVEN, WHEN, THEN, AND, BUT, TAGS} 10:59:31.511 [main] ERROR com.intuit.karate.core.FeatureParser - syntax error: extraneous input '<EOF>' expecting {EXAMPLES, STAR, GIVEN, WHEN, THEN, AND, BUT, TAGS} 我们在这里两次读取文件吗?还是我想念什么?