空手道 API 在 XML 中传递 def 变量
Karate API pass def variable in XML
我用
定义了一个变量
* def token = '1bce02b8..'
我想检索我定义的变量,以便将其传递给我的 SOAP 请求。我怎样才能做到这一点?
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.com">
<soapenv:Header/>
<soapenv:Body>
<ws:isValid>
<token>$token</token>
</ws:isValid>
</soapenv:Body>
</soapenv:Envelope>
简单,在 #(foo)
形式中使用 embedded expressions,它们也适用于 XML:
* def token = 'foo'
* def payload =
"""
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.com">
<soapenv:Header/>
<soapenv:Body>
<ws:isValid>
<token>#(token)</token>
</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>
<token>foo</token>
</ws:isValid>
</soapenv:Body>
</soapenv:Envelope>
我建议你也参考这组例子,专门针对XML,会给你更多的想法:xml.feature
我用
定义了一个变量* def token = '1bce02b8..'
我想检索我定义的变量,以便将其传递给我的 SOAP 请求。我怎样才能做到这一点?
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.com">
<soapenv:Header/>
<soapenv:Body>
<ws:isValid>
<token>$token</token>
</ws:isValid>
</soapenv:Body>
</soapenv:Envelope>
简单,在 #(foo)
形式中使用 embedded expressions,它们也适用于 XML:
* def token = 'foo'
* def payload =
"""
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.com">
<soapenv:Header/>
<soapenv:Body>
<ws:isValid>
<token>#(token)</token>
</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>
<token>foo</token>
</ws:isValid>
</soapenv:Body>
</soapenv:Envelope>
我建议你也参考这组例子,专门针对XML,会给你更多的想法:xml.feature