how to write assertion error log into a file by using BeanShell Jmeter.

Solved189 views
0

I want to write all Assertions error in a HTML file so at once I can see which assertion is not working I am looking for BeanShell code for write data into a file.

Question is closed for new answers.
Selected answer as best
0

Paste below code to Beanshell Assertion it will create a HTML file and write failed assertion response to a file.

import org.apache.jmeter.services.FileServer;
f = new FileOutputStream("/home/test/apache-jmeter-3.2/bin/result.html", true);
pt = new PrintStream(f);
pt.println("<html><body>");
for (a: SampleResult.getAssertionResults()) {
if (a.isError() || a.isFailure()) {
log.error("URL :"+ ctx.getCurrentSampler().toString());
log.error(Thread.currentThread().getName()+": "+SampleLabel+": Assertion failed for response: " + new String((byte[]) ResponseData));
pt.println(URL :"+ ctx.getCurrentSampler().toString());
pt.println(Thread.currentThread().getName()+": "+SampleLabel+": Assertion failed for response: " + new String((byte[]) ResponseData)); // update here what you want to write
}
pt.println("</body></html>");
pt.close();
f.close();
}

Selected answer as best