Файл функций 1: inputData.feature
@ignore
Feature: Input data table
Scenario: Input table for testing
* table testData
| accountId | accountname | expectedAccount |
| 'ADS5678543' | 'Peter' | 'DFCVSAEFRG' |
| 'ASDCF45678' | 'Caroline' | 'DFCWEAEFRG' |
Файл 2: payload.json
{
"channelData": {
"data": "CHANNEL_DATA",
"salesChannel": "WEB",
"createdBy": "WEBSITE",
"accountId": "#(accountId)",
"sessionId": "#(accountname)"
}
}
Файл 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)'
File4: Account-token.feature
Feature:
Scenario: identify the reference account
* def initTestData = read('../inputData.feature')
* def reqRes = karate.call('../Request.feature', { initTestData : initTestData })
* def temp = $reqRes[*].account
* def resAccount = temp[0]
В приведенном выше сценарии значения не были успешно переданы в запросе JSON .:
1.) Нам нужно прочитать значение accountId & accountname из inputData.feature и обновить параметры payload.json.
2.) Также мы должны передать значение ожидаемого аккаунта в Request.feature для подтверждения.