JMeter循环变量

JMeter循环变量,jmeter,Jmeter,我有Jmeter(2.5.1)中的测试用例。 我需要定义一个变量,然后在while循环中更改其值,基本上: isQuest = true; while(${isQuest}){ Http Sampler Reg Exp Extractor -> set the isQuest based on the result } 因为JMeter在开始时会将用户定义的变量加载到内存中一次,所以它不允许我为内存中的变量分配另一个值 克服此问题的最佳方法是什么?您可以使用j

我有Jmeter(2.5.1)中的测试用例。
我需要定义一个变量,然后在while循环中更改其值,基本上:

isQuest = true;
while(${isQuest}){
     Http Sampler
         Reg Exp Extractor -> set the isQuest based on the result
}
因为JMeter在开始时会将用户定义的变量加载到内存中一次,所以它不允许我为内存中的变量分配另一个值


克服此问题的最佳方法是什么?

您可以使用jmeter属性而不是变量,通过或beanshell代码访问:

${__P(whileCondition,)}
${__setProperty(whileCondition,TRUE,)}
${__BeanShell(props.get("whileCondition")}
${__BeanShell(props.set("whileCondition")}
您可以尝试使用以下结构:

Thread Group HTTP Request //set-found-condition ${__setProperty(txtFound,FALSE,)} While Controller // invert value in condition - will be executed while txtFound == FALSE Condition = ${__BeanShell(!props.get("txtFound")} . . . [execute your test logic here] . . . YOUR HTTP Request Response Assertion // set your text assertion here // this will results in ${JMeterThread.last_sample_ok} = TRUE if text found IF Controller --FOUND // if text found set separate variable or property - e.g. ${txtFound} - into TRUE Condition = ${JMeterThread.last_sample_ok} HTTP Request //set-found-condition ${__setProperty(txtFound,TRUE,)} // this will be inverted to FALSE in the next WHILE cycle's condition, WHILE cycle will be exited . . . 螺纹组 HTTP请求 //设置发现条件 ${\uuuSetProperty(txtFound,FALSE,)} While控制器 //将在txtFound==FALSE时执行条件-中的反转值 Condition=${BeanShell(!props.get(“txtFound”)} . . . [在此处执行测试逻辑] . . . 您的HTTP请求 响应断言 //在此处设置文本断言 //如果找到文本,这将导致${JMeterThread.last_sample_ok}=TRUE 如果控制器--找到 //如果找到文本,则将单独的变量或属性(例如${txtFound})设置为TRUE 条件=${JMeterThread.last_sample_ok} HTTP请求 //设置发现条件 ${uuuu setProperty(txtFound,TRUE,)}//在下一个WHILE循环的条件中,该值将被反转为FALSE,而该循环将被退出 . . .
我认为您也可以轻松地使用附加到HTTP请求的BSF或BeanShell后处理器将txtFound属性设置为TRUE,而不是使用IF进行繁琐的构造。

否,您可以在运行时为用户定义的变量赋值。如果您使用BeanShell预处理器,
vars.put(“variablename”,“variablevalue”);