每次运行负载测试(注册)时,我都需要创建具有(名字、姓氏、电子邮件、密码)值的唯一用户。
我已经有一个空的 CSV 设置配置,其中包含名字、姓氏、电子邮件、密码值。 问题是 Jmeter 尝试使用之前使用过的电子邮件创建新用户。 我的目标是为我需要生成的 10,000 个唯一用户运行负载测试。
请帮忙!
JMeter 不会“生成”任何内容 - 它只是从文件中读取条目,如果它为空 - 它只会以
${username}
的形式发送空值或变量占位符。
您需要预先生成电子邮件并将其填充到 setUp Thread Group 中并将它们写入 CSV 文件,或者用 JMeter Functions 替换变量,这将动态生成随机/唯一数据,如 __RandomString()或 __UUID() 或 __time() 或以上任意组合。
您可以尝试以下解决方案:
2。将以下 groovy 代码添加到 5 个字段的 JSR223 预处理器中。
import org.apache.commons.lang3.RandomStringUtils
// Get the current Thread Number and Iteration Count
def threadNumber = ctx.getThreadNum()
def iterationCount = ctx.getVariables().getIteration()
// Generate random data
def firstName = RandomStringUtils.randomAlphabetic(5)
def lastName = RandomStringUtils.randomAlphabetic(5)
def email = "${firstName}_${lastName}_${threadNumber}_${iterationCount}" + "@email.com"
def password = RandomStringUtils.randomAlphanumeric(8)
def confirmPassword = password
// Set variables to be used in the test
vars.put("P_FirstName", firstName)
vars.put("P_LastName", lastName)
vars.put("P_Email", email)
vars.put("P_Password", password)
vars.put("P_ConfirmPassword", confirmPassword)
4。现在,在每个请求之前,预处理器将为各个字段生成唯一的值。示例:
希望这有帮助!