You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jmeter.apache.org by Isabel Beltran <ib...@hotmail.com> on 2005/04/14 13:39:59 UTC

How to jump over some HTTPSamplers when one fails with BeanShell assertions?

In my test case, after each HTTPSampler I run a BeanShell assertion to test 
the response data and set Failure to true/false accordingly.

Till now, I set "setStopThread" to "true" and exit when " failure==true". 
But now, I need to do a final sampler to do some cleanup even when it fails. 
I decided to use the IFController with the condition true!=${Failure} to 
jump over. It is not working. So, I changed my mind to use a user variable 
or user parameter inside the BeanShell assertion and use it in the 
condition, but I do not know if it is possible  to access UserParameters in 
BeanShell assertion and how can it be done.

So, am I in the right path?. Any ideas on how to achieve this?.

I know that it can be done easy using the Regular Expression Extractor to 
set a variable to  be used in the condition, but I am receiving EBCDIC data 
in the response.

The BeanShell assertion looks this way:

         byte [] arr = (byte[]) ResponseData ;
         if (arr!=null && (arr[33] & 0x0d) == 0x0d) {
             Failure= true ;
             FailureMessage = " Error" ;
             ByteArrayOutputStream baos = new ByteArrayOutputStream();
             baos.write(ResponseData);
             baos.close();
             log.debug("Response data = " + baos.toString("Cp1047"));
//          setStopThread(true);
         }

Any help would be appreciated. Thanks in advance

Isabel



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


Re: How to jump over some HTTPSamplers when one fails with BeanShell assertions?

Posted by sebb <se...@gmail.com>.
In this case, "Failure" is a BeanShell variable, not a JMeter
Variable, so is not available to the rest of JMeter.

One way round this is to use properties - however, these are global.

The sample file bin/BeanShellSampler.bshrc shows how to read/write
JMeter properties.

It's also possible to access the JMeter variables as follows:

import org.apache.jmeter.threads;

	    	JMeterContext jmctx = JMeterContextService.getContext();
	        JMeterVariables vars = jmctx.getVariables();

		vars.put("myvar","abcd");
		value=vars.get("myvar");

The BeanShell function already has access to "ctx" and "vars";
unfortunately these were not set up for the Beanshell Assertion or
BeanShell Sampler. This will be fixed in a later release, meanwhile
you can use the code above to set a JMeter Variable, which will then
be available to all other test elements in the same thread.

Hope this helps.

S.
On 4/14/05, Isabel Beltran <ib...@hotmail.com> wrote:
> In my test case, after each HTTPSampler I run a BeanShell assertion to test
> the response data and set Failure to true/false accordingly.
> 
> Till now, I set "setStopThread" to "true" and exit when " failure==true".
> But now, I need to do a final sampler to do some cleanup even when it fails.
> I decided to use the IFController with the condition true!=${Failure} to
> jump over. It is not working. So, I changed my mind to use a user variable
> or user parameter inside the BeanShell assertion and use it in the
> condition, but I do not know if it is possible  to access UserParameters in
> BeanShell assertion and how can it be done.
> 
> So, am I in the right path?. Any ideas on how to achieve this?.
> 
> I know that it can be done easy using the Regular Expression Extractor to
> set a variable to  be used in the condition, but I am receiving EBCDIC data
> in the response.
> 
> The BeanShell assertion looks this way:
> 
>         byte [] arr = (byte[]) ResponseData ;
>         if (arr!=null && (arr[33] & 0x0d) == 0x0d) {
>             Failure= true ;
>             FailureMessage = " Error" ;
>             ByteArrayOutputStream baos = new ByteArrayOutputStream();
>             baos.write(ResponseData);
>             baos.close();
>             log.debug("Response data = " + baos.toString("Cp1047"));
> //          setStopThread(true);
>         }
> 
> Any help would be appreciated. Thanks in advance
> 
> Isabel
> 
> ---------------------------------------------------------------------
> 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