如何在URL SoapUI Rest中更改循环参数
例如,我有地址:我想“1234”将在循环中动态更改,所以我这样做:如何在URL SoapUI Rest中更改循环参数,rest,groovy,soapui,Rest,Groovy,Soapui,例如,我有地址:我想“1234”将在循环中动态更改,所以我这样做: 我创建REST项目并在SOAPUI5.3.0中添加url{id}?action=update?status=active 我添加了类似id的参数STYLE=Template,Value=${id} 我使用REST请求和Groovy脚本创建TestCase 我添加了相同的Rest请求(URL{id}?action=update?status=active和add-id-like参数STYLE=Template,Value=${id
def id=[1,2,3,4]
对于(i=0;ids.size();i++){
context.testCase.getProperty('id')为整数
//如何返回到Rest请求?
}
你有什么想法吗?有可能吗?编辑:
这是可能的,我上传了项目到。我想这可能对你有帮助。
我从2012年开始学习男生教程。
例如,我使用了swagger的petstore,但您应该能够将该部分替换为您需要的任何API。不管是模板还是查询参数,方法都是一样的
在创造的时刻,宠物1、2、3、5和6都在场。这就是为什么您可以在输入中看到1,2,3,5,6
假设这是您项目的结构:
1.数据源(Groovy步骤)
2.物业
3.请求(API)
4.数据循环(Groovy步骤)
这是数据源的内容(Groovy步骤)
属性:开始时应为空
请求:
最后是数据循环:
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?如果您使用的是PRO版本,您可能需要考虑使用数据源循环。如果是这样,请告诉我。谢谢。编辑:
这是可能的,我上传了项目到。我想这可能对你有帮助。
我从2012年开始学习男生教程。
例如,我使用了swagger的petstore,但您应该能够将该部分替换为您需要的任何API。不管是模板还是查询参数,方法都是一样的
在创造的时刻,宠物1、2、3、5和6都在场。这就是为什么您可以在输入中看到1,2,3,5,6
假设这是您项目的结构:
1.数据源(Groovy步骤)
2.物业
3.请求(API)
4.数据循环(Groovy步骤)
这是数据源的内容(Groovy步骤)
属性:开始时应为空
请求:
最后是数据循环:
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?如果您使用的是PRO版本,您可能需要考虑使用数据源循环。如果是这样,请告诉我。谢谢。使用属性有一种更简单的方法 将url命名为
${#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
String id[]=[“Value1forid”、“value2”、“value3”、“value4”、“value5”)
对于(inti=0;i,有一种更简单的方法通过使用属性来实现
将url命名为
${#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
String id[]=[“Value1forid”、“value2”、“value3”、“value4”、“value5”)
对于(inti=0;i我通过在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")
}
我通过在groovy脚本中添加值${#TestCase#id}next来解决我的问题:
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")
}
我创建了一个您需要的SoapUI项目,但不确定是否可以附加到这里。@Gregory谢谢。我使用${#TestCase#id}解决了我的问题,在TestCase中我添加了groovy脚本,该脚本通过testRunner.runTestStepByName(“REST#请求”)调用restRequest我创建了一个您需要的SoapUI项目,但不确定是否可以附加到这里。@Gregory谢谢。我使用${#TestCase#id}解决了我的问题,在TestCase中我添加了groovy脚本,该脚本通过testRunner.runTestStepByName(“REST#请求”)调用restRequest通过在循环中仅更改“id”进行修改很有帮助。感谢您接受解决方案并发布您自己的解决方案。通过在循环中仅更改“id”进行修改很有帮助。感谢您接受解决方案并发布您自己的解决方案