You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jmeter.apache.org by Marcelo Jara <ma...@hotmail.com> on 2013/02/15 00:20:02 UTC

Custom assertion message

I am trying to log some custom error messages so that I know exactly why something failed. For example, if I try to log in to an application, it mail fail for many reasons. I have a Response Assertion that checks for an error message. This works fine. But now I also want to log what the username and password caused the error since the test plan picks from a large data set. 
I've tried added a BeanShell Assertion on top of the Response Assertion, but the value of SampleResult is always false. 
Is there a way to act upon the Response Assertion and log a custom error message if the Response Assertion fails? 		 	   		  

Re: Custom assertion message

Posted by Shmuel Krakower <sh...@gmail.com>.
You can add an If Controller after the relevant Sampler and put the
following condition:
"${JMeterThread.last_sample_ok}" == "false"

Then you can have a BeanShell Sampler to log out whatever you want, like:
BufferedOutputStream out = new BufferedOutputStream(new
FileOutputStream("log.txt", true));
out.write((vars.get("username") + "," + vars.get("password") +
"\n").getBytes());
out.flush();
out.close();

Another option is to add a Simple Data Writer listener to log all info
(i.e. request and response headers/data) on failing samples (only) into a
file, then you can analyze the results by opening this file in a View
Results Tree listener.


Shmuel Krakower.
www.Beatsoo.org - re-use your jmeter scripts for application performance
monitoring from worldwide locations for free.


On Fri, Feb 15, 2013 at 1:20 AM, Marcelo Jara <ma...@hotmail.com>wrote:

> I am trying to log some custom error messages so that I know exactly why
> something failed. For example, if I try to log in to an application, it
> mail fail for many reasons. I have a Response Assertion that checks for an
> error message. This works fine. But now I also want to log what the
> username and password caused the error since the test plan picks from a
> large data set.
> I've tried added a BeanShell Assertion on top of the Response Assertion,
> but the value of SampleResult is always false.
> Is there a way to act upon the Response Assertion and log a custom error
> message if the Response Assertion fails?
>