JMeter - 易于更改的配置选项

发布于 2024-08-23 07:27:42 字数 969 浏览 7 评论 0原文

我正在使用 JMeter 来加载测试 SOAP Web 服务。 Web 服务存在于很多地方,例如我的本地主机、开发盒、集成盒、生产盒等。

我正在使用 WebService(SOAP) 请求采样器并设置了“IP 的服务器名称”、“路径” ”和“SOAP Action”参数如下:

Server Name of IP: ${SERVER}
Path: ${PATH}/service
SOAPAction: http://${SERVER}${PATH}service#action

使用“用户定义变量”配置元素时效果很好。我只是将 SERVER 和 PATH 更改为特定于我要访问的位置的任何内容。然而,这比我想要处理的更令人痛苦。我希望做(并尝试)的是在我的线程组中添加多个 If 逻辑控制器,并检查 ${MODE} (另一个 UDV)并采取相应行动,设置我的服务器和路径。因此,我

"${MODE}" == "dev"
"${MODE}" == "local"
"${MODE}" == "production"

在每个 If 控制器上有一个类似的东西,然后我有一个子 UDV 元素设置适当的服务器和路径。尽管我假设 If 控制器返回 false 将阻止对 UDV 进行评估,但始终使用最后一个 UDV 中的值(按照我的线程组中的出现顺序)。但是,我在文档中看到,无论启动任何线程之前的位置如何,都会评估所有 UDV。因此,我尝试使用用户参数,但 SOAP 采样器中的 ${SERVER} 和 ${PATH} 的值不会被替换,我正在向 http://${SERVER}${PATH} 发出请求,这是不好。

有什么优雅的方法来处理这个问题吗?目前,每次我需要更改正在访问的服务器时,我只是复制粘贴 SERVER 和 PATH 的值。我知道我也可以有多个测试计划,每个测试计划对应我要加载测试的每台服务器,但我经常更新结构,包括添加新测试、禁用现有测试和更改 SOAP 请求的某些部分,因此有一堆它们似乎不是一个好的解决方案。

有什么帮助吗?

I am using JMeter to load test a SOAP webservice. The webservice exists in a bunch of places, like my localhost, a dev box, an integration box, a production box, etc.

I am using a WebService(SOAP) Request Sampler and have set the "Server Name of IP", "Path", and "SOAP Action" paramaters like so:

Server Name of IP: ${SERVER}
Path: ${PATH}/service
SOAPAction: http://${SERVER}${PATH}service#action

This works fine when using a "User Defined Variables" config element. I just change SERVER and PATH to whatever is specific to the location I am trying to hit. However, this is more of a pain in the butt then I want to deal with. What I was hoping to do (and tried) was to add multiple If Logic Controllers in my Thread Group and check for ${MODE} (another UDV) and act accordingly, setting up my SERVER and PATH. So, I had something like

"${MODE}" == "dev"
"${MODE}" == "local"
"${MODE}" == "production"

One on each If Controller, then I had a child UDV element setting the appropriate SERVER and PATH. The values from the last UDV (in order of appearance in my Thread Group) was always being used, despite my assumption the If Controller returning false would keep the UDV from being evaluated. However, I see in the docs that all UDVs are evaluated regardless of the location before any threads are started. So, I tried using User Paramaters instead, but the values for ${SERVER} and ${PATH} in my SOAP sampler do not get replaced and I am making requests to http://${SERVER}${PATH} which is not good.

It there any elegant way to handle this? Currently I am just copying an pasting the values for SERVER and PATH every time I need to change the server I am hitting. I know I could also have multiple Test Plans, one for each server I am going to load test, but I make frequent updates to the structure including adding new tests, disabling existing tests and changing some parts of the SOAP requests so having a bunch of them does not seem like a good solution.

Any help?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

赢得她心 2024-08-30 07:27:42

我们使用 BeanShell Sampler 和测试计划本身中定义的变量解决了这个问题。

您可以为整个测试计划定义变量,而不是使用“用户定义的变量”元素。只需单击树的根元素并添加一个名为“mode”的变量,其内容为“dev”、“local”或“Production”。

在测试用例中添加采样器“Bean Shell Sampler”并添加以下代码:

if ("dev".equals(vars.get("mode"))) {
 vars.put("server","x.y.z");
}
if ("local".equals(vars.get("mode"))) {
 vars.put("server","127.0.0.1");
}
if ("production".equals(vars.get("mode"))) {
 vars.put("server","10.0.0.10");
}

然后,您可以定义所需的所有变量,还可以根据需要添加其他环境。

但你还可以更进一步:
创建一个简单控制器并将 Bean Shell Sampler 放在那里。在所有线程组中,您现在可以使用模块控制器访问此简单控制器。在这种情况下,您只需为整个测试计划定义一次环境选择器。

We solved this problem with a BeanShell Sampler and variables defined in the Testplan itself.

Instead of using the element "User Defined Variables" you can define variables for the entire Testplan. Just click on the root element of the tree and add a variable called "mode" with the content "dev", "local" or "production".

In the testcase add the Sampler "Bean Shell Sampler" and add following code:

if ("dev".equals(vars.get("mode"))) {
 vars.put("server","x.y.z");
}
if ("local".equals(vars.get("mode"))) {
 vars.put("server","127.0.0.1");
}
if ("production".equals(vars.get("mode"))) {
 vars.put("server","10.0.0.10");
}

You can then define all variables you need and also add other environments if needed.

But you can also go a step further:
Create a Simple Controller and put your Bean Shell Sampler there. In all ThreadGroups, you can now access to this Simple Controller with a Module Controller. In this case, you have to define your environment selector just once for the entire Testplan.

ヅ她的身影、若隐若现 2024-08-30 07:27:42

就我个人而言,我发现拥有多个 UDV 模块要容易得多,并且全部位于顶层。

除了我想使用的那个之外,我将它们全部禁用。

我发现做同一件事有很多种方法;-)

Personally I found much easier to have several UDV modules, all at the top level.

I keep them all disabled except the one I want to use.

I see there are so many ways of doing the same thing ;-)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文