问题
I'm using a MailReaderSampler which gets all the messages from given email ID. All the emails have a verification token in it. For now, the token is being passed on the subject of the mail.
So the Response Data will have:
Date:--
To: --
From: --
Subject: token : someToken
I have defined a Token value in User Defined Variables
and I'm using Response assertion
to check if the mail contains the Token.
So it checks for all the sub-results(all emails). Now whenever an email contains the token, then I want to stop the test and the assertion condition should not check in other emails as it already found the email which has token value.
Any suggestions on how to do it?
回答1:
This should do the trick, but I haven't tried it yet... Add BeanShell sampler after your mail sampler with 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();
}
来源:https://stackoverflow.com/questions/38109597/exit-a-loop-when-assertion-is-true