iOS Mobile App Automation Testing— setup Appium and Xcode
As a newbie to “Mobile App Automation” your mind may be spinning with questions about -
What is the right tool?
What is the best framework?
What Programming Language should I use?
Should I start with iOS or Android?
Should I automate my app using a Simulator or Real devices?
All of these questions bugged me when I first started automating mobile applications in my company. Ultimately, I decided to learn to use Appium as it is the common tool to automate mobile applications. For both iOS and Android, I plan to use the same automation framework by only making changes where necessary to account for the platform differences. I am using Appium with Cucumber and Ruby to write Automation tests on iOS
As this is the first article of the series on automating iOS apps with simulators, let’s begin with the hardest part to set up which is the initial framework for automation.
Let’s install and configure the below to get started:
- Appium Inspector
Appium is an open-source test automation framework for use with native, hybrid, and mobile web apps. It drives iOS, Android, and Windows apps using the WebDriver protocol.
How to Install Appium
- Install the latest Appium-Desktop application from https://appium.io/downloads.html
- Download and install the .dmg file for mac,
- Click and open the installed Appium desktop application
- Start the Appium server — Start Server v1.22.0
- All good then you could see — The server is running.
Xcode is an integrated development environment created by Apple for developing software for macOS, iOS, watchOS, and tvOS. The role of Xcode in mobile application automation is just to compile the app (.xcodeproj) in the required simulators (iPhone/iPad) with the required version of OS.
Ex: iPhone 13 simulator with iOS Version 15.2
How to install Xcode
- Search for Xcode in the App Store and install,
- Get the project code from the iOS team, clone and save it on your machine,
- Navigate to the project folder in the terminal and execute the below commands to install the dependencies required
% bundle Install
% bundle exec pod install
- From the project folder double click the .xcodeproj file to open it in the installed Xcode,
- Compile and build the project — Build Succeeded,
- Within the Project Navigator, you can find the .app file for the project in the Products folder.
Launch Application with Simulator
iOS simulator provides a fast and easy way to set up a software environment for application testing purposes without mimicking actual hardware. You could view the app in an iPad or iPhone-like window.
- Select the required simulator and OS version from the top menu in Xcode and run the build:
- Upon successful compilation, the selected simulator will open with the app installed,
- A virtual iPhone with the application is now available for testing:
- Similarly, you could open many simulators with different operating systems for testing the application.
Appium inspector is used to uniquely locate or find the UI elements of a mobile application. It works with both real devices and simulators. Appium Inspector is part of the Appium desktop application for older versions. With the new versions, Appium Inspector must be installed separately.
How to install Appium Inspector
- Appium Inspector is now available as a separate application,
- Download and Install the required release from: https://github.com/appium/appium-inspector/releases
- For additional information on the Appium Inspector, please visit https://github.com/appium/appium-inspector
- Open Appium Inspector and define the desired capabilities for iOS:
“deviceName”: “iPhone 13”,
“bundleId”: “XXX” (Get the BundleId for the project from the iOS team or Xcode — click on the project — Signing & Capabilities — Bundle Identifier)
- Above mentioned capabilities are mandatory, you could include optional capabilities as required. Save the capability set for easy use
- Start Session, Appium Inspector starts the application and displays the current snapshot with App source:
- Start inspecting elements of the screen captured using Appium Inspector
Challenges faced during the setup:
- Make sure the Mac, Xcode, and Appium versions are compatible
- Configure the project in Xcode and its dependencies like homebrew, npm, node, Carthage, Cocoapods. The iOS Team helped me build the project successfully by troubleshooting configuration issues
As the initial installations and setup required to start mobile application automation are complete, the next step is to configure the automation framework in IDE to start the test script.