My Blog List

Wednesday, October 19, 2011

Selenium - Custom ExceptionHandling to Control the script execution

Hi all,

Every time exception throws while running the selenium test, we can't know whats the original place its thrown. So you can write an exception handler by own so that it will throw the type.

Here is the ExceptionHandler.Java file.

package SeleniumUtils;
import java.lang.Exception;

public class ExceptionHandler extends Exception { 
 public String functionName;
 public String errorMessage; 

 public ExceptionHandler(String functionName, String errorMessage) {
  this.functionName = functionName;
  this.errorMessage = errorMessage; 

 public String toString(){
        return "\nFunction Name: " +this.functionName+ "\nError Message: " +this.errorMessage+ "\n" ;

So, just write your handler in your script like below to control your script.

function abc() {
   if (isElementPresent(locator))
      throw new ExceptionHandler ("function111", "Error while doing click.")

1 comment:

  1. Thanks for sharing great information in your blog. Got to learn new things from your Blog . It was very nice blog to learn about Selenium