I am trying to send an email after executing the test cases with an attachment of testng generated emailable-report.html file ,But I am resulting in error.
please find the stack trace here and do needful
javax.mail.MessagingException: IOException while sending message;nested exception is:
java.io.FileNotFoundException: D:\test-output (Access is denied)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:421)
at hb.util.SendMail.sendMail(SendMail.java:148)
at hb.util.SendMail.execute(SendMail.java:29)
at hb.listeners.CustomListener.onTestFailure(CustomListener.java:41)
at org.testng.internal.Invoker.runTestListeners(Invoker.java:1895)
at org.testng.internal.Invoker.runTestListeners(Invoker.java:1879)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:778)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
at org.testng.TestRunner.privateRun(TestRunner.java:767)
at org.testng.TestRunner.run(TestRunner.java:617)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
at org.testng.TestNG.run(TestNG.java:1057)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
Thanks in Advance
-
Are you sending the mail in your after suite method...Vicky– Vicky2015年07月15日 06:07:03 +00:00Commented Jul 15, 2015 at 6:07
-
Yes I am trying to do thatQAMember– QAMember2015年07月15日 06:16:07 +00:00Commented Jul 15, 2015 at 6:16
-
Hello Vicky, I resolved the issue ,but it was sending the previous execution report (emailable-report.html) file instead of current execution report . Can you please help me in thisQAMember– QAMember2015年07月15日 06:26:49 +00:00Commented Jul 15, 2015 at 6:26
1 Answer 1
As you're sending emailable-reports while your test is running you're getting FileNotFoundException
.Reports get generated only after test execution.
EDIT : If you're sending your emailable reports for the test which has already been executed then you will get previous test report as the current test is still running.
I have explained about the solution to this problem in this Post
I want to send a mail when ever the test case is failed. So I am trying to attach the emailable-report.html file because it's having all the data. so I am trying attach that
You can send the mail with the error which occurred but you cannot attach the report in the mail as the test is still executing
//This method will automatically be called if a test fails
public void onTestFailure(ITestResult result) {
//returns the test which failed
result.getMethod().getMethodName());
//create an object of the send mail class and call the method which send the mail and pass the test name which failed as an argument to it.
}
If you want to attach reports then you have to set it as a post build option either using jenkins
or tools like maven,ant
.Or the other option is to generate your own custom report from the test results which you have got from methods onTestSuccess
(passed tests),onTestFailure
(failed tests),onTestSkipped
(skipped tests)
Hope this helps you...Kindly get back if you have any doubts
-
Hello Vicky Thanks for your reply and answer. I am using the CustomListenter by implementing ITestListener in that onTestFailure() , i was implemented the logic to send an email.Because I want to send an email if test case was failedQAMember– QAMember2015年07月15日 06:55:21 +00:00Commented Jul 15, 2015 at 6:55
-
Hi @QAMember I can't understand your question...Do you want to send mail only on Testfailure and you don't want to attach email-able reportVicky– Vicky2015年07月15日 07:36:47 +00:00Commented Jul 15, 2015 at 7:36
-
Hello Vicky, I want to send a mail when ever the test case is failed. So I am trying to attach the emailable-report.html file because it's having all the data. so I am trying attach thatQAMember– QAMember2015年07月15日 07:57:26 +00:00Commented Jul 15, 2015 at 7:57
-
@QAMember you cannot attach the email report on your 'onTestFailure' method as test is still executing and report has not been generated...pls refer my above editVicky– Vicky2015年07月15日 09:06:04 +00:00Commented Jul 15, 2015 at 9:06
-
Thank you @Vicky,That I have understood by your post.Actually I don't require that html report but I want to show some information about why the test case has been failed .so that I have choose html report.QAMember– QAMember2015年07月15日 10:10:02 +00:00Commented Jul 15, 2015 at 10:10
Explore related questions
See similar questions with these tags.