空手道 - 如何将XML响应保存为XML以后使用?

发布于 2025-02-01 18:50:08 字数 740 浏览 2 评论 0原文

我正在发送一个请求,该请求返回XML中的响应。 当响应首先回来时,我可以从XML提取值,如下示例所示。

* def balanceAmount = $response/Envelope/Body/balanceAmount/amount
And print balanceAmount

但是,我然后发送另一个请求,以使上述响应被覆盖 - 因此我需要将其保存为XML-因此我可以在测试中以后回想起这些值。

我已经尝试了许多方法来完成此操作,包括以下内容:

* def xmlResponse = $response
* def xmlResponse = response
* xml xmlResponse = $response
* xml xmlResponse = response

但是我无法像以前那样访问XML响应中的值。

我已经尝试过这些:

* def balanceAmount = xmlResponse/Envelope/Body/balanceAmount/amount
And print balanceAmount

* def balanceAmount = $xmlResponse/Envelope/Body/balanceAmount/amount
And print balanceAmount

以上都没有作用。

那么,如何将XML响应保存为XML,以便在发送其他请求后在测试中以稍后从其中提取值?

I am sending a request that returns a response in XML.
When the response first comes back I can extract values from the XML as shown in the example below.

* def balanceAmount = $response/Envelope/Body/balanceAmount/amount
And print balanceAmount

However I then send another request so the above response is overwritten - so I need to save it as XML - so I can recall the values later on in the test.

I have tried many ways of doing this including the following:

* def xmlResponse = $response
* def xmlResponse = response
* xml xmlResponse = $response
* xml xmlResponse = response

But I can no longer access the values in the XML response like I could earlier.

I've tried these:

* def balanceAmount = xmlResponse/Envelope/Body/balanceAmount/amount
And print balanceAmount

* def balanceAmount = $xmlResponse/Envelope/Body/balanceAmount/amount
And print balanceAmount

None of the above works.

So how can I save the xml response as xml so I can extract values from it later on in the test after sending a different request?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月棠 2025-02-08 18:50:08

它对我来说很好,这里可以尝试此独立功能:

Feature:

  Scenario:
    * url 'https://httpbin.org/xml'
    * method get
    * def firstResponse = response

    * url 'https://httpbin.org/get'
    * method get

    * match firstResponse ==
    """
    <slideshow
        title="Sample Slide Show"
        date="Date of publication"
        author="Yours Truly">
        <slide type="all">
          <title>Wake up to WonderWidgets!</title>
        </slide>
        <slide type="all">
            <title>Overview</title>
            <item>Why <em>WonderWidgets</em> are great</item>
            <item/>
            <item>Who <em>buys</em> WonderWidgets</item>
        </slide>
    </slideshow>
    """
    * def firstSlide = $firstResponse/slideshow/slide[1]
    * match firstSlide == <slide type="all"><title>Wake up to WonderWidgets!</title></slide>

如果您仍然卡住-issue“ rel =“ nofollow noreferrer”> https://github.com/karatelabs/karate/wiki/how-to-to-submit-an-sissue

It works fine for me, here try this stand-alone feature:

Feature:

  Scenario:
    * url 'https://httpbin.org/xml'
    * method get
    * def firstResponse = response

    * url 'https://httpbin.org/get'
    * method get

    * match firstResponse ==
    """
    <slideshow
        title="Sample Slide Show"
        date="Date of publication"
        author="Yours Truly">
        <slide type="all">
          <title>Wake up to WonderWidgets!</title>
        </slide>
        <slide type="all">
            <title>Overview</title>
            <item>Why <em>WonderWidgets</em> are great</item>
            <item/>
            <item>Who <em>buys</em> WonderWidgets</item>
        </slide>
    </slideshow>
    """
    * def firstSlide = $firstResponse/slideshow/slide[1]
    * match firstSlide == <slide type="all"><title>Wake up to WonderWidgets!</title></slide>

If you are still stuck, follow this process: https://github.com/karatelabs/karate/wiki/How-to-Submit-an-Issue

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文