如何 运行 多个值的 Web 服务
How to run a web service for multiple values
我正在尝试 运行 设置了多个值的 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
根据讨论,这属于数据驱动测试。
虽然数据驱动测试功能由 ReadyAPI(soapui 的付费版本)开箱即用,但在 groovy 脚本的帮助下,这也可以在免费版本中完成。
对于您的案例,请按以下步骤创建测试用例:
- groovy 脚本测试步骤(下面建议的脚本)
- soap 请求测试步骤(您已在问题中显示)
以下是第一步需要执行的脚本:
//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>
我正在尝试 运行 设置了多个值的 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
根据讨论,这属于数据驱动测试。
虽然数据驱动测试功能由 ReadyAPI(soapui 的付费版本)开箱即用,但在 groovy 脚本的帮助下,这也可以在免费版本中完成。
对于您的案例,请按以下步骤创建测试用例:
- groovy 脚本测试步骤(下面建议的脚本)
- soap 请求测试步骤(您已在问题中显示)
以下是第一步需要执行的脚本:
//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>