Step on the URL that comes to GMail with Jmeter at random. I'm making a tool called. I don't understand the behavior of MailReaderSampler ... imap doesn't work as referenced. pop3 is connected. But how do you extract the text? Something like that. In particular,
I'm nested like this, and I don't know how to take this text by post-processing regular expression extraction. (I don't know how to focus on the first result in the bottom layer)
After all, I used to make my own sampler, so make your own sampler. In that.
I forgot how to make my own sampler, so I wrote an article anyway.
apache-jmeter : 5.2.1 JRE : 1.8
DemoSampler.java
package jmeter.extend.sampler;
import org.apache.jmeter.config.Arguments;
import org.apache.jmeter.protocol.java.sampler.AbstractJavaSamplerClient;
import org.apache.jmeter.protocol.java.sampler.JavaSamplerContext;
import org.apache.jmeter.samplers.SampleResult;
public class DemoSampler extends AbstractJavaSamplerClient {
//Define parameter keys
private static final String MAIL_ADDRESS = "mailAddress";
private static final String PASSWORD = "password";
/* (non-Javadoc)
*Set default parameters
*/
@Override
public Arguments getDefaultParameters() {
//Setting default parameters
Arguments defaultParameters = new Arguments();
defaultParameters.addArgument(MAIL_ADDRESS, "[email protected]");
defaultParameters.addArgument(PASSWORD, "input your password");
return defaultParameters;
}
@Override
public SampleResult runTest(JavaSamplerContext context) {
SampleResult result = new SampleResult();
try {
//Get the parameters entered in JMeter
String mail = context.getParameter(MAIL_ADDRESS);
String password = context.getParameter(PASSWORD);
//Start time measurement(1)
result.sampleStart();
//Arbitrary processing you want to measure
Thread.sleep(500);
StringBuilder bulder = new StringBuilder();
bulder.append("this is ResponseData\n");
bulder.append("mail : ").append(mail).append("\n");
bulder.append("password : ").append(password).append("\n");
bulder.append("Japanese string character string\n");
bulder.append("URL : https://github.com/");
//Time measurement finished(2)
// (2) - (1)Time can be obtained as the response time of JMeter
result.sampleEnd();
//Successful acquisition of JMeter
result.setSuccessful(true);
//OK JMeter's response code(200)Set to
result.setResponseCodeOK();
result.setRequestHeaders("this is RequestHeaders");
result.setResponseData(bulder.toString(), "utf-8");
//This guy doesn't seem to appear anywhere
result.setResponseMessage("this is ResponseMessage");
} catch (Exception e) {
//Time measurement finished(2)
// (2) - (1)Time can be obtained as the response time of JMeter
result.sampleEnd();
//JMeter acquisition result fails
result.setSuccessful(false);
//OK JMeter's response code(200)Set to a number other than
result.setResponseCode("500");
//Fill in the contents of the response data displayed in JMeter
result.setResponseMessage("Error!! " + e.getMessage());
}
return result;
}
}
All the required libraries are under bin in jmeter.
Make the above package into a jar with the export function of Eclipse etc. Just place it under libs / ext of jmeter and restart jmeter. If your code depends on a jar other than the one that comes with jmeterlib from the beginning, Place that jar in the same folder as well.
Use Java requests. Classes that inherit AbstractJavaSamplerClient are listed in the list of class names.
The character specified in result.setResponseData is displayed in ResponseBody.
https://qiita.com/kiida/items/6af3e46e5bae14c38242 It's almost a round pakuri for reference. I'm sorry.
You can get it normally from MailReaderSampler! Please let me know if you have any questions.
Recommended Posts