空手道中带有“字符串”XML 的 Def 变量

问题描述 投票:0回答:2

我的问题与另一个现有问题类似(对此感到抱歉),但有一些不同......我的 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>
xml api karate
2个回答
0
投票

尝试:

* 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


0
投票

@cherryhoney,你找到解决方案了吗?我也面临着同样的问题。如果问题解决了,请告诉我

© www.soinside.com 2019 - 2024. All rights reserved.