首页 > 解决方案 > 如何使用groovy将参数传递给SOAP UI测试用例中的HTTP请求(teststep)并运行它

问题描述

我正在编写一个 groovy 脚本来执行/自动化我的测试套件。在一个测试用例中,我有一个 HTTPRequest,其中我有一个请求 URL、参数(用户名和密码)和方法(GET)来获取令牌 ID,然后我将该令牌 ID 传递给我的下一步(SOAP 请求)获取数据。

我被困在需要使用 groovy 传递参数(用户名和密码)、请求 URL 和方法(GET)的地方。我在测试用例下手动创建了一个测试步骤,我只需要传递参数

当我在网上搜索时,我知道如何将标头、url 传递给 SOAP 请求,如下所示

def headers = new StringToStringMap()
testRunner = new com.eviware............WsdlTestCaseRunner(myTestCase,null);
testStepContext = new com.eviware.soapui........WsdlTestRunContext(testsetp);
headers.put("apikey", "abcd")
teststep.getTestRequest().setRequestHeaders(headers)
teststep.getHttpRequest().setEndpoint(encpointurl);
testsetp.run(testRunner ,testStepContext )

但我想知道如何将参数传递给 http 请求(测试步骤)并运行它。

标签: groovyparametershttprequestsoapui

解决方案


  • 将属性测试步骤添加到您的测试用例。让它保持默认的“属性”名称。
  • 将属性添加到您需要传输的属性测试步骤
  • 在您的常规测试步骤中,您可以使用以下内容设置属性:

    def properties = testRunner.testCase.getTestStepByName("Properties"); properties.setPropertyValue("名称", "值");

  • 使用 ${Properties#name} 格式的变量直接在您的请求中添加参数,并将“name”替换为实际参数名称。如果您愿意,这可以在请求正文和 URL 中完成。


推荐阅读