Groovy SoapUI 中测试步骤的脚本
Groovy script for test steps in SoapUI
在 SoapUI(专业版)中我有 12 个测试步骤:
GET
请求
- Groovy 脚本 从上一步的响应中获取
total
值
- 属性
- 财产转让
POST
请求 1
POST
请求 2
POST
请求 3
POST
请求 4
POST
请求 5
POST
请求 6
POST
请求 7
POST
请求 8
所有 POST
个请求都有 ID
个参数。
问题:
如何编写这样的 Groovy 脚本或其他决策方式:
if total = 8 then set ID parameters of POST 1 = 1,POST 2 = 1,POST 3 = 1,POST 4 = 1,POST 5 = 1,POST 6 = 1,POST 7 = 1,POST 8 = 1
if total = 7 then set ID parameters of POST 1 = 2,POST 2 = 1,POST 3 = 1,POST 4 = 1,POST 5 = 1,POST 6 = 1,POST 7 = 1
if total = 6 then set ID parameters of POST 1 = 2,POST 2 = 2,POST 3 = 1,POST 4 = 1,POST 5 = 1,POST 6 = 1
if total = 5 then set ID parameters of POST 1 = 2,POST 2 = 2,POST 3 = 2,POST 4 = 1,POST 5 = 1
if total = 4 then set ID parameters of POST 1 = 2,POST 2 = 2,POST 3 = 2,POST 4 = 2
if total = 3 then set ID parameters of POST 1 = 3,POST 2 = 3,POST 3 = 2
if total = 2 then set ID parameters of POST 1 = 4,POST 2 = 4
if total = 1 then set ID parameters of POST 1 = 8
您可以在 groovy [步骤 2]
中使用以下内容
def totalPostSteps = 8
def totalFromResponse = 7 //map the one you got from prev response
def postIdArray = new int[totalPostSteps]
def index = 0
1.upto (totalPostSteps,
{
postIdArray[index]+=1;
index = index==totalFromResponse-1?0:index+1
})
//log.info postIdArray.toString()
postIdArray.eachWithIndex{num, idx ->
def numString = num!=0?num.toString():""
//The next step will create/update properties in TestCase custom properties and u can map these directly to your POST requests
//OR You can set these directly to step3 and continue with step 4
testRunner.testCase.setPropertyValue("IdForPost_"+(idx+1), numString)
}
在 SoapUI(专业版)中我有 12 个测试步骤:
GET
请求- Groovy 脚本 从上一步的响应中获取
total
值 - 属性
- 财产转让
POST
请求 1POST
请求 2POST
请求 3POST
请求 4POST
请求 5POST
请求 6POST
请求 7POST
请求 8
所有 POST
个请求都有 ID
个参数。
问题:
如何编写这样的 Groovy 脚本或其他决策方式:
if total = 8 then set ID parameters of POST 1 = 1,POST 2 = 1,POST 3 = 1,POST 4 = 1,POST 5 = 1,POST 6 = 1,POST 7 = 1,POST 8 = 1
if total = 7 then set ID parameters of POST 1 = 2,POST 2 = 1,POST 3 = 1,POST 4 = 1,POST 5 = 1,POST 6 = 1,POST 7 = 1
if total = 6 then set ID parameters of POST 1 = 2,POST 2 = 2,POST 3 = 1,POST 4 = 1,POST 5 = 1,POST 6 = 1
if total = 5 then set ID parameters of POST 1 = 2,POST 2 = 2,POST 3 = 2,POST 4 = 1,POST 5 = 1
if total = 4 then set ID parameters of POST 1 = 2,POST 2 = 2,POST 3 = 2,POST 4 = 2
if total = 3 then set ID parameters of POST 1 = 3,POST 2 = 3,POST 3 = 2
if total = 2 then set ID parameters of POST 1 = 4,POST 2 = 4
if total = 1 then set ID parameters of POST 1 = 8
您可以在 groovy [步骤 2]
中使用以下内容def totalPostSteps = 8
def totalFromResponse = 7 //map the one you got from prev response
def postIdArray = new int[totalPostSteps]
def index = 0
1.upto (totalPostSteps,
{
postIdArray[index]+=1;
index = index==totalFromResponse-1?0:index+1
})
//log.info postIdArray.toString()
postIdArray.eachWithIndex{num, idx ->
def numString = num!=0?num.toString():""
//The next step will create/update properties in TestCase custom properties and u can map these directly to your POST requests
//OR You can set these directly to step3 and continue with step 4
testRunner.testCase.setPropertyValue("IdForPost_"+(idx+1), numString)
}