On 12/10/2008, Pavel Gouchtchine <[EMAIL PROTECTED]> wrote:
> Thanks a lot.
> This is working as expected:
>
>
> import org.apache.jmeter.util.JMeterUtils;
> import org.apache.jmeter.samplers.SampleResult;
>
> import org.apache.jmeter.assertions.AssertionResult;
>
You probably don't need the imports.
>
> print("running");
> SampleResult prev_result=ctx.getPreviousResult();
There is no need to declare variables.
Also, the current result (i.e. the one the Assertion is intended to be
applied to) is already set up in the variable "SampleResult".
See:
http://jakarta.apache.org/jmeter/usermanual/component_reference.html#BeanShell_Assertion
for all the variables that are defined to the BeanShell Assertion script.
> if (prev_result != null) {
>
> print("prev is not null");
>
> AssertionResult [] results=prev_result.getAssertionResults();
>
> if (results == null) print ("results is null");
>
> int size = results.length;
>
> for (int i=0; i<=size-1; i++) {
>
> AssertionResult result_item = results[i];
>
> if (result_item == null) print ("result item is null");
>
> else print("result_item "+i+" is not null");
> print("Name: "+result_item.getName()+" ===>
> "+result_item.toString());
>
> }
> }
> else print("prev_result is null");
>
>
> On Sat, Oct 11, 2008 at 7:35 PM, sebb <[EMAIL PROTECTED]> wrote:
> > On 12/10/2008, Pavel Gouchtchine <[EMAIL PROTECTED]> wrote:
> >> Hi All.
> >> I am trying to get access to "prev" variable (SampleResult object)
> >> from BeanShell Assertion.
> >> My code look like this:
> >>
> >> import org.apache.jmeter.util.JMeterUtils;
> >> import org.apache.jmeter.samplers.SampleResult;
> >>
> >> print("running");
> >> SampleResult prev=vars.get("prev");
> >> if (prev != null) {
> >> print("prev is not null");
> >> results=prev.getAssertionResults();
> >> if (results == null) print ("results is null");
> >> size = results.length;
> >> for (int i=0; i<=size-1; i++) {
> >> result_item = results[i];
> >> if (result_item == null) print ("result item is null")
> >> else ("result_item "+i+" is not null");
> >> }
> >>
> >> This code does not work at all. prev variable is null.
> >
> > The previous sampler is stored in the BeanShell variable "prev", not
> > the JMeter variable "prev". The code above overwrote the variable you
> > want...
> >
> > Just use "prev" - it is already set up, as are the other variables,
> > e.g. "log", "ctx" etc.
> >
> >> Please, help.
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: [EMAIL PROTECTED]
> >> For additional commands, e-mail: [EMAIL PROTECTED]
> >>
> >>
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]