[Windows] Unable to switchToApplication when the Desktop Application is opened via .bat file

Hello,

Am using Katalon Studio 8.3.0 and trying to automate a Desktop Application that is already opened using .bat file

I have opened a notepad application using .bat file

Runtime.runtime.exec(“C:\notepad.bat”)

Once notepad is opened successfully, am unable to switch the control to opened notepad app for automation. I have tried many ways but still unable to switch the control to the existing application

Windows.switchToWindowTitle(“Notepad++”, FailureHandling.STOP_ON_FAILURE)

Windows.switchToApplication(findWindowsObject(obj))

Below is the error that i get,

(Root cause: java.lang.NullPointerException
at com.kms.katalon.core.windows.keyword.helper.WindowsActionHelper.switchToWindowTitle(WindowsActionHelper.java:371)
at com.kms.katalon.core.windows.keyword.helper.WindowsActionHelper$switchToWindowTitle$0.call(Unknown Source)
at com.kms.katalon.core.windows.keyword.builtin.SwitchToWindowTitleKeyword$_switchToWindowTitle_closure1.doCall(SwitchToWindowTitleKeyword.groovy:40)
at com.kms.katalon.core.windows.keyword.builtin.SwitchToWindowTitleKeyword$_switchToWindowTitle_closure1.doCall(SwitchToWindowTitleKeyword.groovy)
at com.kms.katalon.core.keyword.internal.KeywordMain.runKeyword(KeywordMain.groovy:89)
at com.kms.katalon.core.keyword.internal.KeywordMain$runKeyword.call(Unknown Source)
at com.kms.katalon.core.windows.keyword.builtin.SwitchToWindowTitleKeyword.switchToWindowTitle(SwitchToWindowTitleKeyword.groovy:39)
at com.kms.katalon.core.windows.keyword.builtin.SwitchToWindowTitleKeyword.execute(SwitchToWindowTitleKeyword.groovy:35)
at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:74)
at com.kms.katalon.core.windows.keyword.WindowsBuiltinKeywords.switchToWindowTitle(WindowsBuiltinKeywords.java:991)
at com.kms.katalon.core.windows.keyword.WindowsBuiltinKeywords$switchToWindowTitle.call(Unknown Source)
at notepad.run(notepad:24)
at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:445)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:436)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:415)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:407)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:284)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:142)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:133)
at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
at TempTestCase1649771239091.run(TempTestCase1649771239091.groovy:25)
)

Can you please help me with it . Is there any way to switch to application that is already opened

@branham1993,

With your current approach, you need to use Windows.startApplication keyword with Root param to create associated WinAppDriver with desktop session after starting notepad.

Runtime.runtime.exec('C:\notepad.bat')
Windows.startApplication('Root')

Just my curious: Why don’t you start the app directly from Katalon Studio Windows.startApplication keyword?