dongzeao5047
dongzeao5047
2017-04-07 16:23

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

  • groovy
  • php
  • soapui
已采纳

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 duanputian5341 4年前

    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)
       }
    
    点赞 评论 复制链接分享

为你推荐