当前位置:网站首页>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、执行测试计划,查看结果树
边栏推荐
猜你喜欢
.NET 跨平台应用开发动手教程 |用 Uno Platform 构建一个 Kanban-style Todo App
Summary of the stock problem of state machine dynamic programming
@requestmapping注解的作用及用法
2D Transform Module && Media Queries
[In-depth and easy-to-follow FPGA learning 13---------Test case design 1]
MySQL table design for message queue to store message data
消息队列存储消息数据的MySQL表设计
(5) fastai application
[Tang Yudi Deep Learning-3D Point Cloud Combat Series] Study Notes
joiplay模拟器如何调中文
随机推荐
binglog log tracking: data backup and backup tracking
Jetpack Compose学习(8)——State及remeber
firewalld
Dry goods | 4 tips for MySQL performance optimization
[In-depth and easy-to-follow FPGA learning 15---------- Timing analysis basics]
在微服务中使用事件溯源的六大原因 - Herath
从笔试包装类型的11个常见判断是否相等的例子理解:包装类型、自动装箱与拆箱的原理、装箱拆箱的发生时机、包装类型的常量池技术
transition transition && animation animation
Xss target drone training [success when pop-up window is realized]
数据库的严格模式
[Deep learning] Detailed explanation of Transformer model
joiplay模拟器如何导入游戏存档
Necessary artifacts - AKShare quants
会议OA项目待开会议、所有会议功能
How to install joiplay emulator rtp
Oracle一个诡异的临时表空间不足的问题
The first level must project independently
How to solve the error of joiplay simulator
Kotlin协程:协程上下文与上下文元素
MySQL系列一:账号管理与引擎