tags:

views:

30

answers:

1

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?

+2  A: 

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.

Steve
+1. Thanks. I will explore this as a solution. However, I did get it to work as I had it, I just had to define the SERVER and PATH variables outside of the Thread Group and then override them with the If Controller -> User Parameters.
sberry2A