[英]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.