Friday, October 28, 2011

Selenium test report as mail attachment

Consider a situation where an user wants to mail the reports after all the automation tests have been done. Maven has provided with a plugin maven-postman-plugin.  It is available in the maven repo.

<plugin>
        <groupId>ch.fortysix</groupId>
        <artifactId>maven-postman-plugin</artifactId>
        <configuration>
            <mailhost>smtp.gmail.com</mailhost>
            <mailport>465</mailport>
            <mailssl>true</mailssl>
            <mailAltConfig>true</mailAltConfig>
            <mailuser>xxxx@gmail.com</mailuser>
            <mailpassword>xxxxxxx</mailpassword>
            <from>your_gmail_emailer_account@gmail.com</from>
            <receivers>
                <receiver>receipient@domain.com</receiver>
            </receivers>

            <subject>Important subject</subject>
            <failonerror>true</failonerror>
            <htmlMessage>
                    <![CDATA[
                    <p>Hi,</p>
                    <p>Check out the attached report.</p>
                    ]]>
            </htmlMessage>
            <fileSets>
                <fileSet>
                    <directory>${basedir}/${tests}</directory>
                    <includes>
                        <include>**/emailable-report.html</include>
                    </includes>
                </fileSet>
            </fileSets>
        </configuration>
    </plugin>

The above configuration will send the emailable-report.html as an attachment to all the recipients. If can be configured to send mail at any phase of maven. The following command is used to send mail after the test phase mvn test postman:send-mail.

Will send the mail after the test phase.

4 comments:

  1. Excellent Its really useful for me .... Thanks for Post.

    ReplyDelete
  2. hi Am not able to email the reports.

    am using maven+testng the same code am using

    ReplyDelete
  3. Hi,

    I'm using maven+testng in eclipse. Emailable report is being generated,but email is not being sent. I've added this plugin to my PM.xml file in eclipse.
    FYI,I'm using appium for automation.

    Please let me know what might be the possible causes for this problem and suggestions to resolve this issue.

    ReplyDelete
  4. Hi,
    I am trying to do the same but I keep getting this exception: com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 No AUTH command has been given.
    I am able to connect to the smtp server but the Send fails. I am giving the username and password of my smtp account as well, just as above. This is the smtp server of my company account.
    Any idea how can this be resolved?

    ReplyDelete