简体   繁体   中英

how to use assertion in selenium so that if it throws assertion error next line will not skip(java)

I am using assert to verify the scenario in Selenium webdriver. Below is my code. If I get assertion error in my first line, the execution is not happening for next line. But I want to execute the next line as well and want to print the fail report in testng xslt. I am using ANT to trigger my build.

Assert.assertEquals(actualdatesent, expecteddatesent, "comparing assert date");
Assert.assertEquals(actualuccnumber, expecteduccnumber);    

Edit

Try-catch block

try
{ 
    Assert.assertEquals(actualdatesent, expecteddatesent, "date validation failed"); 
    Assert.assertEquals(actualuccnumber, expecteduccnumber, number validation failed);
} 
catch(Throwable T)
{
    ErrorUtils.addVerificationFailure(T); 
    SeleniumScreenshot.takeFailedScreenshot(testname);
}

The only way is to surround every assert with try {} catch (AssertionError ex) and store the messages from exception in a list. At the end of method you will need to check if list is not empty and throw AssertionError yourself with all messages from list concatenated.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM