Mobile automation using Katalon Studio during test suite execution

Posting on behalf of Kim (김지연)

Hello, I’d like to report a couple of issues we are experiencing with mobile automation using Katalon Studio during test suite execution:

We are currently running mobile automation tests using Katalon by executing a suite that includes test cases for multiple countries.
These test cases are run on a single PC connected to up to three mobile devices simultaneously.

Here are two major issues we’ve encountered:

  1. Sometimes Katalon Studio closes unexpectedly, but the mobile devices continue executing the tests even after the program exits.
  • Do you know why this might happen?
  1. Occasionally, when we start executing the test suite, we receive exceptions like:
  • "Unable to start app with application ID: 'package.name'"
  • "No application is started yet."
  • What might be the cause of this issue?

For your reference, after each test case ends, we make sure to call Mobile.closeApplication() and also run the following ADB commands to completely terminate the app:

adb shell am force-stop <package.name>
adb shell am kill-background-processes <package.name>

If anyone has insight or potential solutions for these issues, we would really appreciate your help. Thank you!

1 Like

Solution to address the two issues in Katalon Studio mobile automation:

Issue 1: Katalon Studio Closes Unexpectedly, but Devices Continue Tests

Root Causes:

  • Background processes (Appium/ADB) remain active even if Katalon crashes.
  • Resource contention (CPU/memory) due to multiple devices on a single PC.
  • Unhandled exceptions or thread leaks in test scripts.

Solutions:

  1. Terminate Background Processes Gracefully:
  • Use a tearDown method to kill Appium/ADB sessions for each device:
CustomKeywords.'com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords.terminateMobileDriver'()
  • Execute batch commands post-crash to force-stop processes:
# Kill all Appium nodes (Windows)
taskkill /F /IM node.exe
# Kill ADB (optional)
taskkill /F /IM adb.exe
  1. Increase Katalon’s Heap Memory:
  • Edit katalon.ini:
-Xmx4096m  # Increase to 4GB or higher
  1. Isolate Device Sessions:
  • Assign unique Appium ports/UUIDs per device to avoid conflicts:
// In test case setup
AppiumDriverDriverProperties properties = new AppiumDriverDriverProperties()
properties.setDeviceUdid("device_udid_here")
properties.setServerPort(4723)  // Unique port per device
MobileDriverFactory.startApplication(properties)
  1. Monitor Resources:
  • Use tools like Windows Task Manager or htop (Linux) to check CPU/RAM usage during runs.

Issue 2: “Unable to Start App” Exceptions

Root Causes:

  • Residual app processes/APK files not fully terminated.
  • Timing issues between test cases (app not closed before next start).
  • Incorrect app package name or corrupted app installation.

Solutions:

  1. Add Explicit Waits After Closing App:
Mobile.closeApplication()
Mobile.delay(5)  // Wait 5 seconds for app to fully terminate
  1. Verify App Termination with ADB:
  • Use a custom keyword to check if the app is still running:
boolean isAppRunning = "adb shell ps | grep <package.name>".execute().text.contains("<package.name>")
if (isAppRunning) {
  "adb shell am force-stop <package.name>".execute()
}
  1. Clear App Data and Cache:
// After closing the app
"adb shell pm clear <package.name>".execute()
  1. Reinstall App Between Tests:
// In setup phase
Mobile.installApp("/path/to/app.apk")
  1. Validate Capabilities:
  • Ensure appPackage and appActivity are correct:
"appium:appPackage" -> "<package.name>",
"appium:appActivity" -> "<main.activity>"
  1. Disable Auto-Launch (if needed):
"appium:autoLaunch" -> "false"
Mobile.startApplication(app, false)  // Launch manually later

General Best Practices:

  • Parallel Execution: Use Katalon Test Suite Collections with multiple executors (one per device) to reduce resource strain.
  • Logging: Enable Katalon’s debug logs and check Logs folder for crash causes.
  • Device Farm Alternative: Consider cloud services like AWS Device Farm or BrowserStack for better device isolation.

Example Workflow:

// Test Case Setup
@BeforeTestCase
def setup() {
  // Start fresh app installation
  Mobile.installApp("/path/to/app.apk")
}

// Test Case
def "Test Example"() {
  Mobile.startApplication(app, [:])
  // Test steps...
}

// Test Case Teardown
@AfterTestCase
def tearDown() {
  Mobile.closeApplication()
  CustomKeywords.'com.kms.utils.ADBHelper.forceStopApp'("<package.name>")
  "adb shell pm clear <package.name>".execute()
  Mobile.delay(3)
}

By implementing these fixes, you’ll stabilize Katalon execution across multiple devices and resolve app-start issues