Recently encountered a project, the interface has the need to upload pictures of the field, it is in the form of Image Base64 encoded format passed. (Base64 is currently used primarily for HTML5, mobile development and other scenarios where IE6 is not considered.) Sample request messages are as follows:
Questions about how to test the implementation:
1) How do I encode a picture?
2) How to implement automatic Base64 coding for Interface Automation testing
Solution:
Method 1: Use the image to encode the online transcoding base64 website.
Encoded website: http://tool.css-js.com/base64.html
Upload a local image, tick as needed: "Include header" and other options, generate Image base64 encoding.
Disadvantage: When testing different pictures, it is necessary to manually encode, and then copy the code into the interface request message, can not realize automation, test efficiency is low.
Method 2: Use JMeter's BeanShell to write a picture Base64 encoded conversion code
1) write picture base64 Coding code
In general, the development will provide the code; if not, do not be afraid, Baidu can, or have code skills of students can write their own. Some of the code is as follows:
2) Build the jar package and place it in the ${jmeter_home}\lib\ext directory
3) Write BeanShell, call encoding method to encode
4) Parameterized Request message
Actual Request message:
This method solves the problem of manual image base64 coding, and provides support for the subsequent automated testing.
Extension: If the upload image is not in Base64 encoded format, that is, as a picture file to send the request message, how to deal with it?
Solution: Take advantage of the "Send files with Request" feature in JMeter's sampler
A, click on the "Send files together with the request" column of the Add button;
b, click the Browse button, select a need to upload the image, the address will be automatically recorded in the File Name column;
C, fill in the parameter name, here is "image";
D, MIME type is Multipart/form-data
(Note: Another setting is > in order to upload files, you must also tick "use Multipart/form-data for POST", then MIME type can be filled out according to the actual situation, otherwise the request will not contain the uploaded file. )
Save the HTTP request, execute, view the server, and discover that the image selected in the previous steps has been successfully uploaded to the server. For picture parameterization, simply parameterize the path of the image.
JMeter Test upload Image Base64 encoding interface