问题
I am calling login feature from another feature under background tag by passing un, pwd and endpoint url like below. Login feature is running successfully but the response of it is not returned to called feature file.
@Add
Feature: Adding products
Background:
* table loginDetails
| username | password | endPointURL |
| 'kUser' | 'kPass' | 'https://qa1.com/shop/login/login' |
* def result = call read('Login.feature') loginDetails
* print 'Result-'+response
* print 'Result-'+result.response
@loginTest
Scenario: running @loginTest from runner file
* print 'Login response -'+result.responseCookies
This is what i am getting in response.
13:08:53.470 [main] INFO com.intuit.karate - [print] {
"redirect": false,
"loginSuccess": true,
"redirectUrl": ""
}
13:08:53.519 [main] INFO com.intuit.karate - [print]
13:08:53.546 [main] INFO com.intuit.karate - [print] RUResult-undefined
13:08:53.547 [main] INFO com.intuit.karate - [print] Login response -undefined
回答1:
When you pass a data table/ JSON array to the called feature you will get JSON array in return.
Here result
object will have JSON array/list like data, so you have to read that variable accordingly
for the above example try,
* print result[0].response
* print result[0].responseCookies
来源:https://stackoverflow.com/questions/54466959/karate-api-why-response-in-not-returning-to-called-feature-file