My app keeps closing mid-test and I can't figure out why!

Hi everyone, I’m really struggling with a mobile test in Katalon Studio. I start my test, and everything seems fine for the first few steps—it logs in and navigates to the dashboard. But then, out of nowhere, the app just disappears or closes while the test is still running.

I tried adding a WebUI.delay(10) thinking maybe it just needed to wait, and I even tried to re-click the element, but Katalon just throws an “Element Not Found” error because the app isn’t even on the screen anymore. I don’t know if it’s crashing or if Katalon is losing the connection to the session. I’m stuck in a loop of restarting the app manually, but it keeps happening at the same spot. Has anyone dealt with this “vanishing act” before?

Problem Analysis

You’re experiencing a mobile app session disconnection during test execution—the app disappears mid-test, causing “Element Not Found” errors. This is a known issue in Katalon mobile testing with several root causes related to driver state management, Appium process issues, and improper wait strategies.

The key insight from Katalon’s official troubleshooting documentation is that repeatedly starting and stopping the application can put the driver in a bad state, which directly matches your symptom of the app vanishing at the same spot repeatedly.


Root Causes & Solutions

1. Driver State Corruption (Most Likely)

Problem: Repeated app restarts corrupt the Appium driver session.

Solution: Restructure your test suite to start the app once at the beginning and stop it once at the end:

// ❌ WRONG - Causes driver corruption
Test 1: Mobile.startApplication() → Test steps → Mobile.closeApplication()
Test 2: Mobile.startApplication() → Test steps → Mobile.closeApplication()

// ✅ CORRECT - Maintains driver state
Test Suite:
  Mobile.startApplication()  // Start ONCE
  Test 1: Test steps
  Test 2: Test steps
  Mobile.closeApplication()  // Stop ONCE

Reference: Katalon Documentation - “No Driver Found” Error


2. Stale Appium Processes

Problem: Appium processes don’t quit completely, interfering with new test runs.

Solution: Before running tests, check and kill stale Appium processes:

# macOS/Linux
ps aux | grep appium
kill -9 <process_id>

# Windows
tasklist | findstr appium
taskkill /PID <process_id> /F

Then verify your Appium directory is correctly set:

  • macOS: usr/local/lib/node_modules/appium
  • Windows: C:\npm\node_modules\appium

Navigate to Preferences > Katalon > Mobile to confirm the path.


3. Insufficient Wait Strategies (Your Current Issue)

Problem: WebUI.delay(10) doesn’t actually wait for element readiness—it just pauses. If the app crashes or becomes unresponsive, the delay won’t help.

Solution: Replace static delays with mobile wait keywords that check for actual element readiness:

// ❌ WRONG - Static delay doesn't check element state
WebUI.delay(10)
Mobile.tap(findTestObject('dashboard_element'), 0)

// ✅ CORRECT - Waits for element to be present AND visible
Mobile.waitForElementPresent(findTestObject('dashboard_element'), 30)
Mobile.waitForElementVisible(findTestObject('dashboard_element'), 30)
Mobile.tap(findTestObject('dashboard_element'), 0)

Available Mobile Wait Keywords:

  • Mobile.waitForElementPresent() - Waits for element to exist in DOM
  • Mobile.waitForElementVisible() - Waits for element to be visible
  • Mobile.waitForElementNotPresent() - Waits for element to disappear

Reference: Mobile Wait Keywords Documentation


4. Device/Emulator Resource Issues

Problem: The device or emulator may be running out of memory or experiencing background interference.

Solution:

  • Close unnecessary background apps on the device
  • Restart the emulator/device before running tests
  • Check device memory: adb shell dumpsys meminfo
  • For emulators, allocate more RAM in AVD settings

Recommended Action Plan

  1. Immediate: Kill all stale Appium processes and verify your Appium directory path
  2. Short-term: Restructure your test suite to start/stop the app once per suite, not per test
  3. Long-term: Replace all WebUI.delay() calls with proper Mobile.waitForElement*() keywords
  4. Verify: Run your test again and monitor the Console tab to confirm Appium starts cleanly and the driver remains active throughout

References

Hi @wazir,

Thank you for sharing your issue. Can you please help share recording or screenshot, your code so that we can better support? Thank you

I believe you are using Katalon Studio version 11.0.1. I faced the same issue with this version as well.

