Script keeps crashing on startup – how to wait for a slow-loading app home screen?

Hey everyone, I’m really struggling with my first mobile automation script in Katalon Studio and could use some help. I’m testing our company’s Android app, but every time I run the script from the beginning, the app takes a really long time to load—usually about 20 to 25 seconds because it’s doing some initial setup on the first run.

The problem is that my Katalon script keeps failing before the app even gets to the actual ‘Home’ screen. It feels like Katalon just gives up too quickly.

Problem Analysis

Your issue is a timeout problem in mobile automation. Your Android app takes 20-25 seconds to initialize on first run, but Katalon’s timeout settings may be too short, causing the script to fail before the app reaches the Home screen.

The root cause is likely one of two scenarios:

  1. New Command Timeout is too short: If you created your project in Katalon Studio 10.4.0 or later, the default New Command Timeout is only 60 seconds. This controls the maximum idle time Appium waits between commands. If your app initialization takes longer than expected or there’s network latency, Appium may terminate the session prematurely.

  2. Missing explicit waits for elements: Even if the app loads, your script may be trying to interact with elements before they’re fully rendered, causing failures.

Solution: Step-by-Step Configuration

Step 1: Increase Mobile Timeout Settings

  1. Go to Project > Settings > Execution > Mobile

  2. Increase the New command timeout to at least 120-180 seconds (2-3 minutes):

    • This gives Appium more time to handle slow app initialization
    • Set it based on your app’s actual startup time plus buffer
  3. Verify Default wait for element timeout is set to at least 60 seconds (default is usually sufficient)

Step 2: Use Explicit Waits in Your Script

Instead of relying on default timeouts, add explicit waits for elements that appear after app initialization. This is the best practice for handling slow app startup:

import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import internal.GlobalVariable as GlobalVariable

// Start the application
Mobile.startApplication(GlobalVariable.G_AndroidApp, false)

// Wait for the Home screen element to appear (with extended timeout for slow startup)
// Increase the timeout value (in seconds) based on your app's actual startup time
Mobile.waitForElementPresent(findTestObject('Object Repository/HomeScreen/HomeButton'), 30)

// Optionally, wait for element to be visible (more reliable than just present)
Mobile.waitForElementVisible(findTestObject('Object Repository/HomeScreen/HomeButton'), 30)

// Now proceed with your test steps
Mobile.tap(findTestObject('Object Repository/HomeScreen/HomeButton'), 0)

Step 3: Recommended Best Practices

Use waitForElementVisible() instead of waitForElementPresent():

  • waitForElementPresent() - Element exists in DOM but may not be visible
  • waitForElementVisible() - Element is visible and ready for interaction (more reliable)
// Better approach for slow-loading apps
Mobile.waitForElementVisible(findTestObject('Object Repository/HomeScreen/HomeButton'), 35)

Add delay between actions if needed:

  • Go to Project > Settings > Execution > Mobile
  • Increase Delay between actions (in milliseconds) if elements need time to render between interactions
  • Default is 0ms; try 500-1000ms for slow apps

Step 4: Check Your Desired Capabilities

If you’re using custom Desired Capabilities, ensure they don’t override your timeout settings:

// In your test case or test listener
Map<String, Object> capabilities = [:]
// Don't set appium:newCommandTimeout here if you want to use project settings
// Or set it to a higher value if needed:
// capabilities['appium:newCommandTimeout'] = 180

Key Considerations

  • New projects vs. old projects: Projects created before Katalon Studio 10.4.0 have a default new command timeout of 1800 seconds (30 minutes). Newer projects default to 60 seconds. Check which version you’re using.

  • Avoid mixing implicit and explicit waits: Use explicit waits (Mobile.waitForElementPresent(), Mobile.waitForElementVisible()) for better control and predictability.

  • Test on actual device vs. emulator: Emulators are often slower. If testing on an emulator, increase timeouts accordingly.

  • Network and device performance: Slow network or low-end devices may require longer timeouts. Monitor actual execution times and adjust accordingly.

The issue is that your script tries to interact with elements before the app’s Home screen is fully loaded. Katalon gives up too quickly because it doesn’t wait for the element to be present. Here’s how to fix it:

Solution: Use Mobile.waitForElementPresent() Instead of Just delay()

Replace your static delay with an explicit wait that checks for the Home screen element:

