当前位置:网站首页>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 .
边栏推荐
- Integer array merge [JS]
- Computed property “xxx“ was assigned to but it has no setter.
- There is a new breakthrough in quantum field: the duration of quantum state can exceed 5 seconds
- 【PyG】文档总结以及项目经验(持续更新
- vulnhub靶场-Hacker_Kid-v1.0.1
- [flask introduction series] cookies and session
- 【C语言补充】判断明天是哪一天(明天的日期)
- Official announcement! Hong Kong University of science and Technology (Guangzhou) approved!
- Openlayers 自定义气泡框以及定位到气泡框
- 在MeterSphere接口测试中如何使用JMeter函数和MockJS函数
猜你喜欢
Roewe rx5's "a little more" product strategy

Shenyu gateway development: enable and run locally

Borui data integrated intelligent observable platform was selected into the "Yunyuan production catalogue" of China Academy of communications in 2022

Vulnhub range hacker_ Kid-v1.0.1

ShenYu 网关开发:在本地启用运行

(1) CNN network structure

【牛客网刷题系列 之 Verilog快速入门】~ 优先编码器电路①

Iommu/smmuv3 code analysis (10) page table operation

为什么你要考虑使用Prisma

There is a new breakthrough in quantum field: the duration of quantum state can exceed 5 seconds
随机推荐
String的trim()和substring()详解
Research Report on development monitoring and investment prospects of China's smart environmental protection industry (2022 Edition)
Develop those things: easycvr cluster device management page function display optimization
SQL question brushing 586 Customers with the most orders
中国PBAT树脂市场预测及战略研究报告(2022版)
Pyqt5, draw a histogram on the control
Official announcement! Hong Kong University of science and Technology (Guangzhou) approved!
英特尔开源深度学习工具库 OpenVINO,将加大与本土软硬件方合作,持续开放
Research Report on development prediction and investment direction of nylon filament sewing thread in China (2022 Edition)
Research Report on China's enzyme Market Forecast and investment strategy (2022 Edition)
(1) CNN network structure
DNS
SQL question brushing 584 Looking for user references
Judge whether the binary tree is a binary search tree
redis -- 数据类型及操作
Encryption and decryption of tinyurl in leetcode
DNS
Redis distributed lock
(16) ADC conversion experiment
中国茂金属聚乙烯(mPE)行业研究报告(2022版)