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
(2) Add a listener under the interface for obtaining the verification code image and save the response to a file; as shown below:
(3) Add JSR223 Sampler to the sampler; note that the sampler converts images into base64 format; and write code;
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
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
code through the jsonpath method in the json extractor
(6) Verify whether the extracted fields are verified with the image The fields on the code are consistent;
(8) Through step 7, you can see that the verification code field is correctly extracted, and then call image_code on the login interface;