【问题标题】:Def variable with "string" XML in Karate空手道中带有“字符串”XML 的 Def 变量
【发布时间】:2021-07-26 08:29:34
【问题描述】:

我的问题与另一个现有问题相似(对此感到抱歉),但有所不同...我的 XML 输入具有字符串格式:

* def token = '123456'
* def payload =
"""
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.com">
   <soapenv:Header/>
   <soapenv:Body>
      <ws:isValid>
         &lt;token&gt;#(token)&lt;/token&gt;
      </ws:isValid>
   </soapenv:Body>
</soapenv:Envelope>
"""
* print payload

哪些打印:

[print] <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.com">
  <soapenv:Header/>
  <soapenv:Body>
    <ws:isValid>
       &lt;token&gt;#(token)&lt;/token&gt;
    </ws:isValid>
  </soapenv:Body>
</soapenv:Envelope>

你能帮帮我吗?


我尝试了给定的解决方案,但也不起作用:

def num = '&lt;num&gt;' + random_num(5) + '&lt;/num&gt;'
[print] &lt;num&gt;39631&lt;/num&gt;

Given request:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
    <ns1>
        <ns1:XML_INPUT>     
    &lt;testone&gt;00&lt;/testone&gt;    
    &lt;numtwo&gt;267&lt;/testtwo&gt;   
    #(num)
    &lt;testthree&gt;267&lt;/testthree&gt;
        </ns1:XML_INPUT>
    </ns1>
</soap:Body>
</soap:Envelope>

【问题讨论】:

  • 欢迎来到 StackOverflow!如果您知道可能存在重复,那么添加链接而不只是提及事实会很有用。

标签: xml api karate


【解决方案1】:

试试:

* def token = '&lt;token&gt;' + 123456 + '&lt;/token&gt;'
* def payload =
"""
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.com">
   <soapenv:Header/>
   <soapenv:Body>
      <ws:isValid>#(token)</ws:isValid>
   </soapenv:Body>
</soapenv:Envelope>
"""

并阅读文档:https://github.com/intuit/karate#embedded-expressions

【讨论】:

  • 谢谢托马斯先生。我尝试了给定的解决方案但也不起作用,我已经在上面的帖子中发布了请求。你能帮帮我吗?
  • @Cherryhoney 抱歉,我对这个无效的 XML 无能为力。请只使用字符串替换。搜索有关堆栈溢出的文档或其他答案
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-03-21
  • 1970-01-01
  • 2013-10-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-03-08
相关资源
最近更新 更多