how to pass null values using example table for a SOAP request. Record 2-6 are forming fault XML request

北战南征 提交于 2021-02-10 14:14:32

问题


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

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