Looking for such a mechanism so that if any exception occurs while executing the test suite it should mark the corresponding test/method as failed.

Answered

Hi,

I am currently working on a project in which I have mainly created scripts for CRUD operations using Page Factory concepts with TestNG Reporting.

I have put the code for all the main test scripts under try…catch block to handle exceptions. After running the test suite I am able to successfully catch the exceptions in eclipse console. But the problem I am facing is “Results of running suite” (TestNG) tab in eclipse shows all the scrips as passed.

I am looking for such a mechanism so that if any exception occurs while executing the test suite it should mark the corresponding test/method as failed in TestNG report.

Please suggest.

sumitk Train Asked on April 9, 2015 in Selenium WebDriver.
Add Comment
5 Answer(s)
Best answer

In the <Message that you want to print> using printStackTrace.toString()

Virender Singh Professor Answered on April 10, 2015.
Add Comment

You have to use the org.testng.Assert class to put a failing assert in the catch block. If you want to do it the way you are trying to do it.

Yuo probably need to put Assert.assertTrue(false, <message that you want to print>);

Virender

Virender Singh Professor Answered on April 10, 2015.
Add Comment

Hi Virender,

Thanks for the answer. This will help.

sumitk Train Answered on April 10, 2015.
Add Comment

Hi Virender,

I tried this. Its working fine in case i want to print my own message like failure occurred in so and so module.
What if i want to print the printStackTrace() (exception error) itself using Assert.assertTrue(false, <message that you want to print>) instead of passing the user defined message to make it more accurate while checking the failure report?.

sumitk Train Answered on April 10, 2015.
Add Comment

Thanks Virender for promt response.

Sumit & Raj

sumitk Train Answered on April 10, 2015.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.