Karate API - Why response in not returning to called feature file

我怕爱的太早我们不能终老 提交于 2021-01-20 11:35:42

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!