dongzeao5047 2017-04-07 16:23
浏览 243
已采纳

用于SoapUI中的测试步骤的Groovy脚本

In SoapUI (Pro version) I have 12 test steps:

  1. GET request
  2. Groovy script witch get total value from response from the previous step
  3. Properties
  4. Properties transfer
  5. POST request 1
  6. POST request 2
  7. POST request 3
  8. POST request 4
  9. POST request 5
  10. POST request 6
  11. POST request 7
  12. POST request 8

All POST requests have ID parameters.

Question:

How to write a Groovy script like this or maybe another decision way:

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条回答 默认 最新

  • duanputian5341 2017-04-10 00:00
    关注

    You could use the following in the groovy [step 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)
       }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?