0
votes

How can I use beanshell Post Processor for analyze data from each request ? I need analyze request and if request PASS - write in file, if request FAIL - write in other file. Any body can write simple example script for this situation ?

2

2 Answers

0
votes

If you want to save the passed and failed requests in different files, you can use View Results Tree listener element, no need of beanshell Post processor and beanshell scripting. Add two View results tree() elements to thread group. For saving requests that are passed, tick Successes under Log/Display only option. Also provide a file path for saving these requests. To store failed requests check Errors in second view results tree element and file path as in figure. You can decide what to be stored under Configure button.

Note: This consumes more memory and should not be used for huge load.

enter image description here

0
votes
SampleResult res = ctx.getPreviousResult();

if(res.isSuccessful()) {
    String DirPath = FileServer.getFileServer().getBaseDir();

    // write into jmeter.log file under Jmeter/bin directory
    RandomAccessFile f = new RandomAccessFile(DirPath + File.separator + "SuccessFile"+"."+ fileSize, "rw");
    f.writeUTF(DirPath.toString());
    f.writeUTF("test.txt");
} else {
 // do same thing to create a file for failure.
}