如何为多个值运行Web服务

时间:2017-06-01 12:47:14

标签: web-services groovy soapui

我正在尝试在soapUI中运行SOAP Web服务,并设置了多个值,但我无法实现它。问题是如何为Web服务的给定变量ID设置多个值,并为每个值获得相同的多个结果。 wsdl文件如下:

      <soapenv:Body>
  <ws:getData>
     <ws:reportID>MY_DATA</ws:reportID>
     <ws:key>
        <xsd:type>ID</xsd:type>
        <xsd:value>8456321</xsd:value>
     </ws:key>
            <ws:dateInfo>
        <xsd:endDate>2016-05-24</xsd:endDate>
        <xsd:startDate>2016-05-30</xsd:startDate>
     </ws:dateInfo>
  </ws:getData>

您可以看到下面的示例数据通过CSV文件或甚至通过循环读取的接口提供给ID值。

     6115120
     8126106
     0211110
     1212501
     6115120
     8126106
     0211110
     1212501
     6115120
     8126106
     0211110
     1212501

1 个答案:

答案 0 :(得分:1)

根据讨论,这属于数据驱动测试。

虽然数据驱动的测试功能由ReadyAPI(付费版本的soapui)开箱即用,但在groovy脚本的帮助下,这也可以在免费版本中完成。

对于您的情况,请使用以下步骤创建一个测试用例:

  • groovy脚本测试步骤(下面提出的脚本)
  • 肥皂请求测试步骤(您已在问题中显示)

以下是需要进入第一步的脚本:

//Provide the path of your data file below
def datasource = 'C:/Temp/data.csv'

//Read all the lines
def lines = new File(datasource).readLines() 
lines.eachWithIndex { line, index -> 
//Get the data
    def data = line.toString().trim() 
    log.info "current data   : $data"
//Set the current row data into context variable called type
    context.type = data 

//Fire the webservice except last row of the data file as last row is execute automatically
     if (lines.size()-1 != index) { 
            step = context.testCase.testStepList[context.currentStepIndex+1]
            step.run(testRunner, context)       
    } else {
        log.info 'last record'  
    }
}
log.info 'going to finish'

在第二个测试步骤的soap请求中进行以下更改

更改自:

 <ws:key>
    <xsd:type>ID</xsd:type>
    <xsd:value>8456321</xsd:value>
 </ws:key>

To:使用上下文变量type,每次使用新的行数据将在循环中替换

 <ws:key>
    <xsd:type>ID</xsd:type>
    <xsd:value>${type}</xsd:value>
 </ws:key>