在JMeter中有条件地重新启动用户线程
问题内容:
我知道我可以在JMeter中有条件地停止线程。
在我的脚本中,我发送一个请求,然后提取它们的响应json以进一步处理它。在少数情况下,参数响应会提供一些我无法在后续步骤中处理的值。
我实际上可以通过提取另一个参数来检测此有效响应。是否可以根据条件重新启动线程,而不是停止线程?
问题答案:
对于进一步的研究人员:
根据条件(即从json中提取一些数据)开始线程的另一次迭代的简单方法是使用BeanShell Sampler,如上所述。
import org.apache.jmeter.samplers.SampleResult;
import org.apache.jmeter.threads.JMeterContext;
import org.apache.jmeter.threads.JMeterContext.TestLogicalAction;
String statVar = vars.get("statusVariable"); //getting some data for condition check (statusVariable is a variable that has been set previously in the Jmeter JSON Extractor)
if(statVar.equals("NOK")){ . //checking the condition
SampleResult.setTestLogicalAction(TestLogicalAction.START_NEXT_ITERATION_OF_THRE
AD); //Starting thread again (it starts the thread from the beginning, so we may compare this to restart effect)
}