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

Unofficial Content
This documentation is valid for:

This tutorial shows how to create and run an automated UI Test for your GeneXus iOS application


Component Minimum required
GeneXus 15
  Upgrade 8

Set the property Enable Test Mode property  = Yes on your application's main object.

Mac computer with XCode (see iOS Requirements page for more details).

How to create the UI test

You can write your UI tests using Apple's XCTest framework, but there is also a more GeneXus-friendly API available.

Suppose there is a Smart Device iOS 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.

Step by step guide

1. Open the Xcode project located at ~/Documents/Projects/<kb_name>/<environment>/<main_object_name>/<main_object_name>.xcodeproj

For example: ~/Documents/Projects/ProyectoUDE/doNetEnvironment/MenuMain/MenuMain.xcodeproj


2. Open the Swift file generated by GeneXus, named <main_object_name>UITest.swift. That's the file were you'll write the test cases.


In that file you can write as many tests as you like, each one of them has to be in a function with name starting with "test".

3. Implement your test case.

For example:

func testExample() {
       // Use recording to get started writing UI tests.
       mainTable().tap(button: "+2")
       validateEquals(expression1: mainTable().read(text: "&TestOutput"), expression2: "Test OK", message: "El valor de &testoutput deberia ser test OK")
       mainTable().fill(edit: "&InValue", value: "3")
       mainTable().tap(button: "+2")
       validateEquals(expression1: mainTable().read(text: "&TestOutput"), expression2: "Error", message: "El valor de &testoutput deberia ser Error")


How to run it

From XCode

1. Select the Test option from the Run drop-down. It runs all the available tests for the project.


2. Verify that the test succedded


From Windows

Create a .bat with the following command:

msbuild.exe /t:OpenKnowledgebase;test /p:ObjectName=%TestObjectName%;KBPath=%KBPAth%;DeviceName="iPhone 6";DeviceOS="latest" c:\testios\msbuild\test.msbuild  /verbosity:minimal > %TestOutputFile%

Where the variables for our sample (ProyectoUDE) are:

%TestObjectName% = "MenuMain"

%KBPAth% is the path of the KB GEnexus, for example "c:\kbproyectoude"  

%TestOutpuFile% is a text file with the result of the test, for example: "c:\testios\iOSTestOutput.txt"

And the test.msbuild has the following

<Project xmlns="">
    <Import Project="$(GX_PROGRAM_DIR)\GeneXus.Tasks.targets"/>

    <Target Name="OpenKnowledgeBase">
        <OpenKnowledgeBase Directory="$(KBPath)" SplitXML="$(SplitXML)" ConcurrentGeneration="$(ConcurrentGeneration)" Options="ConcurrentSpecificationInstances=$(ConcurrentSpecifiers);ConcurrentGenerationInstances=$(ConcurrentGenerators)" XmlOutputFile="$(XmlOutputFile)"/>

    <Target Name="Test">
        <Test ObjectName="$(ObjectName)" DeviceName="$(DeviceName)" DeviceOS="$(DeviceOS)" />


How to integrate with the KB

After you've written the test cases, and run them at least once to check they pass, you can add them to your KB so you can run them again whenever you want.

To do that, create a new File object in the KB with the Swift file that implements the tests.

Warning: The file name must follow the naming convention <Main>UITests.swift.



KB Name: ProyectoUDE

GxServer: http://florida/genexusserversaltostable

Startup Object: MenuMain