You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jmeter.apache.org by Miklos Tverdota <tv...@axelero.hu> on 2005/08/08 13:27:56 UTC

Using User variables in BeanShell

Hallo,

I would like to write some User Variables to log on certain conditions.

Unfortunately I was not able to find out how to get the values of User 
Variables in BeanShell.


This is my try:

import org.apache.jmeter.threads.JMeterContext;
import org.apache.jmeter.threads.JMeterContextService;
import org.apache.jmeter.threads.JMeterVariables;

// write erro message to log
if ( ResponseCode != null && ResponseCode.equals("200") == false )
{
  Failure=true ;
  FailureMessage = "response code was not 200 reponse code it was " + 
ResponseCode + "." ;
  log.warn("the return code is " + ResponseCode);
}
print ( "variable  " + ResponseCode);   // OK
-----------------------------------------------------------------------------------------------------------------------------------------

// How to use user variables in BeanShell ?

// In java code from BeanShell:
// Add variables for access to context and variables  (dut it does not work)
//     JMeterContext jmctx = JMeterContextService.getContext();
//     JMeterVariables vars = jmctx.getVariables();
//     bshInterpreter.set("ctx",jmctx);  //$NON-NLS-1$
//     bshInterpreter.set("vars",vars);//$NON-NLS-1$

// Does not work
print ( "variable  " + ctx);    // return void
print ( "variable  " + vars);  // return void

// Cause exception
print ( "variable  "  + vars.get("myVariable"));           // cause 
exception
JMeterVariables jmvars = (JMeterVariables) vars;  // cause exception
JMeterVariables jmvars = ctx.getVariables();          // cause exception

Thanks for your help.

Miklos


---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: Using User variables in BeanShell

Posted by sebb <se...@gmail.com>.
Difficult to say what the problem is without more information:

What version of JMeter?
What Exceptions?
Which of the BeanShell elements are you using - Sampler, Function,
Response Assertion?
Any messages in jmeter.log?


[There may also be some useful information in the jmeter user mailing
list archives ...]

S.
On 08/08/05, Miklos Tverdota <tv...@axelero.hu> wrote:
> Hallo,
> 
> I would like to write some User Variables to log on certain conditions.
> 
> Unfortunately I was not able to find out how to get the values of User
> Variables in BeanShell.
> 
> 
> This is my try:
> 
> import org.apache.jmeter.threads.JMeterContext;
> import org.apache.jmeter.threads.JMeterContextService;
> import org.apache.jmeter.threads.JMeterVariables;
> 
> // write erro message to log
> if ( ResponseCode != null && ResponseCode.equals("200") == false )
> {
>  Failure=true ;
>  FailureMessage = "response code was not 200 reponse code it was " +
> ResponseCode + "." ;
>  log.warn("the return code is " + ResponseCode);
> }
> print ( "variable  " + ResponseCode);   // OK
> -----------------------------------------------------------------------------------------------------------------------------------------
> 
> // How to use user variables in BeanShell ?
> 
> // In java code from BeanShell:
> // Add variables for access to context and variables  (dut it does not work)
> //     JMeterContext jmctx = JMeterContextService.getContext();
> //     JMeterVariables vars = jmctx.getVariables();
> //     bshInterpreter.set("ctx",jmctx);  //$NON-NLS-1$
> //     bshInterpreter.set("vars",vars);//$NON-NLS-1$
> 
> // Does not work
> print ( "variable  " + ctx);    // return void
> print ( "variable  " + vars);  // return void
> 
> // Cause exception
> print ( "variable  "  + vars.get("myVariable"));           // cause
> exception
> JMeterVariables jmvars = (JMeterVariables) vars;  // cause exception
> JMeterVariables jmvars = ctx.getVariables();          // cause exception
> 
> Thanks for your help.
> 
> Miklos
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org