In selenium how to continue running a script even if it is failed

i have a form filling script during the execution in any line (Step) if the test case is failed it is directly closing the browser . ex: while filling the form if it couldn't find a element (Textbox or Checkbox) it throws an exception nosuchelements and directly closes the browser i am using assert (testNG) in my script what i want is if the test case is failed anywhere middle i want the test case to continue its execution but in the report it should show that the test case is failed

in my code

String Jobvalue = driver.findElement(By.xpath("//label[@for='ctl00_ContentPlaceHolder1_RadPanelBar1_i0_chkColumns_5']")).getText();

Assert.assertEquals(Jobvalue, "Job Value ($)");

Reporter.log(Jobvalue+" Text Verification ---- Passed",true);

Assert will fail the test case if actual value is not equals to expected value i want an alternate to assert or any code which continues executing the test case till the end and at reports it should show it is failed if the actual value is not equal to expected value

Answers


Santhosh, We need more info/code on what are you exactly trying.By assumption, here is my answer for your question.

Use validate() methods rather assert () in your test steps.


Any exception can be easily handled using try-catch.

try{
String Jobvalue = driver.findElement(By.xpath("//label[@for='ctl00_ContentPlaceHolder1_RadPanelBar1_i0_chkColumns_5']")).getText();

Assert.assertEquals(Jobvalue, "Job Value ($)");
}
catch()
{
//Write your code here about failing the test
}

If an Assert fails, it throws an AssertionError and that's why your program is stopped. You can use try/catch to handle the exception.

try{
 Assert......
}catch(AssertionError  e){
 //handle the exception
}

Refer here for Assert documentation


Need Your Help

CSS transition not working with ajax content

jquery ajax performance css3

I'm relatively new to doing animations with CSS, having some experience with JQuery in the past, but I noticed that the animation was really choppy on smaller devices like my iPad, nook and android...

Eclipse: Shortcut to jump to matching tag of XML element

xml eclipse keyboard-shortcuts

I tried with CTRL + SHIFT + P, this works for brackets in code, but not in XML (tried different positions, before the opening tag, after, etc.).