If a test case fails, how to close the browser and move to the next one?

  • How can i stop the execution of a test case if an exception happen and caught and move to next one. I am using TestNG, Eclipse, Selenium. In my xml, i have:

    <?xml version="1.0" encoding="UTF-8"?>
    <suite name = "Regression Suite" >       
     <listener class-name="Utility.Listener"></listener> 
    <test name = "Regression">
    <class name = "Scripts.TestNG_Temp"/>  -->
    <class name = "Scripts.CreateAppointment"/>
    public void main(){
    }cuaght(ElementNotFoundException e){
    //here i want to stop the execution of my test case, close the browser & move to next one.

  • As I understand you want execution to stop if error occurs, in that case you don't want to inclose your code in try and catch block. Remove try and catch block and add @AfterMethod in your testng class. Once your program errors out it would move move to AfterMethod block or after successful completion of your test.

    public void cleanup(){

Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2