While executing a Test Suite Collection, the execution was progressing normally and test cases were running successfully; however, Katalon Studio suddenly closed unexpectedly without any error or warning. This issue occurred multiple times (around 5–6 executions).

:white_check_mark: Solution (Worked for me):

  1. Launch Katalon Studio and log in.

  2. Navigate to Project → Close and Clean Up.

  3. Repeat the “Close and Clean Up” action 5–6 times continuously.

  4. Reopen the project and execute the Test Suite Collection again.

After performing the above steps, the issue was resolved, and Katalon Studio no longer closed abruptly during execution.

Let me know after performing the above simple steps in case the issue is still there

Is Katalon aware of it? Any written acknowledgement from Katalon about the bug? Or, you are suggesting your own know-how without any input from Katalon?

I am not certain whether this was a product bug or an issue on my side or Katalon server issue, but I experienced the same scenario, and the suggested approach worked for me. After applying the workaround, the issue no longer occurred.

If the problem had continued, I would have posted the details in the Katalon Community for further investigation. Since the issue is now resolved, I did not raise it further.

From an architectural standpoint, what you are experiencing is likely one of two things: an Application Crash (common during specific memory-intensive activities) or a Backgrounding Event where the OS reclaims resources.

In enterprise-grade automation, we don’t just “hope” the app stays open. We implement Lifecycle Monitoring. If the app closes unexpectedly, your script should be able to detect the state of the application and either attempt a “Hot Recovery” (re-launching without resetting data) or fail gracefully with a captured log to tell developers exactly why it crashed.

Activity State Verification

Instead of simple delays, we use the Mobile driver to check if the app package is still in the foreground. If it isn’t, we trigger a recovery method.

Custom Keyword: App Recovery Helper

You can create a Custom Keyword in Katalon to check if the app is still active and restart it if it has vanished.

package com.recovery




import com.kms.katalon.core.annotation.Keyword

import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile

import io.appium.java_client.android.AndroidDriver

import com.kms.katalon.core.mobile.keyword.internal.MobileDriverFactory

import io.appium.java_client.appmanagement.ApplicationState




public class AppLifecycle {




    @Keyword

    def ensureAppIsRunning(String bundleId) {

        AndroidDriver driver = MobileDriverFactory.getDriver()

        ApplicationState state = driver.queryAppState(bundleId)

        

        // Check if the app is NOT running in the foreground

        if (state != ApplicationState.RUNNING_IN_FOREGROUND) {

            println "App crashed or closed. Attempting to activate..."

            driver.activateApp(bundleId)

            return false // Signifies a recovery happened

        }

        return true // Everything is fine

    }

}


How to use it in your script:

Instead of just clicking, you can call this keyword before critical steps to ensure your environment is still valid:

  1. Identify your App ID: (e.g., com.example.myapp).

  2. Call the Keyword: CustomKeywords.'com.recovery.AppLifecycle.ensureAppIsRunning'('com.example.myapp')

  3. Result: If the app disappeared, this script will pull it back to the front immediately so the test can continue or fail with a clear message.

Pro-Tip: Check your Logcat (for Android) or Device Logs (for iOS) in Katalon’s “Event Log.” If the app disappears at the exact same spot every time, it’s almost certainly a memory leak or a crash in the application code, not a fault in your test script!

I took image of the execution when the Katalon studio got closed all of a sudden even when the test execution was going on, please find the image and see the tool bar at the bottom ( no studio) but execution is going on.

I deliberately disfigured the content of the UI,

Hi everyone, we’re investigating this issue. We’ll get back to you once we’ve identified the root cause, along with the timeline for a fix.

In my case, the browser will “crash”/close due to a Katalon statement that is missing a parameter or has too many parameters. As an example, if I have:

WebUI.verifyElementVisible(findTestObject(‘…’), 10)

this will cause the browser to crash. The issue usually occurs by changing a “waitFor” command into a “verify” command without removing the “timeOut” parameter, but Katalon comes to it and then crashes. Check out your mobile statements if you are doing something similar.

Could you please upload or looking up in the file named appium.log in Project folder? And Did you using StartApplication or StartExistingApplication along with CloseApplication built-in keywords?

This helped me in managing lifecycle not just in this case but in many cases, actually it was an app bug which we now monitor using this keywords so it helped alot. Thanks Mr Kab.