// Launch app**
Mobile.launchApp('your.app.package', 30, 0)

// Wait for Home screen element to appear (up to 25 seconds)
Mobile.waitForElementPresent(findTestObject('HomeScreen/div_HomeHeader'), 25)

// Now interact with Home screen elements
Mobile.setText(findTestObject('HomeScreen/input_Search'), 'test', 0)**

Why this works:

  • waitForElementPresent() pauses execution until the element appears, then continues immediately

  • If the element doesn’t appear within 25 seconds, it fails (but you won’t get false failures from timing issues)

  • Much better than Mobile.delay(25) which waits 25 seconds even if the app loads in 5 seconds

Alternative: Add a Test Listener (Setup Hook)

For a reusable solution across all test cases, create a Test Listener that waits automatically before each test:

// In BaseListener (Setup Hook)**
@BeforeTest
public void waitForAppToLoad() {
Mobile.waitForElementPresent(findTestObject('HomeScreen/div_HomeHeader'), 25)
}**

Also Check: Execution Settings for Mobile

Since Katalon Studio 10.4.0+, you can set default timeouts per platform:

  1. Go to Project > Settings > Execution > Mobile

  2. Adjust Default Timeout or Element Wait Timeout to 25–30 seconds

This applies to all Mobile operations without needing to add wait keywords everywhere.

Quick Fix Summary

Problem Wrong Approach Right Approach
App loads slowly Mobile.delay(25) (waits fixed time) Mobile.waitForElementPresent(..., 25) (waits until element appears)
Element not found Script crashes immediately Wait for element to be present first
Multiple tests Add delay in every test case Use Test Listener (Setup Hook)

Try Mobile.waitForElementPresent() first—it’s the most reliable fix for your startup crash issue

The industry-standard approach is to implement an explicit, dynamic wait targeting a unique, identifying element on the landing page (e.g., a logo, a main header, or a navigation bar). This ensures the script proceeds the exact millisecond the app is ready, maximizing execution speed while ensuring robust stability.

The Solution

Use Katalon’s built-in Mobile.waitForElementPresent keyword. This method actively polls the application for a specified element up to a maximum timeout threshold, moving forward immediately once found.

If this behavior is widespread across multiple apps or environments in your framework, wrapping it into a Custom Keyword makes it reusable, clean, and easily maintainable.

Implementation: Custom Keyword

  1. In Katalon Studio, navigate to the Tests Explorer.

  2. Right-click Keywords > New > Keyword.

  3. Set the Package Name to com.utils and Class Name to AppLifecycle.

Paste the following implementation:

Groovy

package com.utils

import com.kms.katalon.core.annotation.Keyword
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.testobject.TestObject
import com.kms.katalon.core.util.KeywordUtil

public class AppLifecycle {

    /**
     * Dynamically waits for the application's home screen to load by polling for a specific Test Object.
     * * @param homeScreenElement The Test Object unique to the Home Screen.
     * @param timeoutInSeconds The maximum duration to wait before throwing an exception.
     */
    @Keyword
    def syncAndVerifyHomeScreen(TestObject homeScreenElement, int timeoutInSeconds) {
        KeywordUtil.logInfo("Waiting for the Home Screen to initialize (Timeout: " + timeoutInSeconds + "s)...")
        
        boolean isPresent = Mobile.waitForElementPresent(homeScreenElement, timeoutInSeconds)
        
        if (isPresent) {
            KeywordUtil.markPassed("Application successfully loaded the Home Screen.")
        } else {
            KeywordUtil.markFailedAndStop("CRITICAL: Application failed to load the Home Screen within " + timeoutInSeconds + " seconds.")
        }
    }
}

How to use it in your Script (Script View)

Groovy

import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject

// 1. Start your application
Mobile.startApplication('path/to/your/app.apk', false)

// 2. Call your custom keyword to dynamically handle the 20-second cold-start ceiling safely
CustomKeywords.'com.utils.AppLifecycle.syncAndVerifyHomeScreen'(findTestObject('Object Repository/Home_Screen/main_Header_Logo'), 30)

// 3. Continue your test flow safely
Mobile.tap(findTestObject('Object Repository/Home_Screen/btn_GetStarted'), 5)

Try using “Mobile.waitForElementPresent” keyword . It is katalon built-in keyword so very easily u will get