【问题标题】:Groovy script for test steps in SoapUISoapUI 中用于测试步骤的 Groovy 脚本
【发布时间】:2017-04-07 16:23:01
【问题描述】:

在 SoapUI(专业版)中,我有 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

【问题讨论】:

    标签: php groovy soapui


    【解决方案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)
       }
    

    【讨论】:

    • 你每次的脚本结果都不一样,大概是这样的 - I@3bb633cd or I@52c6035 or I@47a007e77 等等
    • 哦。我改变了一些东西和它的工作。谢谢你。我将 testRunner.testCase.setPropertyValue("IdForPost_"+(idx+1), numString) 更改为 testRunner.testCase.getTestStepByName("Properties").setPropertyValue("IdForPost"+(idx+1), numString)
    猜你喜欢
    • 2018-05-24
    • 1970-01-01
    • 1970-01-01
    • 2021-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多