URL SoapUI Rest 中的循环参数如何更改
How change in loop paramter in URL SoapUI Rest
我有地址,例如:https://whosebug.com/1234?action=update?status=active,我想“1234”将在循环中动态更改,所以我这样做:
- 我创建 REST 项目并在 SoapUI 5.3.0 中添加 url https://whosebug.com/{id}?action=update?status=active
- 我添加id像参数STYLE = Template, Value = ${id}
- 我使用 REST 请求和 Groovy 脚本创建测试用例
- 我添加相同的 Rest Request(URL https://whosebug.com/{id}?action=update?status=active 并添加 id,如参数 STYLE = Template,Value = ${id})
- 在 Groovy Scipt 中,我想更改 &{id} 的值并转到休息请求,所以我写:
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?
}
你有什么想法吗?有可能吗?
编辑:
有可能,我把项目上传到google drive。我想这可能对你有帮助。
我从 2012 年开始关注 this 个人的教程。
例如,我使用了 swagger 的 petstore,但您应该能够将该部分替换为您需要的任何 API。无论是 TEMPLATE 还是 QUERY 参数都没有关系 - 方法保持不变。
P.S 在创建宠物 1、2、3、5 和 6 时存在。这就是为什么您可以在输入中看到 1,2,3,5,6 的原因。
假设这是您项目的结构:
1.DataSource(Groovy step)
2.Properties
3.Request(API)
4.DataLoop(Groovy step)
这是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?也许准备好了API?如果您使用的是 Pro 版本,您可能需要考虑使用 Data Source Loop。让我知道是否是这种情况。谢谢。
有一种更简单的方法可以使用属性
将 url 命名为
${#TestCase#url}
禁用名称为"request1"
的请求
添加一个groovy脚本,通过它您将运行请求多次
参考这一步
String id[]=["Value1forid","value2","value3","value4","value5")
for(int i=0;i<5;i++)
{
def temp=" https://whosebug.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
我通过在 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")
}
我有地址,例如:https://whosebug.com/1234?action=update?status=active,我想“1234”将在循环中动态更改,所以我这样做:
- 我创建 REST 项目并在 SoapUI 5.3.0 中添加 url https://whosebug.com/{id}?action=update?status=active
- 我添加id像参数STYLE = Template, Value = ${id}
- 我使用 REST 请求和 Groovy 脚本创建测试用例
- 我添加相同的 Rest Request(URL https://whosebug.com/{id}?action=update?status=active 并添加 id,如参数 STYLE = Template,Value = ${id})
- 在 Groovy Scipt 中,我想更改 &{id} 的值并转到休息请求,所以我写:
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?
}
你有什么想法吗?有可能吗?
编辑: 有可能,我把项目上传到google drive。我想这可能对你有帮助。 我从 2012 年开始关注 this 个人的教程。 例如,我使用了 swagger 的 petstore,但您应该能够将该部分替换为您需要的任何 API。无论是 TEMPLATE 还是 QUERY 参数都没有关系 - 方法保持不变。
P.S 在创建宠物 1、2、3、5 和 6 时存在。这就是为什么您可以在输入中看到 1,2,3,5,6 的原因。
假设这是您项目的结构:
1.DataSource(Groovy step)
2.Properties
3.Request(API)
4.DataLoop(Groovy step)
这是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?也许准备好了API?如果您使用的是 Pro 版本,您可能需要考虑使用 Data Source Loop。让我知道是否是这种情况。谢谢。
有一种更简单的方法可以使用属性
将 url 命名为
${#TestCase#url}
禁用名称为"request1"
的请求添加一个groovy脚本,通过它您将运行请求多次
参考这一步
String id[]=["Value1forid","value2","value3","value4","value5")
for(int i=0;i<5;i++)
{
def temp=" https://whosebug.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
我通过在 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")
}