2

I'd like to connect gmail server before user thread group, and I wanna open inbox and check mail count in every user interaction.

  1. Connect gmail ones
  2. Check registration emails many times (100, 1000)
  3. Close gmail connection.

How can I do this?

My JMeter project as in picture

enter image description here

setUp is a BeanShell sampler

import javax.mail.internet.MimeMultipart;
import javax.mail.internet.MimeUtility;
import javax.mail.*;
import org.apache.commons.io.IOUtils;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Properties sessionProps = new Properties();
String sTo = "";
String token = "";

sessionProps.put("mail.store.protocol", "imaps");
Session session = Session.getDefaultInstance(sessionProps);
Store store = session.getStore("imaps");
store.connect("${mailHost}", "${mailUser}", "${mailPassword}");
log.info("Store: " + store);

vars.putObject("store", store);
${__setProperty("store1", store)}
props.set("store2", store)

log.info("Mailbox opened. - " + vars.getObject("store"));

tearDown is a BeanShell sampler

import javax.mail.internet.MimeMultipart;
import javax.mail.internet.MimeUtility;
import javax.mail.*;
import org.apache.commons.io.IOUtils;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Store store = vars.getObject("store");
store.close();

log.info("Mailbox closed.");

getValidationToken is a BeanShell sampler too

import javax.mail.internet.MimeMultipart;
import javax.mail.internet.MimeUtility;
import javax.mail.*;
import org.apache.commons.io.IOUtils;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Store store = vars.getObject("store");
// Strore store = props.get("store")
Folder inbox = store.getFolder("Inbox");
inbox.open(Folder.READ_ONLY);

int msgCount = inbox.getMessageCount();
log.info("Count: " + msgCount);

My problem is I wanna one store (connect ones to mailbox) like a JDBC Connection Configuration. After this in the userRegistration section

  1. Send a HTTP request with following body data:

    { "userId" : "${__P(registeredMail${__threadNum})}"}

  2. Read token from response mail generated/sent by back end what placed in the mailbox.

  3. Do next step with this token.

I don't know is it clear enough, but if you have any ideas how to do it, please share any details.

1 Answer 1

2

Be aware of the following constraints:

  1. Properties are not the same as variables. Variables are local to a thread; properties are common to all threads

    It means that you can use vars within the bounds of one Thread Group only and variables are thread-local (each JMeter thread - virtual user - has its own set of variables)

    Properties are global so if you do something like props.set("store2", store) with user1 and then the same code will be executed by user2 - the value will be overwritten so I would rather recommend adding current thread number as prefix/postfix like:

    props.put("store_" + ctx.getThreadNum(), vars.getObject("store"));
    
  2. Since JMeter 3.1 you should be using JSR223 Test Elements and Groovy language for scripting mainly for performance reasons, see Apache Groovy - Why and How You Should Use It article for comprehensive explanation

  3. As per JSR223 Sampler documentation you should not be inlining JMeter functions and variables into scripts, moreover it's not very safe as they may resolve into something causing compilation failure or unexpected behaviour.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.