Jmeter Series Advanced-Get Image Verification Code (4)

Installation tools

Use the ocrserver tool to identify the image verification code. After decompression, double-click the .exe to start it.

Used in jmeter

(1) HTTP request to obtain the verification code
Insert image description here
(2) Add a listener under the interface for obtaining the verification code image and save the response to a file; as shown below:
Insert image description here

(3) Add JSR223 Sampler to the sampler; note that the sampler converts images into base64 format; and write code;
Insert image description here

SampleResult.setIgnore();
import java.io.*;
import org.apache.commons.codec.binary.Base64;
String image=vars.get("png");
byte[] data = null;
try {
    
    
    InputStream in = new FileInputStream(image);
    data = new byte[in.available()];
    in.read(data);
    in.close();
} catch (IOException e) {
    
    
    e.printStackTrace();
}
Base64 base64=new Base64();
vars.put("base64",base64.encodeToString(data));
//return image;

(4) Add an HTTP request to call the OcrServer tool, the IP address is 127.0.0.1, the port is 12349, post request, reference base64 in the body; (5) Add a json extractor under the verification code recognition
Insert image description here
request ; Extract the fields of the recognized image verification code; as shown below: The fields of the recognized image verification code are in json format; extract the value of the
Insert image description here
code through the jsonpath method in the json extractor
Insert image description here
(6) Verify whether the extracted fields are verified with the image The fields on the code are consistent;
Insert image description here
(8) Through step 7, you can see that the verification code field is correctly extracted, and then call image_code on the login interface;
Insert image description here
Insert image description here

Guess you like

Origin blog.csdn.net/m0_62091240/article/details/132756993