Assert Stopping Script

Hello, I have an issue with an assertion stopping my script and not continuing execution to close the browser. I am checking that a user sees the homepage after entering correct credentials. In the scenario that the wrong credentials have been entered this stops after the assert, I get the right error, but the browser is never closed.

I know in other functions that you can add the FailureHandler as a parameter and tell it to continue. But assert isn’t called in the same way. I was considering a try/catch/finally statement but feel that is bad practice. Any advice? Thanks in advance!

**CODE********************************************
//After user enters correct credentials, user should see the homepage

assert WebUI.getWindowTitle() == GlobalVariable.homePage_PageTitle

//If bad credentials then execution does not continue to close the browser window

WebUI.closeBrowser()
******************************************************

Hi Richard,

what about simple condition?

if(WebUI.getWindowTitle() != GlobalVariable.homePage_PageTitle) {
    KeywordUtil.markFailedAndStop("Invalid window title.")
}
1 Like

Marek Melocik said:

Hi Richard,

what about simple condition?

if(WebUI.getWindowTitle() != GlobalVariable.homePage_PageTitle) {
KeywordUtil.markFailedAndStop("Invalid window title.")

}


  

That worked beautifully, thank you Marek.

Were you able to test with Assert? Can you help with below query?

for below assert command the object is invalid so it is bound to fail and I want test case to run though this test step fails, but in my case this is not working
assert WebUI.verifyElementPresent(findTestObject(‘Analyst Coverage/h5_Argus’), 0)
is the above right statement?