当前位置:网站首页>Jmeter parameter transfer method (token transfer, interface association, etc.)
Jmeter parameter transfer method (token transfer, interface association, etc.)
2022-07-31 00:23:00 【Weimu fills the sea】
简介
JmeterThe parameter transfer from the thread group dimension is divided into the transfer within a thread group and between multiple thread groups,Because each thread group runs independently,Therefore, it is necessary to pass between multiple thread groupsbeashellThe post processor sets the extracted parameters as global variables.
适用场景
When we are doing interface testing or functional testing,Need to get the login interfacetokento continue to access other interfaces,Or there are data dependencies between interfaces,比如接口BThe input needs to depend on the interfaceA的返回字段.
Parameter passing category
Intra-thread parameter passing
Argument passing within a thread group can be done via regular expression extractors and json提取器.
正则表达式提取器
This element will be in its scope 请求之后执行,应用正则表达式、提取请求的值、Generate a template string and store the result into the given variable name.
组件说明:
● 引用名称:The variable name in which to store the matching result,Can be a single value or a set of values
● 正则表达式:Regular expression to match content,There can be multiple regular expressions in a regular expression
● 模板:Regular expression extractor type,样式为: n n n,Templates can be freely combined,Concatenate to form a new string content.
- 模板为 0 0 0,则为整个表达式匹配到的内容;
- 模板为: 1 1 1,It corresponds to the first parentheses in the regular expression()匹配的内容;
- 模板为 2 2 2,corresponds to the second parenthesis in the regular expression()匹配的内容;
- 模板为 1 1 1 2 2 2,则把2个()所匹配的内容拼接起来, 1 1 1aa 2 2 2Concatenates the contents of two variables,并在中间加上aa
● 匹配数字:-1代表取全部数据,0代表随机取值,1代表取第1个数据,2代表取第2个数据,正数N代表取第N个
● 缺省值:找不到匹配时的值
json提取器
JSON 后处理器使用 JSON PATH 语法从 JSON 响应中提取数据.Post processors are very similar to regular expression extractors.它必须作为 HTTP A sampler or any other child of a sampler with a response.
组件说明
● 变量名:Stores the extracted variable name
● Json Path Expressions:Json Path 表达式,返回匹配的结果
● Match Numbers: 匹配的数量,如果jsonPath returns multiple results:0Represents random acquisition;1represents the acquisition of the first1个数据;N代表第N个结果,如果Ngreater than the number of matches,使用默认值;-1Represents fetching all data
● Compute concatenation var (suffix_ALL):是否统计所有,All the matched values will be saved as variables_ALL.
● Default Values: The prompt message when there is no matching value
Json Extractor The extracted value is stored in a variable,The method of use is the same as that of ordinary variables,通过${}引用Json Extractor 的变量即可.Json ExtractorThe stored variable names are expanded based on the variable names in the extractor,建议通过添加DebugSampler获取Json ExtractorThe variable name that actually stores the value.
示例
1、设置变量名、Json Path 表达式
2、Add new ones within the same thread grouphttp请求,设置参数变量
login_nameThe value is set to jsonThe variable extracted by the extractor
3、执行测试计划,查看结果树
Parameter passing between multithreaded groups
BeanShell后置处理器
Parameter passing between thread groups requires additional useBeanShell后置处理器.
The post processor is applied after the sampler,They apply to all samplers in the same scope,To ensure that post processors are only applied to specific samplers,It needs to be added as a child of the sampler.
The overall idea of the post-processor is similar to the code we write,即:
1.Extract the fields that need to be retrieved
2.把它赋值给一个变量a,In order to get this variable also in other thread groups
3.If the subsequent interface needs to use this variable,Reference this variable directlya
Beanshell传参方式
1、内置变量vars和props
️:
vars Can only be used within the current thread,props 可以跨线程组使用;
vars 只能保存 String 或者 Object,props 是 Hashtable 对象.
//same thread group
vars :操作 jmeter 变量,它是测试用例与 BeanShell 交互的桥梁,常用方法:
vars.get(String key):从jmeter 中获得变量值
vars.put(String key,String value):数据存到 jmeter 变量
//跨线程组
props :操作 jmeter 属性,该变量引用了 JMeter 的配置信息,可以获取Jmeter
的属性,它的使用方法与 vars 类似,但是只能 put 进去 String 类型的值,而不能是一个对象.
props.get("START.HMS");START.HMS 为属性名,在jmeter.properties 中定义
props.put("key","value");
//beanshell语句示例
String str =vars.get("token");
props.put("newToken",str);
vars和props都有put和get方法 ,But since we want to operate across thread groups,所以只能使用props进行put值.
2、函数
//Set variables across thread groups,注意此处的key不要写成“key”
${__setProperty(key,value)}
//Reference variables across thread groups
${__P(key)}//Just need the variable name
${__P(变量名)} 基本等同于${__property(变量名)}
示例:
${__property(init,start,10)} 变量名为init, 默认值为10,同时会将10默认传给start这个变量,startCan be reused ${start}
P和propertyThe difference is whether to store the value of the first variable in another variable
示例
1、添加后置处理器
2、编写beanshell脚本,传递参数
3、Add user management thread group,添加更新用户http请求
4、引用全局变量
设置接口入参"token"The value of is a variable processed by the post processoruserName
5、执行测试计划,查看结果树
边栏推荐
- How to open the payment channel interface?
- Strict Mode for Databases
- 【愚公系列】2022年07月 Go教学课程 015-运算符之赋值运算符和关系运算符
- 什么是Promise?Promise的原理是什么?Promise怎么用?
- Machine Learning 1-Regression Model (2)
- 会议OA项目待开会议、所有会议功能
- 【深入浅出玩转FPGA学习15----------时序分析基础】
- 消息队列存储消息数据的MySQL表设计
- Ukraine's foreign ministry: wu was restored to complete the export of food security
- An easy-to-use interface testing tools - the Postman
猜你喜欢
Steven Giesel 最近发布了一个由5部分内容组成的系列,记录了他首次使用 Uno Platform 构建应用程序的经验。
binglog日志追踪:数据备份并备份追踪
Neural Network (ANN)
joiplay模拟器如何调中文
Error ER_NOT_SUPPORTED_AUTH_MODE Client does not support authentication protocol requested by serv
MySQL数据库面试题总结(2022最新版)
【Multithreading】
(5) fastai application
After writing business code for many years, I found these 11 doorways, which only experts know
2D转换模块&&媒体查询
随机推荐
The difference between substring and substr in MySQL
【Yugong Series】July 2022 Go Teaching Course 017-IF of Branch Structure
ABC 261 F - Sorting Color Balls(逆序对)
Dry goods | 4 tips for MySQL performance optimization
ES 中时间日期类型 “yyyy-MM-dd HHmmss” 的完全避坑指南
pytorch bilinear interpolation
Neural Network (ANN)
封装、获取系统用户信息、角色及权限控制
[Deep learning] Detailed explanation of Transformer model
xss绕过:prompt(1)
Strict Mode for Databases
Machine Learning 1-Regression Model (2)
寄存器(汇编语言)
限制字符绕过
How to solve the error of joiplay simulator
joiplay模拟器rtp如何安装
Gabor滤波器学习笔记
IOT cross-platform component design scheme
Optimization of aggregate mentioned at DATA AI Summit 2022
A Brief Talk About MPI