问题
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:
- i want to test with single guid.
- 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