问题描述
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}"
}