I know that this question is duplicate one. But I am searching for the result from yesterday. I didn't got any solution for that.. I am using Selenium Webdriver 2.47.1 & TestNG for automation. In my automation script I have 12 set of tests & I am using TestNG Assert method to compare Expected Result & Actual Result. My code format is given below...
@Test(priority = 6)
public void TestingeNote1() {
cd.switchTo().frame("RTop");
cd.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
String TesteNote1 = cd.findElement(By.xpath("//table/tbody/tr[2]/td[5]")).getText();
StringBuffer object1 = new StringBuffer(TesteNote1);
String ActeNote1 = object1.substring(108);
String ExpeNote1 = ex.getExcelValue(scenarioName, 75, 4);
try {
Assert.assertEquals(ExpeNote1, ActeNote1);
ex.setExcelValue(scenarioName, 75, 8, "PASSED");
}
catch(Exception e) {
ex.setExcelValue(scenarioName, 75, 8, "FAILED");
}
cd.switchTo().defaultContent();
}
Execution of test script stops once assertion got failed. I want to continue the execution after assertion fail also. I have used Verify() also, It just gives the verify result as passed. But the above test result is Failed one.
I'd recommend using a try/finally block.
. . .
try {
//use IF condition to match Strings (ExpeNote1, ActeNote1)are equal
ex.setExcelValue(scenarioName, 75, 8, "PASSED");
}
catch(Exception e)
{ ex.setExcelValue(scenarioName, 75, 8, "FAILED");}
finally { cd.switchTo().defaultContent();}