Closing app with login screen

Hello!

I’m testing an application that has a login window, then an splash screen and at last - the main window.

My login function:

Runtime.getRuntime().exec("cmd.exe /c start " + “WinAppDriver/WinAppDriver.exe”)
Windows.startApplication(GlobalVariable.path)
Windows.setText(findWindowsObject(‘Object Repository/mainWindow/loginWindow/tbUser’), (GlobalVariable.user))
Windows.setText(findWindowsObject(‘Object Repository/mainWindow/loginWindow/tbPass’), (GlobalVariable.password))
Windows.click(findWindowsObject(‘Object Repository/mainWindow/loginWindow/btLogIn’))
Windows.switchToDesktop()
Windows.switchToWindow(findWindowsObject(Object Repository/mainWindow/mainFrame’))

It works fine, the test cases too. The problem is, when I’m using a test suite and a test case fails. The main window is not closing and after like 10 failures i have 10 opened apps, becouse I guess Katalon is tring to close the login window and not the main window.

Is there a work around to close the main window after test case failure instead of closing the login window?

hi,

try to use testlistener where will close browser after Suite or after Test case

@AfterTestCase
def sampleAfterTestCase(TestCaseContext testCaseContext) {
	println testCaseContext.getTestCaseId()
	println testCaseContext.getTestCaseStatus()
           WebUI.closeBrowser()
}


/**
 * Executes after every test suite ends.
 * @param testSuiteContext: related information of the executed test suite.
 */
@AfterTestSuite
def sampleAfterTestSuite(TestSuiteContext testSuiteContext) {
	println testSuiteContext.getTestSuiteId()
            WebUI.closeBrowser()
}

Hey, thanks for reply, but I’m using here an Windows app, so WebUI.closeBrowser() won’t do the work.

hi,

kill your winappdriver there, not sure I am not playing at all with win apps

You pointed the right direction my friend!

I’ve created a new Test Listener and put inside of it:

class KillMyAppProcess {
/**
* Executes after every test case ends.
* @param testCaseContext related information of the executed test case.
/
@AfterTestCase
def sampleAfterTestCase(TestCaseContext testCaseContext) {
println testCaseContext.getTestCaseId()
println testCaseContext.getTestCaseStatus()
Runtime.getRuntime().exec(“Taskkill /IM myMainApp.exe /F”)
}
/
*
* Executes after every test suite ends.
* @param testSuiteContext: related information of the executed test suite.
*/
@AfterTestSuite
def sampleAfterTestSuite(TestSuiteContext testSuiteContext) {
println testSuiteContext.getTestSuiteId()
Runtime.getRuntime().exec(“Taskkill /IM myMainApp.exe /F”)
}
}

And it’s working! It kills my app after every test case, even if it fails.