Jmeter performs http interface testing, this article will do it!

jmeter-http interface test script

The main steps for jmeter to perform http interface testing (1. Add thread group 2. Add http request 3. Write the URL, path, request method, and parameters of the interface in the http request 4. Add the view result tree 5. Call the interface and view the return value)

Add headers to the interface in the following ways:

Jmeter does http interface testing to add cookies:

现在我也找了很多测试的朋友,做了一个分享技术的交流群,共享了很多我们收集的技术文档和视频教程。
如果你不想再体验自学时找不到资源,没人解答问题,坚持几天便放弃的感受
可以加入我们一起交流。而且还有很多在自动化,性能,安全,测试开发等等方面有一定建树的技术大牛
分享他们的经验,还会分享很多直播讲座和技术沙龙
可以免费学习!划重点!开源的!!!
qq群号:110685036

3. General steps for webservice testing using jmeter-webservice script

1. Create a new soap project in soapui, import the wsdl address, and obtain the request message, SOAPAction and request url (can be found in the raw of soapui) 2. Open jmeter to create a new
thread group
3. Create a new SOAP/XML-RPC Request4. Write the URL, soapaction and request message into soaprequest. 5. Call the interface and check the return value)

4.jmeter-parameterization

The role of parameterization: when calling the interface to enter parameters. Sometimes parameters are required to change frequently, and it would be cumbersome to modify them every time. At this time, you need to change the frequently changing values ​​into documents or functions that have been edited in advance, so that different values ​​can be used when calling.

There are three ways to parameterize Jmeter: 1) User-defined variables (this is for the convenience of parameter management and can only have one value, for example, the IP address does not change frequently). Just add a user-defined variable to the thread group, and then write the key and value. The key is the name of the parameter, which is the value you take in the script, and the value is the specific value. When getting a parameterized value, use ${name} to get the value, name is the variable name you took.

Get parameterized values ​​in script

2) Function generator (the function generator can generate data according to certain rules, such as generating some random numbers). For function assistants, you can generate some parameters according to rules, such as taking the current time as a random number. These two are the most commonly used.

Random number __Random can take a random value within a range you specify and take the current time __time. It can be used if there are some situations where time needs to be transmitted. The date format is: yyyy-MM-dd HH:mm:ss year -Month-Day-Hour: Minutes: Seconds Get the unique id, __UUID. This means that a random uuid will be generated every time, which is unique. Use function assistants to generate some parameters according to rules.

3) Reading from the file (reading the file means writing some data in advance and then reading it from the file. In this case, for example, the login interface, account number and password are all registered by us in advance)

There are three steps to reading from a file: 1. Read the file 2. Get the parameters in the file content and give it a name 3. Use the value (if reading from the file, you need to add a CSV Data Set in the thread group Config, it does the first two steps).

5.jmeter Assertion The function of assertion is to check whether the return result is correct. If it is correct, it means that the return value of this request is correct. If not, it means that the result of this request is inconsistent with what we expected. In this way, we can pass the assertion To check the returned results and see if the test passes.

6. The function of jmeter association is that the result returned by the previous server needs to be used in subsequent operations, so the value is saved and passed for use.

The association in Jmeter is usually done through the regular expression extractor (if there is a special jar package, it can also be done)

When the associated value is referenced by other requests, just use ${name} directly. Name is the variable name you set when you associated it.

7. Steps for jmeter to operate the database and mysql to operate the database: 1. Import the jdbc jar package. Because jmeter itself cannot directly connect to mysql, you need to import a third-party jar package to connect to mysql. 2. Create database connection configuration, mysql url, port number, account number, password 3. Write sql, execute sql 4. View the results

Jmeter imports jdbcjar package

Configure mysql connection

(1) Add a JDBC Connection Configuration (2) Configure the name of the mysql connection pool, and specify where to connect when sending SQL requests later (3) Database url: jdbc:mysql://192.168.1.116:3307/bugfree?allowMultiQueries= true (4) Database driver: here is to specify what type of database to connect to, mysql, oracle, SqlServer, etc. (5) Account password Jmeter executes sql

View sql results

8. Running jmeter stress test under Linux When we are doing tests, sometimes it takes a long time to run. The test servers used by the company are generally Linux, so they can be run under Linux. Linux cannot have a graphical interface like Windows, so How to run the script? Just complete the script on Windows first, and then run it under Linux. To run jmeter under Linux, you need to use the jmeter.sh shell script in the bin directory of jmeter.

sh jmeter.sh -n –t a.jmx -l res.jtl-n means starting without a graphical interface, -t means following the test script, a.jmx is the jmeter script we have prepared, and -l means testing The result res.jtl is the test result file. To view the results, import this res.jtl in the result tree view to view the test results. 9. Adding a load machine to jmeter When we are doing the stress test, the concurrency may be relatively large. One machine can no longer start so much concurrency. At this time, we have to use multiple machines to send pressure together. We need to add a press. How to add a press? First, we need to start the jmeter agent on the machine that is used to make the press. , and then add the IP of the press to the machine used as the control machine.

There is a jmeter-server in the bin directory of Jmeter. Just start it. If the Windows machine is used as a press, run jmeter-sever.bat. If Linux is used as a press, run jmeter-server.

Then add the press IP in the jmeter configuration file as the control machine. The jmeter configuration file is in jmeter.properties in the bin directory. When adding the press, find remote_hosts in the configuration file and add the IP, and then restart jmeter to see To the remote press

Add a press to jmeter: 1. First start jmeter-server (jmeter-server.bat windows) (jmeter-server.sh mac, linux) main control machine and load machine on other load machines (another computer)

2. Modify the configuration file of the main control machine jmeter, find remot_hosts, and then add the IP of the load machine to it. remot_hosts=127.0.0.1,192.168.1.2:1099,192.168.1.3:1099 is the default port number of jmeter-server. It is 1099. If the port number on the load machine is changed, then you have to change it here too.

3. When starting up, you must choose to run ps remotely: if there is a parameterized file, then there must also be a parameterized file at the same location on the load machine.


Finally, I would like to thank everyone who read my article carefully. Looking at the increase in fans and attention, there is always some courtesy. Although it is not a very valuable thing, if you can use it, you can take it directly!

Software Testing Interview Document

We must study to find a high-paying job. The following interview questions are from the latest interview materials from first-tier Internet companies such as Alibaba, Tencent, Byte, etc., and some Byte bosses have given authoritative answers. After finishing this set I believe everyone can find a satisfactory job based on the interview information.
 

Insert image description here

 

Guess you like

Origin blog.csdn.net/IT_LanTian/article/details/132835339