Is there a way to handle exceptions in testNG

0 votes
Suppose, I get error in a particular test case, if this happens the remaining test cases are not even checked. Is there a way to handle exception like try catch block in testNG?
Jan 3, 2019 in Selenium by Nitesh
• 3,080 points
3,504 views

2 answers to this question.

0 votes

Yes, like exception handling in java here also in testNG there is a method by which you can handle exceptions

package testNG;
import org.testng.annotations.Test;
public class Test {
    @Test
    public void testException() {
        System.out.println("Check the following");
        int i = 1 / 0;
    }
}

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="testNG">
<test name="Test">
<classes>
<class name="TestNGException" />
</classes>
</test>
</suite>
Output:

[TestNG] Running:

Check the following

===============================================
Default suite
Total tests run: 1, Failures: 1, Skips: 0
===============================================

You can see that there is a failed test case. Hope this helps 

answered Jan 3, 2019 by Nabarupa
0 votes
I don't think this should be a problem. If the test case fails, then the report will say this particular test case failed and others passed/ failed accordingly. It won't prevent others from executing. I'd advise you to check your issue once again.
answered Jan 4, 2019 by Vardhan
• 13,150 points

Related Questions In Selenium

0 votes
1 answer

Is there a way to pass on the options/ flags to Selenium if i'm scripting in Python?

This is the usage: from selenium import webdriver from ...READ MORE

answered Jun 8, 2018 in Selenium by king_kenny
• 3,710 points
4,998 views
0 votes
1 answer
0 votes
1 answer

Is there a way to get element by XPath using JavaScript in Selenium WebDriver?

You can use the document.evaluate: Evaluates an XPath ...READ MORE

answered Nov 27, 2020 in Selenium by Gitika
• 65,770 points
3,879 views
0 votes
2 answers

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,500 points
13,689 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
9,150 views
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,910 points
7,230 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
7,881 views
0 votes
1 answer
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP