What is exception test in testng

0 votes
Jun 19, 2019 in Selenium by Zubin
1,502 views

1 answer to this question.

0 votes

@Zubin, TestNG gives an option for tracing the Exception handling of code by using Exception test. You can verify whether a code throws the expected exception or not. The expected exception to validate while running the test case is mentioned using the expectedExceptions attribute value along with @Test annotation:

package expectedExceptionPackage;
import org.testng.annotations.Test;
public class TestNGException {
 @Test(expectedExceptions = ArithmeticException.class)
public void testException() {
  System.out.println("Facebook.com");
  int i = 1 / 0;
}
}

Now, the testng.xml file for test case is:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="expectedException">
<test name="testngTest">
  <classes>
   <class name="expectedException.TestNGException" />
  </classes>
</test>
</suite>
answered Jun 19, 2019 by Anvi
• 14,150 points

Related Questions In Selenium

0 votes
2 answers

What is the role of TestNG & JUnit frameworks in Selenium?

TestNG and JUnit are test frameworks . it ...READ MORE

answered Sep 4, 2020 in Selenium by Sri
• 3,190 points
2,919 views
0 votes
2 answers
0 votes
1 answer

What is TestNG and why it is used in selenium?

Hello @User, Talking about TestNG, it is an ...READ MORE

answered Dec 24, 2018 in Selenium by Shuvodip
1,312 views
0 votes
1 answer

What is the use of grouping in testNG?

Grouping is the method used to separate ...READ MORE

answered Dec 27, 2018 in Selenium by Trisha
1,089 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,738 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,174 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,252 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,890 views
0 votes
1 answer

What is a feature file in Cucumber test and what are its components?

Hey Jagan, Feature file is a file ...READ MORE

answered Aug 27, 2019 in Selenium by Anvi
• 14,150 points
2,789 views
+1 vote
2 answers

What is the difference between findElement and findElements in Selenium Webdriver?

FindElement Command -This method locates for the ...READ MORE

answered Feb 11, 2020 in Selenium by anonymous
8,398 views
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