用xml和儿子

时间:2018-03-22 17:39:20

标签: automation karate

我是自动化的新手,并从Karate Framework开始。

我想为不同的测试数据参数化随机和国家代码。如何使用xml和json?

我的json请求很庞大,需要多个参数化

场景:创建用户

def createuserrequest = read('classpath:com/imscreateuser/createuser.xml')
Given url imscreateuserurl
And header Content-Type = 'application/json; charset=utf-8'
And request createuserrequest 
When method post
Then status 200

 <?xml version="1.0" encoding="UTF-8"?>
<ReqBody version="1.9.11"  options="prettyOutput">
   <req dest="UserManagement" api="createPerson">
      <Person>
         <countryCode>'#(countrycode)'</countryCode>
         <credentials class="Credentials">
            <password>P@ssword1</password>
            <username>new+'#(random)'@testing.com</username>
         </credentials>
      </Person>
      <AuthRequest />
   </req>
</ReqBody>

1 个答案:

答案 0 :(得分:0)

<countryCode>'#(countrycode)'</countryCode>错了。它应该是<countryCode>#(countrycode)</countryCode>

<username>new+'#(random)'@testing.com</username>错了。它应该是<username>#('new' + random + '@testing.com')</username>

请查看此示例以获取XML构思:https://github.com/intuit/karate/blob/master/karate-junit4/src/test/java/com/intuit/karate/junit4/xml/xml.feature

对于参数化,如果您已阅读文档,则不会询问此问题。请参阅此部分:https://github.com/intuit/karate#data-driven-tests

看看这个例子:https://github.com/intuit/karate/blob/master/karate-demo/src/test/java/demo/outline/examples.feature

找到空手道演示示例并查看dynamic-params.feature