【问题标题】:Adding and asserting random value in SOAPUI Rest testing在 SOAPUI Rest 测试中添加和断言随机值
【发布时间】:2016-07-21 14:58:27
【问题描述】:

我一直在尝试各种方法来发送随机值作为 Rest 测试用例有效负载的一部分。我还需要在返回的响应中声明该随机值。

我能够向有效负载添加一个随机值。但我无法在响应中断言该随机值。

我尝试了以下方法。

  1. 添加一个 groovy 脚本并设置一个全局变量。

    def randomValue = java.util.UUID.randomUUID() com.eviware.soapui.SoapUI.globalProperties.setPropertyValue("randomValue", randomValue)

然后在有效载荷中使用它作为 ${randomValue} 这样我就可以在请求和断言中访问它。 这很适合一个请求。当使用大量并发请求执行负载测试时,请求具有相同的值而不是随机值。

  1. 使用属性测试步骤设置属性。

    ${=(int)(Math.random()*100)

    这证明了请求的随机值。但在断言中,随机值是新值。和请求中的不一样。

非常感谢任何帮助。

【问题讨论】:

    标签: groovy soapui load-testing


    【解决方案1】:

    你在正确的轨道上。

    从测试设置脚本中设置随机值,例如:

    def randomValue // = whatever you like: UUID.randomUUID() or Math.random() work fine
    testCase.setPropertyValue( "randomValue", randomValue.toString() )
    

    这将为每次测试运行生成一个随机值。然后在您的测试中的任何地方,您都可以通过属性扩展将其称为${#TestCase#randomValue}

    【讨论】:

      【解决方案2】:

      您可能需要解析和构建您的请求

      1. 使用JsonSlurperxmlSlurper解析请求
      2. 在请求中插入随机值

      3.使用JsonBuilder/xmlBuilder再次构建Json/xml

        def builder = new JsonBuilder(your_changed_json)
        def json = builder.toPrettyString()
        json = groovy.json.StringEscapeUtils.unescapeJava(json)
      
      1. 将上述 json/xml 设置为您的请求

        step.testRequest.setRequestContent(json)
        

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-11-07
        • 1970-01-01
        • 2014-07-14
        相关资源
        最近更新 更多