代码之家  ›  专栏  ›  技术社区  ›  Rajesh Varma

如何使用Groovy脚本测试步骤在SOAPUI中触发REST请求

  •  1
  • Rajesh Varma  · 技术社区  · 8 年前

    通过下面的脚本,我能够将数据/负载发送到我的POST请求。然而,值得注意的是从脚本运行post请求。需要循环中的post请求。

    def POSTForgivness = testRunner
       .testCase
       .getTestStepByName("postforgivness")
       .getT‌​estRequest() 
    POSTForgivness.setRequestContent(ForgivnessPayload)
    

    评论中的其他信息:

    • 已经有900多条记录,能够读取和发送数据到post请求,但post请求在循环中没有触发/运行。
    2 回复  |  直到 8 年前
        1
  •  1
  •   Rao CrashOverload    8 年前

    给你:sudo代码

    1. 按名称获取测试步骤
    2. 运行步骤
    3. 需要禁用rest步骤,因为每件事都由step1控制(这是groovy脚本步骤)
    //Get the next step
    def nextStep = context.testCase.getTestStepByName("postforgivness")
    //Set the new request
    nextStep.httpRequest.requestContent = ForgivnessPayload
    //run next step
    nextStep.run(testRunner, context)
    

        2
  •  0
  •   Chris Adams    8 年前

    在循环中重新需要post请求。

    这听起来像是数据驱动测试,而不是负载测试。

    然后,只要数据源步骤中设置了行,就可以“循环”post宽恕步骤。对于您设置的每一行,您可以定义要“喷射”到请求中的有效负载。

    SoapUI网站上有一篇优秀的文章 https://www.soapui.org/data-driven-tests/functional-tests.html