On 02/02/2009, perf_eng <[email protected]> wrote:
>
>  I have assertion results for every page that I visit.  In the beanshell post
>  processors, I am trying to ascertain if the previous assertion was a success
>  or failure so that I can force it to make a decision on whether or not to
>  access the subsequent pages.  Essentially, if the previous assertion fails,
>  skip all remaining requests to prevent cascading failures.

No need for a BeanShell PP in that case - just check the variable

        JMeterThread.last_sample_ok

see for example:

http://jakarta.apache.org/jmeter/usermanual/component_reference.html#If_Controller

But if you do want to use BeanShell, then just use the boolean
prev.isSuccessful()

This will work even if the sample fails entirely (e.g. 404) when the
Assertions would be skipped anyway (unless you select Ignore status).

>
>
>  sebb-2-2 wrote:
>  >
>  > On 02/02/2009, perf_eng <[email protected]> wrote:
>  >>
>  >>  I am having a similar issue.  I have a test plan with an http sampler
>  >> with a
>  >>  response assertion as the first child and a beanshell post processor as
>  >> the
>  >>  second child.  When I use the "prev" variable such as this
>  >>
>  >>  assertionLength = prev.getAssertionResults().length;
>  >>
>  >>  assertionLength is 0 even though the assertion did not fail nor give an
>  >>  error.  Where am I going wrong?  I will provide more detail if needed.
>  >>
>  >
>  > Assertion results are only generated if there is an error.
>  > You can see that if you use the Tree View Listener.
>  >
>  > What are you actually trying to do with the BSH PP?
>  >
>  >>
>  >>  sebb-2-2 wrote:
>  >>  >
>  >>  > 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]
>  >>  >
>  >>  >
>  >>  >
>  >>
>  >>  --
>  >>
>  >> View this message in context:
>  >> 
> http://www.nabble.com/How-get-SampleResult-from-BeanShell-Listener-tp19937409p21793226.html
>  >>  Sent from the JMeter - User mailing list archive at Nabble.com.
>  >>
>  >>
>  >>
>  >>  ---------------------------------------------------------------------
>  >>  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]
>  >
>  >
>  >
>
>  --
>
> View this message in context: 
> http://www.nabble.com/How-get-SampleResult-from-BeanShell-Listener-tp19937409p21795540.html
>
> Sent from the JMeter - User mailing list archive at Nabble.com.
>
>
>  ---------------------------------------------------------------------
>  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]

Reply via email to