当前位置:网站首页>How to use JMeter function and mockjs function in metersphere interface test
How to use JMeter function and mockjs function in metersphere interface test
2022-07-01 17:16:00 【Fit2cloud flying cloud】
MeterSphere Interface testing of open source continuous testing platform 、 Performance tests are based on JMeter Realization , And compatible JMeter The function in . In the use of MeterSphere Do interface tests 、 When preparing test data , Need to be used frequently JMeter Function to construct test data that generates interface tests .
Because the data preparation process often needs to check and explore JMeter The scope and method of function , For memo and easy viewing , In order to reduce the time of exploration and experiment , This article will summarize and demonstrate this part , I hope that's helpful .
- JMeter Function settings use
stay MeterSphere platform ,JMeter Functions can be in the interface 、 Interface use case request parameters QUERY Parameters 、REST Parameters 、 Request body 、 Pre operation script 、 Set the use in the post operation script .
1.1 frequently-used JMeter Functions and calls
JMeter All supported functions can be viewed through JMeter Official documents , Or Baidu search related articles and other ways to understand .
The format of the function call is :${__functionName(var1,var2,var3)}.
among ,__functionName For function name , In parentheses are the parameters of the function , Brackets can be omitted when there are no parameters , for example ${_UUID}.
The following are some commonly used functions and use examples :
1.2 Use JMeter function
stay MeterSphere in , Parameters can be requested in interface use cases QUERY Parameters 、REST Parameters 、 Request body 、 Reference in pre and post scripts JMeter function .
The quotation and use method are shown in the following table ( To generate UUID Function as an example ):
One thing to note is that , In front / The post script can also be referenced JMeter Functional .
Specific usage :
① Enter the calling method of the function in double quotation marks , Pictured 1-1 Shown ;
② With Python Take the reference in the script as an example , stay “ Inquire about database List interface use cases ” On the page , Set the following script content as the pre script content , Pictured 1-1 Shown ;
③ Then execute the use case , stay “ Console ” You can see the printed uuid and time Timestamp generated by function , Pictured 1-2 Shown .
uuid="${__UUID()}";
strTime="${__time()}";
log.info("--------pre script begin-------------");
log.info("uuid="+uuid);
log.info("strTime="+strTime);
log.info("--------pre script end-------------");
chart 1-1 Use in pre script JMeter function
chart 1-2 Console output JMeter function
1.3 stay QUERY Parameters 、REST Use in parameter JMeter function
stay QUERY Parameters 、REST Parameter is set to use JMeter function , The specific operation method is :
Get into “ Interface use cases ” page , stay “ Request parameters ” Panel “QUERY Parameters ” Tab , Selection as shown 1-3 Pencil icon shown “ edit ” Button , open “ Parameter setting ” Dialog box , Select settings in the dialog box and save , Pictured 1-4 Shown ; You can also directly enter “$”, Then pull down JMeter Select the function to be used in the function list JMeter function , Pictured 1-5 Shown ;
After setting , When executing use cases , The platform will pass JMeter The parameter value generated by the function sends a request .
chart 1-3 Choose to open “ Parameter setting ” Dialog box
chart 1-4 Parameter setting - Set up JMeter function
chart 1-5 Parameter setting - Input $ Choose... From the drop-down list JMeter function
1.4 Specific scenario demonstration examples
Now we use InfluxDB The process of writing interface test scenarios , To demonstrate JMeter Use of functions .
call InfluxDB write in API Of CURL The order is as follows , We can use API Definition and CURL Commands create interface definitions and interface use cases .
# Write interface API curl call
curl -i -XPOST 'http://10.1.13.12:8086/write?db=monitoringdb' --data-binary 'cpu_usage,host=10.1.10.131,app=dataease value=0.10 1632761023000000000'
#cpu_usage by measurement, Similar to tables in relational databases , host For the host ID,app by dataease
The operation steps are as follows :
① stay “ Interface list ” page , establish “InfluxDB Write interface ”, Set the request protocol to “POST”, Path is “/write”, Pictured 1-6 Shown ;
② stay “CASE” page , choice “+ add to ” Button , open “ Create interface use cases ” page , Create write interface use cases , Pictured 1-7、 chart 1-8 Shown ;
③ according to CURL command , You can see that we need to set QUERY Parameters db, And the request body raw Content . Pictured 1-9 Shown , add to QUERY Parameters db, The setting value uses the environment variable ${dbname}.dbname Variables have been set in the environment , The value is “monitoringdb”. Pictured 1-10 Shown , Set request body , Format selection “raw”, The content is set to :
cpu_usage,host=${
_UUID},app=dataease value=${
usage} ${
_time()}000000
■ Use JMeter function __UUID As host ID;
■ Use __time Function generation 13 Bit time stamp ;
■ Use usage Variable ,usage Variables are used in pre scripts python random Function calculation , The results are stored in usage variable .
chart 1-6 Create a write interface
chart 1-7 Select Create write interface use case
chart 1-8 Add settings QUERY Parameters db
chart 1-9 Set request body - Monitoring data
chart 1-10 Set the leading position python Script - Generate usage And save it to the variable
④ Save and execute the use case , stay “ Response content ” In the catalog “ Request content ” in , View request content POST data, Pictured 1-11 Shown . You can see the use of JMeter The value generated by the function , as well as python random The value generated by the function .
cpu_usage,host=e48222aa-e98e-4974-8dfb-df9a1aecc4cc,app=dataease value=0.00309123923176 1652670605313000000
chart 1-11 View request content
- MockJS Function settings use
stay MeterSphere You can set the request parameters in QUERY Parameters 、REST Use... For parameter values MockJS function .
It should be noted that :
■ MockJS A function cannot be in the body of a request parameter 、 Used in pre and post scripts ;
■ MockJS Function can select multiple function combinations to generate parameter values .
The specific use method is as follows :
① stay “ Interface use cases “ page , choice ” Request parameters “ In the panel “QUERY Parameters ” label , open “QUERY Parameters ” tab ;
② stay “QUERY Parameters ” Tab , Selection as shown 2-1 Pencil icon shown “ edit ” Button , open “ Parameter setting ” Dialog box ;
③ stay “ Parameter setting ” In the dialog box , choice “Mock data ” label , open “Mock data ” tab , In the tab MockJS Select Add... From the list MockJS function , Pictured 2-2 Shown .
MockJS Function supports random generation of Boolean values 、 Natural number 、 Integers 、 Floating point numbers 、 character 、 character string 、 date 、 Time 、 Date time 、 Current time isoparametric value , The details can be found in MockJS View in the function list , And you can click “ preview ” Button to view the generation effect .
chart 2-1 Choose to open “ Parameter setting ” Dialog box
chart 2-2 Parameter setting - choice MockJS function
You can also directly enter “@”, Then pull down MockJS Select the function to be used in the function list MockJS function , Pictured 2-3 Shown .
chart 2-3 Directly enter... In the parameter value input box @ Character list MockJS And select
Next, a scenario of creating interface use cases and setting parameter values is used to demonstrate the specific use :
Pictured 2-4 Shown , stay “ Interface use cases ” On the page , Add two QUERY Parameters : One key is “pretty”, The value is “@boolean”; One key is “serverName”, The value is “@[email protected]”. After executing the use case , It can be found in “ Request content ” Tab to view the random values generated by these functions , Pictured 2-5 Of “ Request content ” Shown .
■ “pretty” Of @boolean The function generates false;
■ “serverName” Of @[email protected] The function generates gl8Im02011-12-2116:10:31.
chart 2-4 MockJS function ( With @ start )
chart 2-5 Check the function output in the request content
- summary
In this paper, we sum up our experience in MeterSphere Open source continuous testing platform JMeter function 、MockJS Methods and precautions of function , And through specific interface test scenarios JMeter Functions and MockJS Use , Hope to be helpful to the majority of community users .
边栏推荐
- Iommu/smmuv3 code analysis (10) page table operation
- 【splishsplash】关于如何在GUI和json上接收/显示用户参数、MVC模式和GenParam
- vulnhub靶场-Hacker_Kid-v1.0.1
- Transition technology from IPv4 to IPv6
- SystemVerilog-结构体(二)
- Soft test network engineer full truth simulation question (including answer and analysis)
- In aks, use secret in CSI driver mount key vault
- Redis 分布式锁
- 单例模式的懒汉模式跟恶汉模式的区别
- Internet News: "20220222" get together to get licenses; Many products of Jimi have been affirmed by consumers; Starbucks was fined for using expired ingredients in two stores
猜你喜欢
Babbitt | yuan universe daily must read: Naixue coin, Yuan universe paradise, virtual stock game Do you understand Naixue's tea's marketing campaign of "operation pull full"
Borui data integrated intelligent observable platform was selected into the "Yunyuan production catalogue" of China Academy of communications in 2022
DNS
[Verilog quick start of Niuke network question brushing series] ~ priority encoder circuit ①
Roewe rx5's "a little more" product strategy
Integer array merge [JS]
Mysql database - Advanced SQL statement (2)
换掉UUID,NanoID更快更安全!
Shenyu gateway development: enable and run locally
(1) CNN network structure
随机推荐
【PyG】文档总结以及项目经验(持续更新
走进微信小程序
ACL 2022 | 分解的元学习小样本命名实体识别
美国国家安全局(NSA)“酸狐狸”漏洞攻击武器平台技术分析报告
字节跳动数据平台技术揭秘:基于 ClickHouse 的复杂查询实现与优化
Judge whether a binary tree is a balanced binary tree
【splishsplash】关于如何在GUI和json上接收/显示用户参数、MVC模式和GenParam
【C语言补充】判断明天是哪一天(明天的日期)
中国一次性卫生用品生产设备行业深度调研报告(2022版)
Exclusive news: Alibaba cloud quietly launched RPA cloud computer and has opened cooperation with many RPA manufacturers
Iommu/smmuv3 code analysis (10) page table operation
6月刊 | AntDB数据库参与编写《数据库发展研究报告》 亮相信创产业榜单
mysql -- explain性能优化
How wild are hackers' ways of making money? CTF reverse entry Guide
Oom caused by improper use of multithreading
C language input / output stream and file operation
Shenyu gateway development: enable and run locally
ACM MM 2022视频理解挑战赛视频分类赛道冠军AutoX团队技术分享
In aks, use secret in CSI driver mount key vault
PHP实现敏感词过滤系统「建议收藏」