groovy - 如何使用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 请求(测试步骤)并运行它。
解决方案
- 将属性测试步骤添加到您的测试用例。让它保持默认的“属性”名称。
- 将属性添加到您需要传输的属性测试步骤
在您的常规测试步骤中,您可以使用以下内容设置属性:
def properties = testRunner.testCase.getTestStepByName("Properties"); properties.setPropertyValue("名称", "值");
使用 ${Properties#name} 格式的变量直接在您的请求中添加参数,并将“name”替换为实际参数名称。如果您愿意,这可以在请求正文和 URL 中完成。
推荐阅读
- javascript - 减少新数组未正确执行
- javascript - Azure Ad CORS 如何调用 web api url
- pandas - 如何在 Matplotlib 的散点图中查看特定点的数据?
- c# - 如何在列表类中隐藏属性
- javascript - 如何:使用 React Native 为 9gag 的“添加按钮”设置动画
- python - Python - 使用子进程在目录和子目录中查找包含特定文本的所有文件
- c# - 值类型的“is T x”的实现和性能
- c# - 获取属性 c# 的返回与分配
- python - 谷歌分析 API:使用正则表达式的 IN 列表
- c++ - 在 LINUX 中构建 Gtest 框架