Robotically Send Test Reports via Mail Using Maven Postman Plugin - Perficient Blogs
Blog
  • Topics
  • Industries
  • Partners

Explore

Topics

Industries

Partners

Robotically Send Test Reports via Mail Using Maven Postman Plugin

 

As Test Engineers, we all know the importance of report generation which contains the summary of test script results. Test Reports give you the overall update on the application’s stability and it also helps to figure out the application issues which in turn could be useful for the developer to fix them. It would be great if reports were generated and sent automatically to the team members and managers on each test build run so issues would be called to everybody’s attention immediately.

In this blog you will see how to send the cucumber test reports automatically through mail using the Maven Postman Plugin after each test build run.

Steps to automate cucumber test reports through mail

  • Open Eclipse IDE and Create a new Maven Project: File -> New -> Maven ProjectSteps to automate cucumber test reports through mail
  • Add the Maven Dependencies required for the Cucumber framework in the POM.xml file
        <dependencies>
            <dependency>
              <groupId>info.cukes</groupId>
              <artifactId>cucumber-java</artifactId>
              <version>1.2.2</version>
              <scope>test</scope>
            </dependency>
            <dependency>  
              <groupId>info.cukes</groupId>
              <artifactId>cucumber-junit</artifactId>
              <version>1.2.2</version>
              <scope>test</scope> 
            </dependency>
            <dependency>
              <groupId>org.seleniumhq.selenium</groupId>
              <artifactId>selenium-java</artifactId>
              <version>2.45.0</version>
            </dependency>
            <dependency>
              <groupId>io.github.bonigarcia</groupId>
              <artifactId>webdrivermanager</artifactId>\
              <version>1.6.0</version>
            </dependency>
            <dependency>
              <groupId>info.cukes</groupId>
              <artifactId>cucumber-testng</artifactId>
              <version>1.2.2</version>
            </dependency>
            <dependency>
              <groupId>org.testng</groupId>
              <artifactId>testng</artifactId>
              <version>6.9.9</version>
            </dependency>
            <dependency>
              <groupId>com.github.mkolisnyk</groupId>
              <artifactId>cucumber-reports</artifactId>
              <version>0.0.5</version>
            </dependency>
          </dependencies>
  • Create the Cucumber feature file, Step Definitions and Runner class filesCreate the Cucumber feature file, Step Definitions and Runner class files Create the Cucumber feature file, Step Definitions and Runner class filesCreate the Cucumber feature file, Step Definitions and Runner class filesCreate the Cucumber feature file, Step Definitions and Runner class filesCreate the Cucumber feature file, Step Definitions and Runner class files
  • Create the TestNG xml for the project: Right Click on the Project and select TestNG -> Convert to TestNG and add the runner class package name then save the TestNG xml file.Create the TestNG xml for the project
  • Add the Maven Surefire Plugin in the POM.xml file and also make sure you add the testng.xml file location inside                          SuiteXmlFiles tag then save the POM file.
     <build>
       <!-- Suirefire plugin -->
         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.17</version>
            <configuration>
                <suiteXmlFiles>
                       <!-- TestNG suite XML files -->
                       <suiteXmlFile>./testng.xml</suiteXmlFile>
                </suiteXmlFiles>
                <testFailureIgnore>true</testFailureIgnore>
           </configuration>
         </plugin>
     </build>
  • Right click POM.xml and Select Run As -> Maven Test Option then check whether all the test cases are executed in the project and test report “cucumber-test-result.html” is generated in the target folder
  • Our aim is to send the test report mail robotically on every test build run. To achieve this we use the plugin called Maven Postman Plugin in Maven. This helps to send mail once after every test build run. To enable the plugin action, we need to add the below plugin dependency in the POM.xml file and save it
       <<!-- Post-Man plugin -->
         <plugin>
            <groupId>ch.fortysix</groupId>
            <artifactId>maven-postman-plugin</artifactId>
            <version>0.1.6</version>
                <executions>
                   <execution>
                       <id>Report Generation</id>
                       <phase>test</phase>
                       <goals>
                           <goal>send-mail</goal>
                       </goals>
                       <inherited>true</inherited>
                       <configuration>
                          <!-- From Email address -->
                          <from>samplemail@yahoo.com</from>
                          <!-- Email subject -->
                          <subject>Cucumber Test Automation Report</subject>
                          <!-- Fail the build if the mail doesn't reach -->
                          <failonerror>false</failonerror>
                          <!-- Email Body Content -->
                          <htmlMessage>
                                    <![CDATA[
                                    <p>New test build triggered!</p>
                                    <p>Attached html file contains the test result status</p> 
                                    ]]>
                          </htmlMessage>
                          <!-- host -->
                          <mailhost>smtp.mail.yahoo.com</mailhost>
                          <!-- port of the host -->
                          <mailport>465</mailport>
                          <mailssl>true</mailssl>
                          <mailAltConfig>true</mailAltConfig>
                          <!-- Email Authentication(Username and Password) -->
                          <mailuser>samplemail@yahoo.com</mailuser>
                          <mailpassword>youraccountpassword</mailpassword>
                          <receivers>
                               <!-- To Email address -->
                               <receiver>sampleuser1@perficient.com</receiver>
                               <receiver>sampleuser2@perficient.com</receiver>
                          </receivers>
                          <fileSets>
                             <fileSet>
                                  <!-- Report directory Path -->
                                  <directory>${basedir}/target</directory>
                                       <includes>
                                          <!-- Report file name -->
                                          <include>cucumber-test-results.html</include>
                                       </includes>
                             </fileSet>
                          </fileSets>
                       </configuration>
                   </execution>
                </executions>
         </plugin>
  • Right click POM.xml and select the Run as -> Maven Test option. It will execute all the test cases and the test report mail will be sent to all the receiver mail ids that are listed under the receiver tag in Maven dependencyRobotically Send Test Reports via Mail Using Maven Postman PluginRobotically Send Test Reports via Mail Using Maven Postman Plugin

You can download and refer to this sample project from GitHub.

https://github.com/Harini-Gnanasekaran/Cucumber_MailTestReports.git

 

 

One thought on “Robotically Send Test Reports via Mail Using Maven Postman Plugin

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Subscribe to the Weekly Blog Digest:

Sign Up

Categories