Exit the loop when Assertion is true

I am using MailReaderSampler, which receives all messages from a given email id. All letters have a validation token. In the meantime, the token is being mailed.

Thus, the response data will have :

Date:-- To: -- From: -- Subject: token : someToken

I defined the Token value in User Defined Variables, and I use Response assertionto check if the mail contains a token .

Thus, it checks all sub-results (all emails). Now that the email address contains the token, then I want to stop the test, and the approval condition should not check other emails, as it has already detected an email with a symbolic value .

Any suggestions on how to do this?

+4
source share
1 answer

This should do the trick, but I haven't tried it yet ... Add a BeanShell sampler after your mail sampling using the following code.

import org.apache.jmeter.samplers.SampleResult;
import org.apache.jmeter.threads.JMeterContextService;

SampleResult[] subResults = JMeterContextService.getContext().getPreviousResult().getSubResults();
for(SampleResult sr : subResults) {
    if (sr.getResponseDataAsString().contains(vars.get("Token").toString()))
        JMeterContextService.getContext().getEngine().stopTest();
}
0
source

All Articles