Groovy скрипт для тестовых шагов в SoapUI

В SoapUI (Pro версия) у меня есть 12 тестовых шагов:

  1. GET запрос
  2. Groovy сценарий, чтобы получить total значение из ответа предыдущего шага
  3. свойства
  4. Передача недвижимости
  5. POST запрос 1
  6. POST запрос 2
  7. POST запрос 3
  8. POST запрос 4
  9. POST запрос 5
  10. POST запрос 6
  11. POST запрос 7
  12. 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

-1

Решение

Вы можете использовать следующее в 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)
}
0

Другие решения

Других решений пока нет …

По вопросам рекламы [email protected]