[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.
- Launch the Coffee Timer application on the device.
- Tap on Green Tea.
- Tap on Start.
- 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
To create a new project, go to File > New > New Project.
Fill in the displayed New Project dialog as shown below:
Name The project name. Type The project type. In this example, we choose the Mobile project type. Project This 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 URL The GitHub repository URL. After choosing the sample project, Katalon automatically fills in the URL. Location The save location of your project. After filling in the project details, click OK. A new mobile project opens.
Record a new test case
-
On the main toolbar, click Record Mobile and select your device type. For our example, we choose the iOS Devices option.
-
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
-
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.
-
In the Device View section, we click Green Tea. Katalon Studio correspondingly selects the Green Tea object in the All Objects section.
-
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.
-
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.
-
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.
-
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.
- A dialog opens, providing you three options to save your recorded test:
Export to new test case To export the recorded test steps to a new test case. Append to test case To add the recorded test steps to an existing test case. Overwrite test case To 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:
- Select the test case where you saved the recorded actions.
-
On the main toolbar, select iOS device in the dropdown list next to Run.
-
In the displayed iOS Devices dialog, select an iOS device or Xcode simulator, then click OK.
Katalon Studio executes the iOS test with the recorded steps accordingly.
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()