我已按以下顺序添加了测试计划
1.Test Plan with user defined variables
2.Header Manager
3.Thread Group 1
4.Http Request
5.JSON extractor
6.Thread Group 2
7.Http Request
8.BeanShell Preprocessor
9.Result Tree
如何将访问令牌从第一个线程组传递到第二个线程组?
我已按以下顺序添加了测试计划
1.Test Plan with user defined variables
2.Header Manager
3.Thread Group 1
4.Http Request
5.JSON extractor
6.Thread Group 2
7.Http Request
8.BeanShell Preprocessor
9.Result Tree
如何将访问令牌从第一个线程组传递到第二个线程组?
Just finished figuring this out. Don't know if it's the best solution. Looked like there were other options.
In my case the first thread group was reading a list of users and passwords from a csv file.
I did it by writing a csv file in the first thread using "JSR223 PostProcessor" after each authentication API call.
Then I read the newly created csv using the "CSV Data Set Config" in the second thread.
Groovy script follows:
import org.apache.jmeter.services.FileServer
log.info("*************************************")
def userId = vars.get("user_id") //JMeter var from parsing auth request
def authToken= vars.get("auth_token")
def configDir = vars.get("config_dir")
log.info("userId:" + userId)
log.info("authToken:" + authToken)
def outputFilePath = configDir + "/userToken.csv"
File outputFile = new File(outputFilePath)
//check if the file exists
if (!outputFile.exists()) {
log.info("File " + outputFilePath + "does not exist")
log.info("Creating a new file")
outputFile << "userId,authToken\n"
}
outputFile << userId + "," + authToken + "\n"
在您上次执行测试期间至少有 3 个错误:
检查jmeter.log 文件以获取详细信息,原因应该在那里
您应该使用不同的线程组来代表不同的业务用户组,如果您正在模拟身份验证流程,将两个 HTTP 请求采样器保持在一个线程组下是有意义的
JMeter 变量是线程(虚拟用户)的本地变量,因此您将无法访问不同线程和线程组中的变量值
根本不需要编写脚本,只需添加一个 HTTP 标头管理器作为workspace
请求的子项(请参阅JMeter 范围规则 - 终极指南文章以了解有关 JMeter 测试元素范围的更多信息)并在那里定义令牌。建议的测试计划结构: