0
votes

Is it possible to load some extra http request parameters from a file in jmeter? My use case is that the filter query parameters I'm sending to SOLR all have exactly same name, but different value:

fq=Field1:Value1&fq=Field2:Value2&fq=Field3:Value3

The bean shell script so far is:

String line = vars.get("facets");

if(line != null) {
     StringTokenizer st = new StringTokenizer(line, ",");

     while (st.hasMoreTokens()) {
        String filterQ = st.nextToken();

        String varname = "fq";
        vars.put(varname,filterQ);
     }
}

Since vars is a "hash map"-like data structure with unique keys it is not an option for supplying many fq parameters in the same go.

I was thinking of using a file with these fq parameters, but does anybody know how to make them attach to the existing http parameters configured in the HTTP Request element?

Upd. Summarizing the answer below, here is what I did:

  1. added the BeanShell PreProcessor as a child of HttpRequest

  2. changed the above code to:

    String line = vars.get("facets");

    if(line != null) { StringTokenizer st = new StringTokenizer(line, ",");

     while (st.hasMoreTokens()) {
        String filterQ = st.nextToken();
    
        // add fq parameter and its value to the http request body
        String paramName = "fq";
        ctx.getCurrentSampler().addArgument(paramName, filterQ);
     }
    

    }

2

2 Answers

1
votes

Why don't you just amend your code to distinguish your variable names, i.e. fq1, fq2, etc.

Like:

String line = vars.get("facets");

    if(line != null) {
        StringTokenizer st = new StringTokenizer(line, ",");
        int i = 0;
        while (st.hasMoreTokens()) {
            String filterQ = st.nextToken();

            String varname = "fq" + i;
            vars.put(varname,filterQ);
            i++;
        }
    }

By the way, Beanshell isn't very recommended for heavy scripting, if you're spawning this code in multiple threads you should rather use JSR223 Sampler and groovy language which is capable of producing native Java code (Beanshell scripting engine isn't).

1
votes

You can use the JMeter CSV data set element. This allows you to load and iterate through the values by using a variable in your script.

Here is an example tutorial:
http://community.blazemeter.com/knowledgebase/articles/65138-using-csv-data-set-config

The official docs are here:
http://jmeter.apache.org/usermanual/component_reference.html#CSV_Data_Set_Config