java - In Selenium, if a step fails for a test case, is it possible to just report the failure and continue with remaining steps? -
in selenium, if step fails test case, possible report failure , continue remaining steps? execution halts if there exception. test case looks like-
public class tc002_abc extends opentapwrappers { @test (description="test") public void main() { try { webdriverwait wait=new webdriverwait(driver, 60); verifytitle(constant.homepage_title); click(homepage.link_login(driver), "login link"); wait.until(expectedconditions.urlcontains(constant.loginurl)); verifytextpopulated(communicationpref.lbl_emailaddress_input(driver), constant.emailaddress); /* validate email communications */ click(communicationpref.link_editemailcommunications(driver),"edit email communications"); verifytext(communicationpref.lbl_uncheckedemailcommunications(driver), constant.uncheckedemailcommunications_text); click(communicationpref.btn_emailcommunicationssave(driver), "save"); verifytext(communicationpref.lbl_checkedemailcommunications(driver), constant.checkedemailcommunications_text); } catch (nosuchelementexception e) { e.printstacktrace(); reporter.reportstep("nosuchelementexception" , "fail"); } } @beforeclass public void beforeclass() { browsername="firefox"; testcasename = "tc002_abc"; testdescription = "test"; } }
sample method-
public static void verifytitle(string title){ try { if (driver.gettitle().equalsignorecase(title)) { reporter.reportstep("page loaded :"+title, "pass"); } else reporter.reportstep("page title :"+driver.gettitle()+" did not match :"+title, "fail"); } catch (exception e) { e.printstacktrace(); reporter.reportstep("the title did not match", "fail"); } }
since you're using testng, implement soft assertion
public void verifytitle(string title) { softassert assertion = new softassert(); string returnedtitle = driver.gettitle(); if (assertion.asserttrue(returnedtitle.contains(title))) { reporter.reportstep("page loaded :" + title, "pass"); } else { reporter.reportstep("page title :" + driver.gettitle() + " did not match :" + title, "fail"); } }
let me know if helps.
Comments
Post a Comment