Skip to main content

[Mobile] Create and Run iOS Test Case in Katalon Studio

This tutorial demonstrates how to create test cases for iOS with Katalon Studio using the Mobile Record Utility, then run the recorded test cases.

In this example, we record the following actions to test the Coffee Timer application:
  1. Launch the Coffee Timer application on the device.
  2. Tap on Green Tea.
  3. Tap on Start.
  4. Tap on Stop.

You can download the sample project as a .zip file here: iOS Mobile Tests.

Requirements

  • iOS setup. To set up Xcode simulators/ real iOS devices, you can refer to this document: [Mobile] iOS Setup.

Create a new project

  1. To create a new project, go to File > New > New Project.

  2. Fill in the displayed New Project dialog as shown below:

    NameThe project name.
    TypeThe project type. In this example, we choose the Mobile project type.
    ProjectThis section allows you to choose a sample project. If you don't want to open a sample project, select the Blank option. In this example, we choose the Sample iOS Mobile Tests Project project.
    Repository URLThe GitHub repository URL. After choosing the sample project, Katalon automatically fills in the URL.
    Location The save location of your project.



  3. After filling in the project details, click OK. A new mobile project opens.

Record a new test case

  1. On the main toolbar, click Record Mobile and select your device type. For our example, we choose the iOS Devices option.



  2. In the displayed Mobile Recorder dialog, specify the information in the Configurations section:



    Device Name To select one of your connected iOS devices or Xcode simulators
    Start with To select Application File in the dropdown list.
    Application File

    For Xcode simulators: browse Coffee Timer.app

    For real iOS devices: browse Coffee Timer.ipa

  3. Click Start to begin recording your test case. After the application under test (AUT) is launched, you can now see:

    • Device View: this section displays the start page of your AUT. You can interact with the Device View section the same way as in a real iOS device.
    • All Objects: this section displays all objects of the current view in the Device View section.

    For our example, we cReqan see the start page of the Coffee Timer application in the Device View section and its object properties in the All Objects section.

  4. In the Device View section, we click Green Tea. Katalon Studio correspondingly selects the Green Tea object in the All Objects section.



  5. Once Green Tea is selected, we click the Tap action in the Available Action section, we now see:

    • The Device View section displays the countdown for Green Tea.
    • Katalon automatically adds the Tap action to the list of recorded steps in the Recorded Actions tab.



    • Katalon also captures the Green Tea object properties and includes it in the Captured Objects tab. To learn more about mobile object properties, you can refer to this document: Manage Mobile Test Objects.



    Note:
    • If you prefer another locator strategy, you can select your preferred one, then click Generate to generate a new locator. You can also check if your newly updated locator can detect the target object correctly by clicking Highlight.



  6. Similarly, click Start in the Device View section, then click Tap in the Available Actions section.

    Katalon automatically adds another Tap action to the list of Recorded Actions and the Start object properties in the Captured Objects tab.



  7. Next, click Stop in the Device View section, then click Tap in the Available Actions section.

    Katalon automatically adds another Tap action to the list of Recorded Actions and the Stop object properties in the Captured Objects tab.



  8. Click Save script. An open dialog asks you to save captured objects into the Object Repository of Katalon Studio. You can create a new folder or select an existing folder in Object Repository, then click OK.

  9. A dialog opens, providing you three options to save your recorded test:
    Export to new test caseTo export the recorded test steps to a new test case.
    Append to test caseTo add the recorded test steps to an existing test case.
    Overwrite test caseTo replace an existing test case with the recorded test case



    Note:
    • Appium known limitation: You may get incorrect object highlighting when rotating the device to landscape view.
    • Workaround: After rotating, you need to click on the Capture Object button to refresh the All Objects tree, then the highlighting will work normally.

Run the recorded test case

To run the recorded steps, follow these steps:

  1. Select the test case where you saved the recorded actions.
  2. On the main toolbar, select iOS device in the dropdown list next to Run.

    Execute iOS

  3. In the displayed iOS Devices dialog, select an iOS device or Xcode simulator, then click OK.

    Choose iOS device

    Katalon Studio executes the iOS test with the recorded steps accordingly.

View the test case in Script mode
import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
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 static com.kms.katalon.core.testobject.ObjectRepository.findWindowsObject
import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint
import com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords as CucumberKW
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
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.webservice.keyword.WSBuiltInKeywords as WS
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import com.kms.katalon.core.windows.keyword.WindowsBuiltinKeywords as Windows
import internal.GlobalVariable as GlobalVariable
import org.openqa.selenium.Keys as Keys

Mobile.startApplication('/Users/thuyngo/Desktop/Project/iOS/App/Coffee Timer 2021-01-27 16-49-52/Apps/Coffee Timer.ipa', true)

Mobile.tap(findTestObject('Object Repository/XCUIElementTypeStaticText - Green Tea (1)'), 0)

Mobile.tap(findTestObject('Object Repository/XCUIElementTypeButton - Start (2)'), 0)

Mobile.tap(findTestObject('Object Repository/XCUIElementTypeButton - Stop (1)'), 0)

Mobile.closeApplication()