Showing posts with label test automation. Show all posts
Showing posts with label test automation. Show all posts

Tuesday, 30 June 2009

How to read e-mails through JMeter

To read e-mails JMeter uses Mail Reader Sampler. You have to place JavaMail and JAF jars in JMeter's classpath to use this sampler. If you plan to use downloaded e-mails in your tests you have to process them. Main problem is, that e-mails are treated as subsamples and many post processors cannot use them. Following code put in BeanShell PostProcessor processes all the messages got by Mail Reader Sampler:

subs = prev.getSubResults()
;

counter = 1;
for(SampleResult sub: subs) {
mail = sub.getResponseDataAsString();

// do something here with your the e-mail if you wish

// or put it into variable for further processing
vars.put("prefix_"+Integer.toString(counter),mail);
counter++;
}



If you put e-mail to variables prefix_# you can use ForEach Controller to process e-mail. For example you test plan may look as follows:
ForEach Controller should be configured as follows:
Remember to check Add "_" before number, because in the code there was underscore after ther prefix. And you can use ${mail} to access mail body or mail = vars.get("mail"); in BeanShell.

What I had to do was to extract URL from confirmation e-mail and pick up the process from where it has been interrupted. So, I have extracted urls in BeanShell Postprocessor and put them into variables rather than whole e-mail.

Happy testing.
Janek

Tuesday, 23 June 2009

Manifesto

I am beginning this blog to show anybody who works with JMeter how certain tasks can be achieved. I believe JMeter is great tools and constitutes good framework to build automated tests. JMeter is flexible and, what I value most, extendable. If you need something and there is no function doing it in JMeter you can extend it either by writing several lines of Java code in BeanShel sampler or building your own custom class and adding your jar to lib/ext directory.

I think some people may need solutions I have worked out for my testing projects, so I want to share them. If you need anything with JMeter, write it and I may be able to help you and we will share the solution with all JMeter users. If you have developed an interesting piece of code regarding JMeter, please share with us.

Janek