编辑:
有可能,我把项目上传到google drive。我想它可能会对你有所帮助。
我从 2012 年开始遵循 this 伙计们的教程。
例如,我使用了 swagger 的 petstore,但您应该能够将该部分替换为您需要的任何 API。无论是 TEMPLATE 还是 QUERY 参数都没有关系 - 方法保持不变。
P.S 在创建时宠物 1、2、3、5 和 6 都在场。这就是为什么您可以在输入中看到 1,2,3,5,6。
假设这是您项目的结构:
1.DataSource(Groovy 步骤)
2.属性
3.请求(API)
4.DataLoop(Groovy步骤)
这是DataSource(Groovy step)的内容
import com.eviware.soapui.support.XmlHolder
import com.eviware.soapui.support.GroovyUtils
def myTestCase = context.testCase
def counter,next,previous,size
def projectDir = new GroovyUtils(context).projectPath
File tickerEnumFile = new File(projectDir + "/input.txt") //make sure input.txt file already exists and contains different set of values sepearted by new line (CR).
List lines = tickerEnumFile.readLines()
size = lines.size.toInteger()
propTestStep = myTestCase.getTestStepByName("Properties") // get the Property TestStep
propTestStep.setPropertyValue("Total", size.toString())
counter = propTestStep.getProperty("Count").value
if (counter == null || counter == ""){
counter = 0
}
counter= counter.toInteger()
next = (counter > size-2? 0: counter+1)
tempValue = lines[counter]
propTestStep.setPropertyValue("Value", tempValue)
propTestStep.setPropertyValue("Count", next.toString())
next++
log.info "Reading line : ${(counter+1)} / $lines.size"
propTestStep.setPropertyValue("Next", next.toString())
log.info "Value '$tempValue' -- updated in $propTestStep.name"
if (counter == size-1){
propTestStep.setPropertyValue("StopLoop", "T")
log.info "Setting the stoploop property now..."
} else if (counter==0){
def runner = new com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner(testRunner.testCase, null)
propTestStep.setPropertyValue("StopLoop", "F")
} else{
propTestStep.setPropertyValue("StopLoop", "F")
}
属性:开头应该为空
请求:
最后是 DataLoop:
import com.eviware.soapui.support.types.StringToObjectMap
def myTestCase = context.testCase
def runner
propTestStep = myTestCase.getTestStepByName("Properties") // get the Property TestStep
endLoop = propTestStep.getPropertyValue("StopLoop").toString()
if (endLoop.toString() == "T" || endLoop.toString()=="True" || endLoop.toString()=="true"){
log.info ("Exit from the loop")
assert true
} else {
testRunner.gotoStep(0)
}
旧评论:
您使用的是免费版的 SoapUI 还是 SoapUI Pro?也许是ReadyAPI?如果您使用的是专业版,您可能需要考虑使用数据源循环。让我知道是否是这种情况。谢谢。