如何使用Karate验证给定XML的SOAP服务XML文件

问题描述 投票:-1回答:1

我正在学习Karate API来执行基于SOAP的Web服务。为此,我创建了两个XML文件,其中一个是请求信息,另一个是响应数据。

然后我又创建了一个名为webservice.feature的文件。

当我执行此功能文件时,我在控制台中收到以下信息,但我不明白,也不知道如何验证。请提出你的建议。

webservice.feature文件:

Feature: Get Membership Details

Background:
* url 'http://111.111.221.145:2201/Customer/ProxyServices/CustomerSummary_PS?wsdl'

Scenario: FunctionalTest
   Given request read('getMbrWksMembershipSummaryRequest.xml')

   And header Content-Type = 'application/soap+xml; charset=utf-8'
   When method post
   Then status 200
   And match response customerSummary/address/city == read('getMbrWksMembershipSummaryResponse.xml')
   And print 'response: ', response

请求文件。

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cus="http://www.abcdedf.com/services/customersummary" xmlns:con="http://www.abcdedf.com/services/customersummary/contract">
   <soapenv:Header/>
   <soapenv:Body>
      <cus:getMbrWksMembershipDetails>
         <!--Optional:-->
         <cus:WksMembershipSummaryRequest>
            <!--Optional:-->
            <channel>CC</channel>
            <!--Optional:-->
            <consumerName>GUIDE_PORTAL</consumerName>
            <level>0</level>
            <!--Optional:-->
            <locale>en_US</locale>
            <!--Optional:-->
            <productType>ExtraVacation</productType>
            <!--Optional:-->
            <requestId/>
            <!--Optional:-->
            <sessionId/>
            <!--Optional:-->
            <con:memberID>C05506493</con:memberID>
         </cus:WksMembershipSummaryRequest>
      </cus:getMbrWksMembershipDetails>
   </soapenv:Body>
</soapenv:Envelope>

响应文件:

<ns2:customerSummary>
  <ns2:address>
    <ns2:city>SOUTH CHESTERFIELD</ns2:city>
    <ns2:country>USA</ns2:country>
    <ns2:isoCountryCode>US</ns2:isoCountryCode>
    <ns2:line1>9998, N. MICHIGAN ROAD.</ns2:line1>
    <ns2:postalCode>23834</ns2:postalCode>
    <ns2:state>VA</ns2:state>
  </ns2:address>
</ns2:customerSummary>

控制台输出:

You can implement missing steps with the snippets below:

@Given("^url 'http://(\\d+)\\.(\\d+)\\.(\\d+)\\.(\\d+):(\\d+)/Customer/ProxyServices/CustomerSummary_PS\\?wsdl'$")
public void url_http_Customer_ProxyServices_CustomerSummary_PS_wsdl(int arg1, int arg2, int arg3, int arg4, int arg5) throws Throwable {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

@Given("^request read\\('getMbrWksMembershipSummaryRequest\\.xml'\\)$")...

谢谢

selenium automation cucumber web-api-testing karate
1个回答
0
投票

错误消息似乎是标准的黄瓜错误而不是空手道。看起来您的项目结构本身是错误的。我建议你按照文档说明:Quickstart。运行以下命令:

mvn archetype:generate \ -DarchetypeGroupId=com.intuit.karate \ -DarchetypeArtifactId=karate-archetype \ -DarchetypeVersion=0.6.2 \ -DgroupId=com.mycompany \ -DartifactId=myproject

然后在users.feature旁边创建此功能文件:soap.feature。如上所述,您可以将url更改为'http://www.dneonline.com/calculator.asmx'。现在,如果右键单击并运行UsersRunner.java作为JUnit测试,您应该看到工作正常。

© www.soinside.com 2019 - 2024. All rights reserved.