Skyx
Skyx

Reputation: 103

Karate get one variable from a request

    Given request
"""
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.openkm.com">
   <soapenv:Header/>
   <soapenv:Body>
      <ws:login>
         <!--Optional:-->
         <user>TestUser</user>
         <!--Optional:-->
         <password>TestUser</password>
      </ws:login>
   </soapenv:Body>
</soapenv:Envelope>
"""
When soap action 'http://ws.openkm.com/OKMAuth/login'
Then status 200
  * def token = //return

Result = response={soap:Envelope={={soap:Body={ns2:loginResponse={=‌​ {return=a866fb4f-47e‌​4-4895-ac13-2118b6c0‌​25c8}, @={xmlns:ns2=ws.openkm.com}}}}, @={xmlns:soap=schemas.xmlsoap.org/soap/envelope}}}, responseStatus=200, __loop=-1, responseCookies=null, token=a866fb4f-47e4-4895-ac13-2118b6c025c8}

I got this response from a request. How can I get the 'return' or the 'token' from the body?

Upvotes: 1

Views: 1156

Answers (1)

Peter Thomas
Peter Thomas

Reputation: 58128

You don't seem to have read the documentation on calling features. Unless you are clear about how it works, I recommend you don't use call at all.

I am (still) not able to read your response XML, so I can't say if //return actually gets you the value you want. Assuming that it does, you have now assigned it to a variable called result in RequestToken.feature right. So now, try this:

# this result will again contain a variable 'result'
* def result = call creator
* def return = result.result
* print return

I can't help more unless you read the doc carefully, all the best.

Upvotes: 1

Related Questions