2
votes

I have created java method to send mail and that mail attaching TestNG emailable-report. Mail and report is sending fine to specified email address.

My issue is I am calling sendmail method at last means when all other tests complete but thing is I am always getting previous last report in mail. So is it like TestNG update report after all class execution?

I want to get latest emailable-report in mail rather than previous last emailable-report.. How can I do that?

2

2 Answers

4
votes

I want to get latest emailable-report in mail rather than previous last emailable-report.. How can I do that?

I think..you're sending mail in your @aftersuite.You're getting previous test emailable-report because the test is currently running and only when it finishes reports will be generated.

I will suggest you to use a continuous Integration server like jenkins because it gives sending emails as a post build option or build tool like Maven or ant to run your tests, then have a post test event to email the results.Maven also provides many plugins to automatically send mails after test execution like Postman mail plugin

Another solution : If you are not willing to use a continuous Integration server(jenkins) or maven or ant

TestNG IReporter listener

Create your own CustomReport by implementing your class to IReporter Interface.This interface has only one method to implement generateReport. This method has all the information of a complete test execution in the List and we can generate report using it.

public class CustomReporter implements IReporter{

        @Override

        public void generateReport(List<XmlSuite> arg0, List<ISuite> arg1,

                String outputDirectory) {

            // Second parameter of this method ISuite will contain all the suite executed.

            for (ISuite iSuite : arg1) {

             //Get a map of result of a single suite at a time

                Map<String,ISuiteResult> results =    iSuite.getResults();

             //Get the key of the result map

                Set<String> keys = results.keySet();

            //Go to each map value one by one

                for (String key : keys) {

                 //The Context object of current result

                ITestContext context = results.get(key).getTestContext();

            //results of all the test case will be stored in the context object

            //Ex: context.getFailedTests(); will give all failed tests and similarly you can get passed and skipped test results make your own html report using the above data 
    }
    }
    }
    }

Hope this helps you...Kindly get back if you need any further help

0
votes

For Windows OS, I've created (for TestNG) in @AfterSuite at the end a method to send mail with attachment and batch file with 2 steps. First step launch mvn clean test to execute all test without previous results. Second step launch test without parameter clean and operates on non existing group :) Batch is in folder with tests.

start /wait cmd /k "mvn clean test && exit"  /secondary /minimized
REM to send email with results in file, whitch was composed after test suite (mvn without: clean)
start /wait cmd /k "mvn test -Dgroups=PhantomGroupNonExist && exit" /secondary /minimized