I have written a test plan in Jmeter using the mail reader sampler to test an IMAPS server. The test only allows me to either read all mails from a folder or read x number of mails from the folder. Optionally I can delete the mails from the server after they are read.
However there seem to be no options to do other operations like:
- Read a particular email only identified by some mail identifier
- move mails between folders
- copy mails to another folder
- mark mails are read/unread
- delete mails from trash explicitly
etc.
Is there a way in which these other scenarios can also be tested using some addon sampler or plugin?
If JMeter does not support this, kindly suggest any other performance testing tool using which this kind of testing can be done
Unfortunately JMeter Mail Reader Sampler doesn't allow advanced operations. However JMeter can be extended by scripting.
So you can implement all required methods using Java Mail API and one of scripting samplers provided:
- Beanshell Sampler
- JSR223 Sampler
Refer to example below for deleting all messages from "Spam" folder using IMAP for Gmail:
import com.sun.mail.imap.IMAPSSLStore;
import javax.mail. *;
try {
Properties properties = props;
properties.put("mail.smtps.auth", "true");
properties.put("mail.imap.ssl.enable", "true");
Session imapsession = Session.getInstance(properties, null);
imapsession.setDebug(false);
Store imapstore = new IMAPSSLStore(imapsession, new URLName("imaps", "imap.gmail.com", 993, "", "your.account@gmail.com", "password"));
imapstore.connect();
Folder rootfolder = imapstore.getDefaultFolder();
Folder[] imapfolders = rootfolder.list("*");
for (Folder folder : imapfolders) {
if (folder.getName().equals("Spam")) {
folder.open(Folder.READ_WRITE);
log.info("Spam folder contains " + folder.getMessageCount() + " messages");
Message[] messages = folder.getMessages();
for (Message message : messages) {
message.setFlag(Flags.Flag.DELETED, true);
log.info("Marking message with subject: " + message.getSubject() + " for deletion");
}
folder.expunge();
folder.close(true);
}
}
imapstore.close();
} catch (Exception ex) {
log.error("IMAP operation failed", ex);
}
Beanshell Sampler doesn't require any extra configuration, you can just copy and paste the code above.
However Beanshell has well known performance issues and limitations so if your test assumes more or less high load it's recommended to use JSR223 Sampler and Groovy language.
See Beanshell vs JSR223 vs Java JMeter Scripting: The Performance-Off You've Been Waiting For! scripting engines comparison benchmark for more information and installation instructions for Groovy scripting engine.