Assert Stopping Script


#1

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()
******************************************************


#2

Hi Richard,

what about simple condition?

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

#3

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.