繁体   English   中英

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

[英]Def variable with "string" XML in Karate

我的问题与另一个现有的问题相似(对此感到抱歉)但有所不同...我的 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>

尝试:

* 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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM