Automating Android Jetpack Compose app with Katalon

I’m rather new user to Katalon studio and I know that in the near future I will need to test Android App which is written using Jetpack compouse. As for now I’m trying to find some useful information’s how to write test cases for mobile app in Jetpack and to be honest there is not a lot in this topic. Is there anyone who has worked with Katalon and Jetpack compose apps??? What do I need to do to make it work?

2 Likes

To automate testing for an Android Jetpack Compose app using Katalon Studio, follow these organized steps:

1. Prepare Your Compose App for Testing

  • Add Test Tags: Ensure developers annotate UI elements with Modifier.testTag("uniqueTag") to make them identifiable.

kotlin

Button(
    modifier = Modifier.testTag("loginButton"),
    onClick = { /* ... */ }
) { Text("Login") }
  • Set Semantics for Accessibility: Use Modifier.semantics to expose elements to UI Automator if needed:

kotlin

Modifier.semantics {
    contentDescription = "Login Button"
    testTag = "loginButton" // If needed for Espresso
}

2. Configure Katalon Studio

  • Set Up Mobile Project: Create a mobile project in Katalon and configure Android settings (package name, launch activity).

3. Choose Automation Engine

  • Espresso: Better for Compose with direct test tag support. Configure test cases to use Espresso in Mobile Settings.
  • UI Automator: Relies on accessibility properties; ensure contentDescription is set.

4. Capture Elements with Mobile Spy

  • Spy Elements: Use Katalon’s Mobile Recorder to identify elements. Look for testTag as resource-id or content-desc.
  • Manual Locators:
    • Accessibility ID: Use contentDescription.
    • XPath: Example: //*[@content-desc='loginButton'].
    • Espresso (Test Tag): Use testTag directly if supported.

5. Write Test Scripts

  • Object Repository: Add elements with captured locators (e.g., testTag as ID or content-desc as accessibility ID).
  • Sample Test Case:

groovy

Mobile.startApplication('path/to/app', true)
Mobile.tap(findTestObject('Object Repository/loginButton'), 10)
Mobile.verifyElementExist(findTestObject('Object Repository/homeScreen'), 10)
Mobile.closeApplication()

6. Handle Challenges

  • Element Not Found: Ensure tags are correctly set and use Katalon’s WaitForElement keyword.
  • Custom Keywords: For advanced scenarios, write custom Espresso code in Groovy/Java.

7. Execute and Debug

  • Run Tests: Use emulators/devices with USB debugging enabled.
  • Logs and Reports: Analyze Katalon’s logs for element identification issues.

Resources

Example Workflow

  1. App Setup: Developers add testTag to a “Submit” button.
  2. Spy in Katalon: Locate the button via testTag using Espresso.
  3. Script:

groovy

Mobile.tap(findTestObject('SubmitButton'), 10)

By integrating Compose’s test tags with Katalon’s Espresso or UI Automator engines, you can effectively automate testing for modern Android apps. Collaborate closely with developers to ensure testability and iterate based on test results.

1 Like