Jmeter 每个线程具有相同的随机数和字符串
我需要为HTTP请求的每个线程生成两次相同的JSON数据。我在JMeter中设置它时遇到问题。 我的结构是:Jmeter 每个线程具有相同的随机数和字符串,jmeter,Jmeter,我需要为HTTP请求的每个线程生成两次相同的JSON数据。我在JMeter中设置它时遇到问题。 我的结构是: Test Plan - HTTP Header Manager - Thread Group 1 users, 5 loop - Random Variable, - HTTP Request 我尝试将每线程用户设置为true并使用seed实现随机函数,但我无法实现我想要的。它不断地为每个循环生成新的数字/字符串 基本上,对于每个用户,我想要完全相同的JSON
Test Plan
- HTTP Header Manager
- Thread Group 1 users, 5 loop
- Random Variable,
- HTTP Request
我尝试将每线程用户设置为true并使用seed实现随机函数,但我无法实现我想要的。它不断地为每个循环生成新的数字/字符串
基本上,对于每个用户,我想要完全相同的JSON请求数据 我认为你的案件有三项判决:
- 在HTTP请求之前使用。在这里指定变量。在这种情况下,最好使用随机变量
- 在HTTP请求之前使用(循环计数=5)(而不是线程组中的循环=5)
import java.util.Random
def out= new File('File1.txt') // create file if it is not exists
if(!out.exists())
{
out.createNewFile()
Random rand = new Random()
int max = 10
def a = rand.nextInt(max+1)
out << a // write text to file
}
//then read value of generated variable
String fileContents = new File('File1.txt').text
//then put your variable into User defined Variable that I named HELLO
vars.putObject("HELLO",fileContents)
import java.util.Random
def out=new File('File1.txt')//如果文件不存在,则创建该文件
如果(!out.exists())
{
out.createNewFile()
Random rand=新的Random()
int max=10
def a=随机数下一次(最大值+1)
为什么不使用CSV配置数据呢?您的解决方案适用于数值变量。但不适用于字符串变量。我在HTTP请求中调用了RandomString函数,但该函数不断更改值。HTTP请求在循环控制器中。
import java.util.Random
def out= new File('File1.txt') // create file if it is not exists
if(!out.exists())
{
out.createNewFile()
Random rand = new Random()
int max = 10
def a = rand.nextInt(max+1)
out << a // write text to file
}
//then read value of generated variable
String fileContents = new File('File1.txt').text
//then put your variable into User defined Variable that I named HELLO
vars.putObject("HELLO",fileContents)