In JMeter, I need to extract a value from response, only when text assertion fails for a request. And display the extracted value in log

126 views Asked by At

I have a JSON request which sends 200 OK response even when response body is not correct. I want to capture "wrongdata" value only from incorrect response bodies and display them in log or results file.

How can I do this.

Tried adding a JSON extractor and stored the value in as "myVariable". enter image description here

Then added a JSR223 PostProcessor with the below code: enter image description here

Looks like JSR223 postprocessor is not executing

2

There are 2 answers

0
rollno748 On

The simplest way to achieve the requirement is

  1. Enable the text check for the request

  2. Add simple data writer listener to the test plan and provide a file location path to write the data. Then enable errors only option in it. Then click configure button -> check all the required data needs to logger when failure

  3. Later, You can view the file using view results tree listener or via editor (if you are comfortable)

0
Dmitri T On

JSR223 PostProcessor is being executed for sure, but it will do anything meaningful only if response will contain wrongData

In the opposite case it will just won't get into the if block

You might also want to mark the request as failed, it can be done using prev.setSuccessful(false) function

More information on Groovy scripting in JMeter: Apache Groovy: What Is Groovy Used For?