我一直在使用 JMeter,我知道__Random
and __RandomString
功能。我需要选择一个随机选项并将其存储在变量中,因为它将用作多个调用的参数路径的一部分。例如:
http://www.example.com/pets/{random option such as: cat, dog, parakeet}/
我尝试过像这样简单地设置变量${query}
to one
, two
, or three
使用随机控制器,并将用户定义的变量作为子变量。这似乎是这样should工作,但我总是得到${query}
set to three
.
任何见解或想法都会受到好评。提前感谢大家。
您可以使用Beanshell 预处理器 http://blazemeter.com/blog/queen-jmeters-built-componentshow-use-beanshell生成随机值
String[] query = new String[]{"cat", "dog", "parakeet"};
Random random = new Random();
int i = random.nextInt(query.length);
vars.put("randomOption",query[i]);
之后在你的HTTP请求 http://jmeter.apache.org/usermanual/component_reference.html#HTTP_Request
http://www.example.com/pets/${randomOption}
作为替代方案String[] query = new String[]{"cat", "dog", "parakeet"};
您可以使用预定义的 BeanshellParameters
节。
Random random = new Random();
int i = random.nextInt(query.length);
vars.put("randomOption",bsh.args[i]);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)