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 in Selenium by Nitesh
• 2,810 points

2 answers to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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 {
    public void testException() {
        System.out.println("Check the following");
        int i = 1 / 0;

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "">
<suite name="testNG">
<test name="Test">
<class name="TestNGException" />

[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 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 by Vardhan
• 10,560 points

Related Questions In Selenium

0 votes
1 answer
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,590 points
0 votes
1 answer
0 votes
2 answers

Is it possible to scroll down in a webpage using selenium webdriver programmed on python?

I using next code for facebook for ...READ MORE

answered 4 days ago in Selenium by
0 votes
1 answer

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,030 points
0 votes
1 answer
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,130 points
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.