How to pass user defined variable of JMeter to Javascript?

2.1k views Asked by At

I have following javascript in eclipse:

package print_first_fifteen;

public class PrintText { 

   public static void main(String[] args) {

int i;
   char var;

   for (i=1; i<=var ; i++)

        System.out.println(i);

   }
}

I have defined char var = 20 in JMeter user defined variable. How to call this variable defined in Jmeter to this Javascript? Thanks in advance

1

There are 1 answers

0
CharlieS On

You can access JMeter variables from javascript in different ways.

You won't be able to run the javascript in eclipse and get the jmeter variable, unless you develop some code to do the exchange.

You can run the javascript in jmeter, and access the variable when you need it.

Create a JSR223 sampler or processor in a thread group, and copy and paste your javascript. Select javaScript as the language.

Replace the line:

char var;

with:

char var = vars.get("VARNAME");

or:

char var = ${VARNAME};