问题
My externalized XML file named "myXml.xml" is as below:
<names>
<firstname>#(fname)</firstname>
<middlename>#(mname)</middlename>
<lastname>#(lname)</lastname>
</names>
My karate feature file code is something like below (actual karate feature code is SOAP request for a different use case)
Feature: Karate load null value
Scenario: xml empty elements and null
Scenario Outline: load null values to externalized xml input
* url 'myurl'
* path'/mypath'
* request read(myXml.xml)
* soap action 'xxxxxxx'
* status 200
Examples:
| fname| mname | lname |
| f1 | m1 | l1 |
| f2 | null | l2 |
| f3 | '' | l3 |
| f4 | #null | l4 |
| f5 | | l5 |
| f6 | 'null' | l6 |
Issue: getting successful response to the first record only. Others XML formation is not been honored.
Whenever null value for 'middlename', XML needs to be formed or <middlename></middlename>
but always string values from example table is stored.
回答1:
Try this:
Scenario Outline:
* def body =
"""
<names>
<firstname>#(fname)</firstname>
<middlename>##(mname)</middlename>
<lastname>#(lname)</lastname>
</names>
"""
* print body
Examples:
| fname | mname! | lname |
| f1 | 'm1' | l1 |
| f2 | | l2 |
And read this part of the docs to see how using the !
in the column-name has an effect: https://github.com/intuit/karate#scenario-outline-enhancements
Blanks will be auto-converted to null
.
来源:https://stackoverflow.com/questions/66038179/how-to-pass-null-values-using-example-table-for-a-soap-request-record-2-6-are-f