RE: How to make test cases run even if an exception occurs. Exceution of cases should not stop.

Hi,

My selenium scripts are getting stopped if an exception occurred and the remaining set of cases are not executing in that suite file .

I want the suite to execute the remaining cases also even if an exception occured.

Thanks in advance.

mallik9292 Train Asked on November 10, 2014 in Selenium WebDriver.
3 Answers

Hi Malik

You Need to Handle Those Exceptions so that Execution  of of Test Cases Wont Stop

Example:: You have 2 test cases signup and login

public test_signup()
{
try{
// code which is throwing exception

}catch(exception e)
{
// do nothing
}
}

In this Way Exception causes by test_signup wont effect other test cases but make sure test case should not dependent on each  other

Regards
Ankit

Vice Professor Answered on November 10, 2014.

Hi Ankit,

Thanks for the reply.  I am executing some of the testcases like validating the page with different inputs  in a for loop at that time my cases are dependent so what can i do at that point

on November 10, 2014.

here is a basic example to show you how we deal with exception


public class add

{

public int number1()

{

int a =10;
return a;

}
public int number2()           throws NullPointerException                                                                                    // now i know this method will return null pointer exception as we havent assigned any value to b

{
int b;
return b;

}catch(NullpointerException e)

{
b=10;    // now even if exception occurs the code will not stop exceuting as value of b is assigned so it can be used anywhere
}
public void add(){           // this method will exceute even if exception in 2nd method

int c;

c=a+b;

}

}

i just hope this will clear your concept

on November 11, 2014.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.