简体   繁体   English

如何在空手道中迭代多个特征文件

[英]How to iterate multiple feature files in karate

Feature File 1:inputData.feature特征文件 1:inputData.feature

     @ignore
     Feature: Input data table
     Scenario: Input table for testing
* table testData
  | accountId           |  accountname    | expectedAccount  |
  | 'ADS5678543'   | 'Peter'              | 'DFCVSAEFRG'     |
  | 'ASDCF45678'   | 'Caroline'           |  'DFCWEAEFRG'    |

File 2: payload.json文件 2:payload.json

{
"channelData": {
"data": "CHANNEL_DATA",
"salesChannel": "WEB",
"createdBy": "WEBSITE",
"accountId": "#(accountId)",
"sessionId": "#(accountname)"
 }
}

File 3: Request.feature文件 3:Request.feature

@ignore
Feature:

Scenario:
 # read the payload from json file
 * def Request = read('../payload.json')
 * def headersData = { "Content-Type" : "application/json"}
 Given url BaseUrl + '/account/'+'#(accountId)'
 And request Request
 And headers headersData
 When method post
 Then status 200
 * print response
  * def account = karate.jsonPath(response, "$.account")
 * print 'account is '+account
 Then match account == '#(expectedAccount)'

File 4: addressinfo.feature文件 4:addressinfo.feature

@ignore
Feature:

Scenario:
   * def Request = “{
     “accountId": "#(resAccount)”
    }
 ”
 * def headersData = { "Content-Type" : "application/json"}
 Given url BaseUrl +'#(resAccount)’+'/address’
 And request Request
 And headers headersData
 When method post
 Then status 200
 * print response

File5: Account-token.feature File5: Account-token.feature

  Feature: 
Scenario: identify the reference account
 * def initTestData = read('../inputData.feature')
 * def reqRes = karate.call('../Request.feature', { initTestData : initTestData })
 * def resAccount =  $reqRes[*].account // output of this is [“SB987658”,”SB984345”]
 * def addressData = read('../addressinfo.feature’,{resAccount: resAccount}) 

In the above scenario, we have to pass the output of Request.feature as input to addressing.feature.在上面的场景中,我们必须将 Request.feature 的输出作为输入传递给addressing.feature。 java.net.URISyntaxException: Illegal character in path at index 34: http://10.36.145.196:9983/invoker/[ “SB987658”,”SB984345”]/address . java.net.URISyntaxException:索引 34 处的路径中存在非法字符: http ://10.36.145.196:9983/invoker/ [ “SB987658”,“SB984345”]/address。 Our requirement is it should iterate each value of resAccount and we need to pass the o/p response of addressinfo.feature as I/p to another feature file.我们的要求是它应该迭代 resAccount 的每个值,我们需要将 addressinfo.feature 的 o/p 响应作为 I/p 传递给另一个特征文件。

The rule for call args that need to be looped is that it has to be an array of JSONs.需要循环的call参数的规则是它必须是一个 JSON 数组。 Refer: https://github.com/intuit/karate#data-driven-features参考: https : //github.com/intuit/karate#data-driven-features

So you can transform the primitive array, refer: https://github.com/intuit/karate#json-transforms所以你可以转换原始数组,参考: https : //github.com/intuit/karate#json-transforms

* def resAccountList = karate.map(resAccount, function(x){ return { resAccount: x } })

I have to say your tests are badly designed and will cause you maintenance problems in the future.我不得不说你的测试设计得很糟糕,将来会给你带来维护问题。 Try to avoid "too much reuse" and avoid call as far as possible.尽量避免“过多重用”,尽量避免call Refer to this answer for why: https://stackoverflow.com/a/54126724/143475请参阅此答案以了解原因: https : //stackoverflow.com/a/54126724/143475

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 空手道独立作为具有多个功能文件的模拟服务器 - Karate Standalone as Mock Server with multiple Feature Files 如何使用特征文件在空手道中实现 for 循环 - How to implement for loop in karate using feature files 空手道中如何执行其他目录特征文件 - How to execute other directory feature files in karate 如何在空手道 DSL 中跨环境并行执行测试(多个特征文件) - How to execute tests (multiple feature files) across environments in parallel in Karate DSL 空手道API测试-如何遍历读取多个json文件以用作单个场景的请求? - Karate API Testing- how to iterate over reading multiple json files to be used as request for a single scenario? 使用多个标签选择器从空手道测试中调用其他功能文件 - Call other feature files from Karate test with multiple tag selectors 如何使用 gradle 获取空手道测试功能文件的 Jacoco 报告 - How to get Jacoco reports for the Karate test feature files using gradle 如何使用从 karate-config.js 到 .feature 文件的变量 - How to use the variables from karate-config.js to .feature files 如何在空手道 API 中为所有功能文件设置全局标头 - How to set global header for all feature files in Karate API 空手道 - 如何从单个主要功能调用多个外部功能 - Karate - How to call multiple external features from a single main feature
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM