HowTo: Create my first UI Test of a GeneXus Android application

Official Content
This documentation is valid for:

This tutorial shows how to create and run an automated UI Test of your GeneXus Android application.


Component Minimum required
Android Studio  2.3.3
GeneXus 15 Upgrade 10

Set the Enable Test Mode property = True in your main object.

Set the Android Package Name propertycom.artech.<main name> in your main object.

How to create the UI test

Suppose there is a Smart Device application, more specifically, an Android application, with a Menu object that calls an SDPanel.

Event 'Add2'

In the "Add2" SDPanel there is an &InValue variable to enter the value to which it will be added, and a "+2" button that makes the sum. 

Event ClientStart
     &InValue = 2

Event '+2'
        &Result = &InValue + 2
        If &Result <> 4
            &TestOutput = "Error"
            &TestOutput = "Test OK"

The automation implies that when reaching the "Add2" panel, the result of adding 2 to the &InValue variable is 4.

To do so:

  1. Copy the GeneXus-generated Android project to a new directory.
    For example, copy the contents of C:\<model>\<KB_name>\<environment>\mobile\Android C:\MyTests\<KB_name>_test.

  2. Delete the following subdirectories and files:

    1. Folder .gradle

    2. Folder build

    3. Folder <main object name>\build

  3. Open Android Studio and import the project from C:\MyTests\<KB_name>_test\build.gradle

  4. Check that the following directory has been created :
    C:\MyTests\<KB_name>_test \<Main_object_name>\src\androidTest\java\com\artech\menumain\

  5. Try to compile what you have done so far. To do so, look for this icon :
    “SyncNow” (Ctrl+Shift +A Sync Project with Gradle Files)   

       Also, confirm that something similar to the following is displayed below it:

       Locate the “Gradle Console” and confirm that it ends OK.
  6.  Run the application from Android Studio IDE:

      Select the emulator and click OK.
  7.  The application will be run in the emulator. Look for errors in the Gradle console.

  8. Delete the metadata.
  9. Tests are programmed in:
    C:\MyTests\<KB_name>_test \<Main_object_name>\src\androidTest\java\com\artech\menumain\

    For example:
    package com.artech.menumain;
    import org.junit.Rule;
    import org.junit.Test;
    import org.junit.runner.RunWith;
    import static;
    import static;
    import static;
    import static;
    import static com.genexus.uitesting.ControlMatchers.withLabelCaption;
    import static com.genexus.uitesting.DataMatchers.withMenuItemTitle;
    import static com.genexus.uitesting.Selectors.onControl;
    import static com.genexus.uitesting.Selectors.onMenu;
    * Created by UBartram on 19/1/2018.
    public class PrimerTest {
        public ActivityTestRule<Main> mActivityRule = new ActivityTestRule<>(Main.class);
        public void testOne() { 
            // Selects the Menu item
            // Selects a control that has this text
            // Compares the text of the &Result variable to "4"  
            // (the text of the variable value, which is displayed on screen)
            // Compares the text of the &TestOutput variable to "Test OK"
            .check(matches(hasDescendant(withText("Test OK"))));        
  10. It is strongly recommended that you rename the file created in item (9) to <Main>  and attach it as a File object to the KB where the test was created.  
    The purpose is that the next time the KB is compiled, the associated test file is generated instead of the, as indicated in item (4).
    Warning: The file name must follow the naming convention <Main>

How to code the UI test

All expressions created with the API have the following format:



  • onControl: Selects a Genexus control based on the condition imposed by the supplied ControlMatcher.
  • onGrid: Selects a Grid Row based on the condition imposed by the supplied DataMatcher.
  • onMenu: Selects a Menu Item based on the condition imposed by the supplied DataMatcher.

Control Matchers

  • withName: Matches a GeneXus control based on its control name.
  • withThemeClass: Matches a GeneXus control based on its theme class name.
  • withLabelCaption: Matches a GeneXus control based on its label caption.

Data Matchers

  • withTextInRow: Matches a Grid Row based its text content.
  • withMenuItemTitle: Matches a Menu Item based on its title string value.


  • click
  • doubleClick
  • longClick
  • typeText
  • scrollTo
  • swipeLeft
  • & more ...

View the Android Developer - View actions for more actions.


  • matches(isDisplayed())
  • matches(withHint(string))
  • matches(withText(string))
  • matches(withTextColor(colorResource))
  • matches(isChecked())
  • & more ...

View the Android Developer - View matcher for more ways to form assertions



This mechanism can be used as of Genexus 15 Upgrade 10.

See also

Was this page helpful?
What Is This?
Your feedback about this content is important. Let us know what you think.