JMeter use beanshell variable in HTTP Request

后端 未结 3 2009
悲&欢浪女
悲&欢浪女 2021-02-19 19:13

I\'m an absolute rookie here (JAVA i mean), spent hours looking for a solution, now i just want to shoot myself.
I want to create a string in the beanshell assertion which i

3条回答
  •  独厮守ぢ
    2021-02-19 20:15

    In BeanShell Assertion description section you can find the following:

     vars -  JMeterVariables  - e.g. vars.get("VAR1"); vars.put("VAR2","value"); vars.putObject("OBJ1",new Object()); 
     props - JMeterProperties (class java.util.Properties) - e.g. props.get("START.HMS"); props.put("PROP1","1234");
    

    So to set jmeter variable in beanshell code (BeanShell Assertion sampler in your case) use the following:

    String docid = "abcd";
    vars.put("docid",docid);
    

    or simply

    vars.put("docid","abcd");
    

    and then you can refer it as ${docid}, as you've done in your HTTP Request.

提交回复
热议问题