Reputation: 11
I have incorporated a simple HTTP Request sampler in a test plan. And, viewing the result through "View Result Tree" and writing the same results to a file. I want this file to send through mail Sampler.
Issue is, once I execute the test-case, it sends mail first and then append new test results to the file. So, in mail I got the previous run results instead of the new one.
How can I incorporate this?
Upvotes: 1
Views: 5652
Reputation: 760
Reference Article - Send JMeter Test Reports Automatically in Email
If you use 'View Results Tree' or 'Summary Report' Listeners, you won't be able to send the current report, through mail via SMTP Sampler, even if you use tearDown Thread Group.
Reason : JMeter writes the data to these report files, only after the test is finished completely.
You can verify this by adding a tearDown Thread Group and adding a delay before running the SMTP Sampler. Keep an eye on the file size, it is created once the test is started, but data is written when the last thread (SMTP Sampler, in this case) is finished execution.
Hence, only an empty file would be attached with your email.
Solution - 1. Find and modify (or add, if not present) the following section in the 'user.properties' file, setting the autoflush parameter to true:
# AutoFlush on each line written in XML or CSV output
# Setting this to true will result in less test results data loss in case of Crash
# but with impact on performances, particularly for intensive tests (low or no pauses)
# Since JMeter 2.10, this is false by default
jmeter.save.saveservice.autoflush=true
Problem with this approach is, there is a dependency on another utility. Also, we would require to write different scripts for different platforms (Windows/Linux).
In this case, what we need is a 'Flexible File Writer' Plugin. It provides you powerful customization to configure what data you want to write to your report file, and also it would allow you to include complete report file to be sent via SMTP Sampler.
I was able to achieve this using Flexible File Writer Listener, and tearDown Thread Group. Here is the structure of my Test Plan -
Test Plan
--- Thread Group
-------Sampler
-------jp@gc- Flexible Filw Writer
---tearDown Thread Group
------SMTP Sampler
Here is a snapshot of my File Writer Plugin's configuration :
You may want to add some delay before sending the mail from tearDown Thread Group.
You can download the Flexible File Writer plugin using in-built Jmeter's Plugin Manager, or from JMeter Plugins Site - jp@gc Flexible File Writer Plugin
Upvotes: 3
Reputation: 89
I observe that JMeter first sends the Email with either blank or old run report when doing it using the SMTP Sampler. To overvome it, this is what I tried:
call jmeter -n -t "script path" -l "JTL report path"
sendEmail -f Sender_Email -t Receiver_Email -cc CC_Email -s Mail_Server -u "Subject" -m "Email body" -a "Path of JTL Report attachment"
What it is doing that it executes the JMeter script, generate the report in path specified in first step and then send Email with the report using step 2.
It might help.
Upvotes: 2
Reputation: 167992
I would suggest sending your email in tearDown Thread Group which is designed for post processing purposes and seems to be exactly what you're looking for.
Also make sure that you wait for reasonable amount of time via Test Action sampler as JMeter doesn't update results file on the fly, it periodically flushes chunks of results.
If you don't want "old" data you can use setUp Thread Group with i.e. OS Process Sampler to delete old results file or move it somewhere else.
For more JMeter email tips and tricks see Load Testing Your Email Server: How to Send and Receive E-mails with JMeter
Upvotes: 1