简体   繁体   中英

Karate- get value of a field from response in another feature file

I have a scenario where i need to get a specific field from a response of another feature file and re-use it.

Scenario:- Feature file A deals with POST where i get a response and save the field userId in a variable myuser.
Sample response:- { user:"123" tier:"diamond" }

i save the value as *def myuser =response.user

I want to call feature file A from another feature file B. I do not want to pass any parameter to feature file A. My code looks like

  • def ReponseA = read('classpath:FeaturefileA.feature')
  • def currentuser =ResponseA.user

This might be incorrect.My basic need is to get the myuser value from Feature file A to a variable in Feature file B and use in sceanrios for feature file B.Kindly advise. Thank you.

(a.feature) Feature file A: POST Method which gives you response as follows:

{ user:"123" tier:"diamond" }

(b.feature) Feature file B:

 * def fileA = call read('../FOLDER NAME/a.feature')
 * def fileAResponse = fileA.response
 * print fileAResponse

the above code in b.feature will print the response of a.feature

Hope this is what you want?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM