我有地址,例如https://stackoverflow.com/1234?action=update?status=active,我想'1234'将在循环中动态更改,所以我这样做:
def ids= [1,2,3,4]
for(i=0;ids.size();i++){
context.testCase.getProperty('id') as Integer
//How I com back to Rest Request?
}
你有什么想法吗?有可能吗?
答案 0 :(得分:1)
编辑: 有可能,我将项目上传到google drive。我想这可能会对你有所帮助。 我从2012年开始关注this人的教程。 例如,我使用了swagger的petstore,但您应该能够将该部分替换为您需要的任何API。它是TEMTATE还是QUERY参数并不重要 - 方法保持不变。
P.S在创作时刻,宠物1,2,3,5和6出现了。这就是为什么你可以在输入中看到1,2,3,5,6的原因。让我们说这是你项目的结构:
1.DataSource(Groovy步骤)
2.Properties
3.Request(API)
4.DataLoop(Groovy步骤)
这是DataSource(Groovy步骤)的内容
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?如果您使用的是专业版,则可能需要考虑使用数据源循环。如果是这样,请告诉我。谢谢。
答案 1 :(得分:1)
使用属性
有一种更简单的方法将网址命名为
${#TestCase#url}
禁用名称为" request1"
的请求添加 groovy脚本,您将通过该脚本多次运行请求
参考这一步
String id[]=["Value1forid","value2","value3","value4","value5")
for(int i=0;i<5;i++)
{
def temp=" https://stackoverflow.com/{" + id[i] + "}?action=update?status=active "
testRunner.testCase.setProertyValue("url",temp)
tstep=testRunner.testCase.gettestStepbyName("request1")
tstep.run(testRunner,context)
}
// This way you can run the request 5 times with 5 times different URL where we have put the value we want
// This can be used for any number of properties. Since the request is disabled it will not run and will be run via Groovy step
答案 2 :(得分:1)
我通过在groovy脚本中添加值$ {#TestCase#id}来解决我的问题:
def ids= [1,2,3,4]
for(i=0;ids.size();i++){
String id = ids[i]
context.testCase.setPropertyValue("id", ids[i])
testRunner.runTestStepByName( "REST_REQUEST")
}