What is exception test in testng?

0 votes
Jun 19 in Selenium by Zubin
15 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 by Anvi
• 10,310 points

Related Questions In Selenium

0 votes
1 answer

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

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

answered Apr 18, 2018 in Selenium by king_kenny
• 3,590 points
192 views
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
68 views
0 votes
1 answer

What is the use of grouping in testNG?

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

answered Dec 26, 2018 in Selenium by Trisha
55 views
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,050 points
259 views
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
629 views
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
257 views
0 votes
1 answer

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

Hi Nilaabh, Selenium Webdriver uses findElement and ...READ MORE

answered May 8 in Selenium by Anvi
• 10,310 points
120 views
0 votes
1 answer

What is POM in Selenium and what it is used for?

Hello Rubina, POM is Page Object Model which ...READ MORE

answered May 12 in Selenium by Anvi
• 10,310 points
59 views