groovy - SoapUI 从文件中读取请求参数(免费版)
问题描述
我有一个包含以下内容的文件
987656
987534
在我的测试之前,我有一个 Groovy 脚本作为测试步骤:
def myTestCase = context.testCase
new File("filepath/data1.txt").eachLine { line ->
myTestCase.setPropertyValue("inputValue", line)
inputValue = context.expand( '${#TestCase#inputValue}' )
log.info inputValue
}
脚本的日志输出为我提供了文件中的两个值:
987656
987534
我有一个 Testcase 自定义属性设置为“inputValue”,在我的测试中我将参数称为
<enr:Id>${#TestCase#inputValue}</enr:Id>
在执行期间,测试始终针对最后一个值“987534”运行,而不是针对两个输入。
我应该怎么做才能对文本文件中存在的所有值执行测试?
谢谢
解决方案
像这样循环遍历值的方法是,在eachLine
循环中调用 SOAP 步骤,如下所示:
def myTestCase = context.testCase
new File("filepath/data1.txt").eachLine { line ->
myTestCase.setPropertyValue("inputValue", line)
inputValue = context.expand( "${#TestCase#inputValue}" )
log.info inputValue
//define the step
def soapTestStep = testRunner.testCase.getTestStepByName("YourSOAPRequestName").name
//call the step
testRunner.runTestStepByName(soapTestStep)
//if you want to do something with the response XML
def responseSOAP = context.expand("${YourSOAPRequestName#Response}")
//if you want to check a value in the response XML
def responseSection = responseSOAP =~ /someNode>(.*)<\/someNode/
def responseValue = responseSection[0][1]
log.info "response: ${responseValue}"
}
推荐阅读
- azure - 一个 Cosmos DB 查询中的 TOP 和 DISTINCT
- python - 如何将此数据框添加到 HDF5 文件中的数据集中?
- java - 如何在我的全局变量中存储一个值并在活动中的任何方法中使用它
- sql - Sql - 打开 Json 插入表
- command-line - Loopback cli (lb4) 在启动时崩溃
- typescript - 由于“TypeError:无法读取未定义的属性 'xxx'”,Jest 测试套件无法运行
- python - 编写代码以检查密码是否符合特定条件
- css - 在屏幕上显示时弹跳或淡入文本和 div
- r - 具有索引向量的子集列表
- javascript - 根据元素值,应修改对象数组中的剩余元素