【问题标题】:Karate get one variable from a request空手道从请求中获取一个变量
【发布时间】:2017-12-11 16:03:47
【问题描述】:
    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

结果 = 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,令牌=a866fb4f-47e4-4895-ac13-2118b6c025c8}

我从一个请求中得到了这个响应。如何从 body 中获取“return”或“token”?

【问题讨论】:

标签: json api karate


【解决方案1】:

您似乎没有阅读过calling features 上的文档。除非您清楚它的工作原理,否则我建议您根本不要使用 call

我(仍然)无法读取您的响应 XML,所以我不能说 //return 是否真的为您提供了您想要的价值。假设确实如此,您现在已将其分配给RequestToken.feature 中名为result 的变量。所以现在,试试这个:

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

除非您仔细阅读文档,否则我无法提供更多帮助,一切顺利。

【讨论】:

  • 感谢彼得的快速解答!现在一切正常。
  • @Skyx *phew* !很高兴听到这个消息:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-08-24
  • 1970-01-01
  • 2020-06-07
  • 1970-01-01
相关资源
最近更新 更多