Skip to main content

Sample Android mobile project in Katalon Studio

This sample demonstrates Android testing fundamentals in Katalon Studio.

The application under test (AUT) is the APIDemos.apk application.

You can learn more about mobile testing in these guides:

Requirements

Open the sample Android test project

To open the Android sample project, in Katalon Studio, go to File > New Sample Project > Sample Android Mobile Tests Project. Katalon Studio will automatically detect and ask you to install Android SDK if your current machine does not have it or your Android SDK is not located at the default folder: ~/.katalon/tools/android_sdk.Open Android sample project

Alternatively, you can download the Android sample project from our GitHub repository: Android sample.

Android sample project components

Profiles

To open the execution profile, go to Profiles > default.

Open execution profile in the sample Android project

You can create and save all global variables in the execution profile. They can be used across test cases in your project. To learn more about execution profile, you can refer to this document: Execution profile.

Katalon creates four global variables in this sample project as follows:

NameValue
G_timeout10
G_NotificationMessageYour message has been sent. View message
G_AndroidAppandroidapp/APIDemos.apk
G_ShortTimeOut5

Test cases

To access test cases in this project, go to the Test Cases folder in the Test Explorer panel.

Sample test cases

There are two test cases for different purposes:

  1. The Verify Correct Alarm Message test case is to verify if we can get the correct displayed message.

    • Start the APIDemos.apk application. Here, the location of the AUT is under the <sample-project-folder>/androidapp folder. We use the following sample code to identify the absolute path to the application:

      /*Get full directory's path of android application*/
      def appPath = PathUtil.relativeToAbsolutePath(GlobalVariable.G_AndroidApp, RunConfiguration.getProjectDir())

      /*Start the AUT*/
      Mobile.startApplication(appPath, false)
    • Tap App. We set the timeout for 10 seconds.
    • Tap Activity. We set the timeout for 10 seconds.
    • Tap Custom Dialog. We set the timeout for 10 seconds.
    • Verify if the text displaying on the App/Activity/Custom Dialog dialog is correct.

      Verify Correct Alarm Message

      You can see the test script as follows:

      import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
      import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
      import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
      import internal.GlobalVariable as GlobalVariable
      import com.kms.katalon.core.configuration.RunConfiguration as RunConfiguration
      import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
      import com.kms.katalon.core.util.internal.PathUtil as PathUtil
      import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
      import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
      import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
      import com.kms.katalon.core.model.FailureHandling as FailureHandling
      import com.kms.katalon.core.testcase.TestCase as TestCase
      import com.kms.katalon.core.testdata.TestData as TestData
      import com.kms.katalon.core.testobject.TestObject as TestObject
      import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint

      Mobile.comment('Story: Verify correct alarm message')

      Mobile.comment('Given that user has started an application')

      'Get full directory\'s path of android application'
      def appPath = PathUtil.relativeToAbsolutePath(GlobalVariable.G_AndroidApp, RunConfiguration.getProjectDir())

      Mobile.startApplication(appPath, false)

      Mobile.comment('And he navigates the application to Activity form')

      Mobile.tap(findTestObject('Alarm Message/android.widget.TextView - App'), 10)

      Mobile.tap(findTestObject('Alarm Message/android.widget.TextView - Activity'), 10)

      Mobile.comment('When he taps on the Custom Dialog button')

      Mobile.tap(findTestObject('Alarm Message/android.widget.TextView - Custom Dialog'), 10)

      'Get displayed message on the dialog'
      def message = Mobile.getText(findTestObject('Application/App/Activity/Custom Dialog/android.widget.TextViewCustomDialog'),
      10)

      Mobile.comment('Then the correct dialog message should be displayed')

      Mobile.verifyEqual(message, 'Example of how you can use a custom Theme.Dialog theme to make an activity that looks like a customized dialog, here with an ugly frame.')

      Mobile.closeApplication()
  2. The Verify Last Items In List test case is to verify whether we can identify the correct last item in the list.

    • Start the APIDemos.apk application. Here, the location of the AUT is under the <sample-project-folder>/androidapp folder. We use the following sample code to identify the absolute path to the application:

      /*Get full directory path of the android application*/
      def appPath = PathUtil.relativeToAbsolutePath(GlobalVariable.G_AndroidApp, RunConfiguration.getProjectDir())

      /*Start the AUT*/
      Mobile.startApplication(appPath, false)
    • Tap Graphics. We use the G_Timeout global variable as the timeout value.
    • Scroll to Xfermodes item.
    • Verify if the current screen should show Xfermodes text after scrolling

      Verify Last Items In List

      You can see the test script as follows:

      import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
      import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
      import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
      import internal.GlobalVariable as GlobalVariable
      import com.kms.katalon.core.configuration.RunConfiguration as RunConfiguration
      import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
      import com.kms.katalon.core.util.internal.PathUtil as PathUtil

      Mobile.comment('Story: Verify correct alarm message')

      Mobile.comment('Given that user has started an application')

      'Get full directory\'s path of android application'
      def appPath = PathUtil.relativeToAbsolutePath(GlobalVariable.G_AndroidApp, RunConfiguration.getProjectDir())

      Mobile.startApplication(appPath, false)

      Mobile.comment('And he navigates the application to Graphics form')

      Mobile.tap(findTestObject('Last Items/android.widget.TextView - Graphics'), GlobalVariable.G_Timeout)

      Mobile.comment('When he scroll to Xfermodes text')

      Mobile.scrollToText('Xfermodes')

      Mobile.comment('Then the current screen should show Xfermodes text after scrolling')

      'Get item\'s label'
      def itemText = Mobile.getText(findTestObject('Last Items/android.widget.TextView - Xfermodes'), GlobalVariable.G_Timeout)

      Mobile.verifyEqual(itemText, 'Xfermodes')

      Mobile.closeApplication()

Test suite

To access the test suite in this project, in the Test Explorer panel, go to the Test Suites > Regression Tests folder. This test suite combines the two test cases shown above.

Test Suites

Execute Android tests

To execute a test case or a test suite in the sample project, follow these steps:
  1. Select the test case/test suite you want to execute.
  2. On the main toolbar, click on the Run dropdown menu and select Android as the device type.
    Execute the selected test

  3. Select your device from the Android Devices list. Click OK.
    Select the Android device

  4. Observe the test result in the Log Viewer tab. To learn more about analyzing test execution logs, you can refer to this document: [WebUI] Analyze Test Execution Logs and Debug the Test Case.
    View results