【问题标题】:Karate Embedded Expression not working as expected for xml attribute空手道嵌入式表达式无法按预期为 xml 属性工作
【发布时间】:2018-03-07 12:57:50
【问题描述】:

这是:3_PostData_Request.xml

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<S:Envelope xmlns:S="http://www.w3.org/2003/05/soap-envelope">
    <S:Body>
        <SucceededGetData RequestID="#(request_uuid)">some text</SucceededGetData>
        <MessageDelivered OfferID="#(request_uuid)" />

    </S:Body>
</S:Envelope>

这是场景文件:

Scenario: test
    * def UUID = function(){ return java.util.UUID.randomUUID() }
    * def request_uuid = call UUID
    * def req = read('classpath:3_PostData_Request.xml')
    * print req

这是结果:

<S:Body>
    <SucceededGetData RequestID="ab5bbb38-d462-42f5-afd2-49c47fd59365">some text</SucceededGetData>
    <MessageDelivered OfferID="#(request_uuid)"/>
  </S:Body>
</S:Envelope>

我想知道为什么会这样。为什么空手道能够将 #(request_uuid) 替换为包含一些文本的 xml 元素,为什么不能替换没有任何文本的元素。我怎样才能在这两种情况下无缝地实现替换。我正在使用空手道 0.7.0.1。谢谢!

我也在他们的 Git 存储库中添加了一个问题。等待他们的回复。 https://github.com/intuit/karate/issues/341

【问题讨论】:

    标签: xml karate


    【解决方案1】:

    是的,这是一个错误!您有一个解决方法:

    * set response /Envelope/Body/MessageDelivered/@OfferID = request_uuid
    

    【讨论】:

    • 感谢彼得的快速回复。解决方法解决了我的问题,但是我想避免在我的场景中编写 xpath。不用担心,我看到你在 0.7.1 版本中修复了这个问题。将等待它在 Maven 中可用。另外为了其他人的帮助,我还使用了另一种解决方法:在scenarioFile中:*替换req.${request_uuid} = request_uuid并在xml中我将:OfferID="#(request_uuid)"改为OfferID="${request_uuid}"
    猜你喜欢
    • 1970-01-01
    • 2017-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-07
    • 1970-01-01
    相关资源
    最近更新 更多