The issue occurs due to one of the below:
- The driver is not initialized or closed properly.
- Conflicts arise when mixing Katalon’s built-in
Mobile
keywords with custom driver creation.
- The app might not start due to incorrect driver setup or
appId
configuration.
Step-by-Step Fix
1. Initialize the Driver Correctly
Avoid using MobileDriverFactory
directly. Instead, use Katalon’s startApplication
or configure a custom driver with Appium desired capabilities.
// Use this in your @BeforeTestCase method
@BeforeTestCase
def setupDriver() {
// Define Appium capabilities
AppiumDriverProperties capabilities = new AppiumDriverProperties()
capabilities.setPlatformName("Android") // or "iOS"
capabilities.setDeviceId("your_device_id")
capabilities.setApp("path/to/app.apk") // or appId if pre-installed
// Start the driver with capabilities
Mobile.startApplication(capabilities, false) // false = new driver session
}
2. Avoid Mixing Built-in Keywords with Custom Drivers
If you use startApplication
, do not call startExistentApp
later. Instead, reuse the existing driver:
// Instead of Mobile.startExistentApp(...), use:
Mobile.switchToExistingApp("your_app_id")
3. Close the Driver Properly in @AfterTestCase
Ensure the driver is terminated after each test to prevent conflicts:
@AfterTestCase
def tearDownDriver() {
Mobile.closeApplication()
}
4. Verify Configuration in execution.properties
In your test case’s Profile (execution.properties
), ensure these settings are defined:
platformName = Android
deviceId = emulator-5554
app = https://your-app-url/app.apk
5. Use Custom Appium Driver (Advanced)
If you need full control over the driver, use AppiumDriver instead of Katalon’s wrapper classes:
import io.appium.java_client.AppiumDriver
@BeforeTestCase
def createCustomDriver() {
// Define Appium server URL and capabilities
String appiumServerUrl = "http://localhost:4723/wd/hub"
DesiredCapabilities caps = new DesiredCapabilities()
caps.setCapability("platformName", "Android")
caps.setCapability("deviceName", "Pixel_4")
caps.setCapability("app", "path/to/app.apk")
// Create the driver and set it globally
AppiumDriver driver = new AppiumDriver(new URL(appiumServerUrl), caps)
MobileDriverFactory.setDriver(driver)
}
Common Pitfalls & Fixes
Symptom |
Cause |
Solution |
App doesn’t start |
Incorrect appId or capabilities |
Double-check appId /appPath and device ID. |
Driver restarts unexpectedly |
Conflict between Mobile keywords and custom driver |
Stick to one approach (either use Katalon’s built-in keywords or custom Appium code). |
App launches after @AfterTestCase |
Driver closed too early |
Ensure Mobile.closeApplication() is called only in @AfterTestCase . |
Debugging Tips
- Check Appium Logs:
Run Appium server with --log-level debug
to see detailed logs.
appium --log-level debug
- Enable Katalon Logging:
Add this to your test script:
import com.kms.katalon.core.configuration.RunConfiguration
RunConfiguration.setLogLevel(RunConfiguration.LOGLEVEL_DEBUG)
Example Project Structure
your-project/
├── Keywords/
│ └── CustomMobileKeywords.groovy
├── Test Cases/
│ └── YourMobileTest.testcase
└── Profiles/
└── default.properties
By following these steps, you should resolve driver initialization issues and avoid conflicts between Katalon’s built-in keywords and custom Appium code