1. Introduction to Jmeter
1. Lightweight testing tool
2. JDK must be installed when running
3. No installation required, the installation package can be used
after decompressing
2. Common operations of Jmeter Http request
Referring to the common operation example in the previous postman for beginners, make a script in Jmeter
1. How to create an http interface script
(1) Add thread group
(2) Add http request
(3) Write interface url, path, request method, parameters in http request
(4) Add view result tree
(5) Call interface and view return value
2. get request
The parameters of the get request are not directly spelled in the url, but written in Parameters.
3. post request
Fill in the parameters in Parameters.
4, post request, json input parameter
Fill in the json string into Body Data.
5. File upload
Select Files Upload to upload files, fill in the parameter name file to be consistent with the interface document, and select utf-8 as the encoding type to avoid garbled characters.
6. File download
Add an http request: right-click the thread group, add -Sampler-HTTP request Write
the url and path in the http request
Add beanshell, get the content of the returned file, and save it to a file. Right-click the thread group and add -Sampler-BeanShell Sampler
Beanshell is a download script. If you download it, one step is to save the file to our local. This jmeter has no ready-made things to use, so you have to write beanshell yourself to save the file to the local.
Of course, if you want to write beanshell, you have to know its syntax, which is written in java. But don't worry about not being able to write java. This save file is written in a dead format, just remember it, and copy it when you need to download it.
1 import java.io. *; 2 3 4 byte[] result = prev.getResponseData(); //This is to get the data returned by the request, prev is to get the return of the previous request 5 6 String file_name = "C:\\Users\\bjniuhanyang\\Desktop\\BaiDu.jpg"; //represents the location and file name of the file 7 8 File file = new File(file_name); 9 10 FileOutputStream out = new FileOutputStream(file); 11 12 out.write(result); 13 14 out.close();
View Results
7. Add header to http interface script
Right-click the http request, add a configuration element, select the HTTP header manager, and add a header.
8. Add cookies to the http interface script
Right-click the http request, add configuration element, select HTTP Cookie Manager, and add Cookier.
Three, Jmeter WebService request common operations
1. How to create a webservice script
You can search "Weather Forecast WebService" on Baidu to find the wsdl address of a weather forecast and make a simple contact
(1) Create a new soap project in soapui, import the wsdl address, and obtain the request message, SOAPAction and request url (which can be found in the raw of soapui)
(2) Open jmeter to create a new thread group
(3) Create a new SOAP/XML-RPC Request
(4) Write the url, soapaction and request message to soaprequest
(5) Call the interface and view the return value
2. If you import the wsdl file or the url reports an error
In the project test, if wsdl is introduced, the following error is reported:
Error loading [http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl]: org.apache.xmlbeans.XmlException: java.io.CharConversionException: Characters larger than 4 bytes are not supported: byte 0xb1 implies a length of more than 4 bytes
Solution: Close the program and find the SoapUI-4.6.4.vmoptions file in the installation location of SoapUI, and add it at the end
-Dfile.encoding=UTF8 resolves
Fourth, solve the problem of garbled characters in Jmeter
1. Use Jmeter to test, the returned result is garbled
solution:
In the installation directory /bin/jmeter.properties set sampleresult.default.encoding=ISO-8859-1
Change to sampleresult.default.encoding=utf-8
2. When Jmeter writes the post script, the Body Data is garbled when entering Chinese
This is not garbled, but the default font (Consolas) does not support Chinese character display due to the optimization of Body Data in version 3.0
solution:
Modify the default display font in the configuration file {JMETER_HOME}\bin\jmeter.properties #jsyntaxtextarea.font.family=Hack
Change to the Chinese font supported by the system (you can enter the system directory [Control Panel\All Control Panel Items\Fonts] to view).
jsyntaxtextarea.font.family=Arial