Karate - editing xml while running the test case

∥☆過路亽.° 提交于 2021-02-02 09:36:13

问题


I have the following xml:

<?xml version="1.0" encoding="utf-8"?>
<request>
    <head>
        <session-id>none</session-id>
    </head>
    <service name="test">
        <function name="testFunc">
            <guids>
                <guid>#guid#</guid>
                <guid>#guid#</guid>
            </guids>
        </function>
    </service>
</request>

I have 2 test cases:

  1. i want to test with single guid.
  2. I want to test with 2 guids.

I created 2 separate xml for both the test cases and it worked. The question here is how can i use a common xml? Also i tried using remove but how do i remove single guid from the xml?


回答1:


There is something called "embedded expressions" in Karate. Read the docs: https://github.com/intuit/karate#embedded-expressions

Example:

* def guids = <guids><guid>one</guid><guid>two</guid></guids>
* def body = <root>#(guids)</root>

Also refer this file, it has a lot of other examples and ideas for XML data-driven tests: xml.feature.



来源:https://stackoverflow.com/questions/63432787/karate-editing-xml-while-running-the-test-case

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!