如何在空手道 DSL 中操作 xml 文件的变量?

How to manipulate xml file's variable in Karate DSL?

使用 Karate DSL 的 SOAP 服务的示例数量非常有限。

我想做的是创建一个 XML 文件,稍后我将使用它作为模板。因为它将成为一个模板,所以我需要使它的某些部分动态化。 在 .json 文件上很容易实现,但我找不到在 .xml[ 上实现它的示例=35=] 个文件。

下面是我的 .xml 文件:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.bigldap.ttech.com/">
<soapenv:Header/>
<soapenv:Body>
    <ws:createwMsisdn>
        <name></name>
        <password>1</password>
        <appId>1</appId>
    </ws:createwMsisdn>
</soapenv:Body>

我想将 name 部分转换为动态变量。

我试过 .replace.set 空手道的方法,但没有用。

* def user = read ('classpath:xxx/assign-name-password.xml')
* replace user.name = anotheruser.username
* print user

当打印工作时,它只向我显示标签,作为空标签。 () 我找不到任何相关示例。

任何帮助将不胜感激。 提前致谢。

我想你错过了这组例子,它在文档中被引用但不是演示的一部分:xml.feature

我想你会喜欢你找到的。有很多选项,包括通过数据驱动表,下面只是几个选项:

* def name = 'John Smith'
* def xml =
"""
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.bigldap.ttech.com/">
<soapenv:Header/>
<soapenv:Body>
    <ws:createwMsisdn>
        <name>#(name)</name>
        <password>1</password>
        <appId>1</appId>
    </ws:createwMsisdn>
</soapenv:Body>
</soapenv:Envelope>
"""
* match xml//name == 'John Smith'
* set xml/Envelope/Body/createwMsisdn/name = 'Jane Doe'
* match xml//name == 'Jane Doe'