Karate get one variable from a request

时光总嘲笑我的痴心妄想 提交于 2019-12-11 07:41:09

问题


    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?


回答1:


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.



来源:https://stackoverflow.com/questions/47756777/karate-get-one-variable-from-a-request

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