0
votes

I have the JMeter script in the below format.

JMeter Structure

The thing here is, once i send the write request to server, the response can come in variable number of read responses. The first 4 read responses are fixed but after that the number of read responses vary on the server busy times. If the server is very busy it will keep sending small chunks of data in a pair of 2 read responses. That is the reason i have kept it in a while controller looping till the end of the response.

Now, for Asserting this response, i check for the string in a postprocessor and save the output into a JMeter variable.

I finally check the Variable values in a "JSR223 Sampler". If i place a JSR223 Assertion, it applies to only first 4 read responses and ignores the responses under While Controller. Problem i'm facing, the error is not getting reported if the text check fails. However, it is ending the iteration and starting a new one.


JSR223 PostProcessor 1

String id=prev.getResponseDataAsString();
vars.put("ReadResponse",id);

if(id.contains("STRING TO FIND") == true)
{
vars.put("s_check", "true");
}
else
{
vars.put("s_check", "false");
}

JSR223 PostProcessor 2

String id=prev.getResponseDataAsString();
vars.put("ReadResponse",id);

if(id.contains("STRING TO FIND") == true)
{
vars.put("s_check_1", "true");
}
else
{
vars.put("s_check_1", "false");
}

JSR223 Sampler

SampleResult.setIgnore();
import org.apache.jmeter.threads.JMeterContext.TestLogicalAction;
import org.apache.jmeter.samplers.SampleResult;

//Final Response Assertion
String s1 = "N";
String s2 = "N";

if( ${__isVarDefined(s_check)} == true )
{
s1 = vars.get("s_check");
}
if( ${__isVarDefined(s_check_1)} == true )
{
s2 = vars.get("s_check_1");
}

if( (s1 == "false" && s2 == "false") || (s1 == "false" && s2 == "N") || (s1 == "N" && s2 == "false") )
{
SampleResult.setSuccessful(false); //NOT WORKING
SampleResult.setResponseMessage("accountID page is not loaded"); //NOT WORKING
ctx.setTestLogicalAction(TestLogicalAction.START_NEXT_ITERATION_OF_THREAD); //WORKING
}
1

1 Answers

0
votes

C'mon, how do you know that these SampleResult.setSuccessful(false); and SampleResult.setResponseMessage("accountID page is not loaded"); lines are "//NOT WORKING" given you have SampleResult.setIgnore();?

If you invoke SampleResult.setIgnore(); you will not see the JSR223 Sampler neither in Listeners nor in the .jtl results file, remove this line and it should start working as expected or at least according to the weird logic of your Groovy script.

One more thing: don't inline JMeter Functions or Variables into Groovy scripts, as per JSR223 Sampler documentation:

When using this feature, ensure your script code does not use JMeter variables directly in script code as caching would only cache first replacement. Instead use script parameters.

The correct way to check the presence of a JMeter variable would be:

if (vars.get('s_check') != null) {
    s1 = vars.get('s_check')
}

More information: Apache Groovy - Why and How You Should Use It