XCUITest with Xcode and Swift

Ozgur Kaya
Software Testing Bootcamp
3 min readOct 23, 2021

Youtube Webinar Video:

Getting Started:

This document will help you to debug your iOS App with Xcode and Run your test scenarios with CI/CD integrations.

Example App:

Example App is a calculator app project with Swift. That App will be under test with XCUITest within the same Xcode project.

https://github.com/Shubham0812/Calculator_UI

BDD support in scenarios:

Project Structure:

Warning-1: iOS deployment target for the XCUITest must be the same with target App’s.

Warning-2: If you have got an error while running this sample project click Product-> Clean build folder, Product -> Clean Test results.. and try again to run tests.

Warning-3: If you have got an error about app signing open Signing and capabilities to set your Apple Development Team and certificate

Test Navigator:

Test Recording and running:

Click any test function and the Recording option will be enabled at the bottom. Click it to start generating your test scripts.

Click the play button that’s left on the class name or function name to start your test run.

Common IDB Commands

IDB is a command-line utility to access and manage your iOS simulators or real devices. For more information -> https://fbidb.io/

Open the terminal window and run the following IDB commands with parameters if you need them.

Get help

Idb -h

List all available simulators and connected iOS devices

Idb list-targets

Open specified simulator/real device with UDID number

idb boot YOUR_DEVICE_UDID

List installed application on the target device

idb list-apps --udid YOUR_DEVICE_UDID

Launch the example Calculator application on the target device

Idb launch com.shubham-iosdev.Calculator-UI

Record a video on the target device

idb record video --udid YOUR_DEVICE_UDID --json /Users/YOUR_USER/Downloads/recordingvideo.mp4

Take a screenshot of the target device

idb screenshot --udid YOUR_DEVICE_UDID --json /Users/YOUR_USER/Downloads/capturescreenshot.png

View logs and processes on the target device

idb log --udid YOUR_DEVICE_UDID

Start tests from Terminal window or CI/CD tools :

Enter the project folder from the terminal and run the following example code. You can change your device’s iOS version and device name.

xcodebuild -project Calculator_UI.xcodeproj/ -scheme Calculator_UI -destination 'platform=iOS Simulator,OS=15.0,name=iPhone 13 Pro' clean build test

--

--