Appium Testing ReactNative for iOS Simulator in Github Actions Self-Hosted Runners, Dec 2020

Sandeep Dinesh
3 min readDec 15, 2020

As promised in my post for Android Emulator, here I am with steps for iOS Simulator, everything else remains the same!

This post is a continuation of my post on how to set up a Github Actions workflow for testing a react native app running on iOS Simulator using Appium.

Again I re-emphasize the only reasons to come down from the cloud nodes of Github Actions VM are the inflexibility to configure the hardware of their nodes and slowness of test execution. Details are provided in my Android Emulator post, link provided above, don’t want to re-tell the same things in this brand new story.

Let’s Jump to the Hardware Setup first/ TLDR:

On your self-hosted runner,
1. Install the homebrew

2. Install node and watchman

  • npm install -g react-native-cli
  • brew install node
  • brew install watchman

3. Install the latest XCode from your MacMini’s AppStore. You would have to create your AppleID and sign into it for this.

4. Install React Native command-line interface

  • npm install -g react-native-cli

5. Install the Xcode Command Line Tools

  • xcode-select --install

6. Ensure your XCode path is set correctly

  • sudo xcode-select --switch /Applications/XCode.app

7. Install ruby and cocoapods

  • brew install ruby
  • brew install cocoapods

8. Install the runtime which you want to test your app against

  • xcversion simulators --install=<RUNTIME>
  • for e.g. xcversion simulators --install='iOS 11.4'

Don’t miss this step, since if you kept this part same as the dynamic installation like in Github action workflow of my example, in subsequent re-runs it will fail since XCode will send a failure exit code if it already finds the runtime installed.

and the pseudo-code for the workflow YAML, with relevant info.

# E2E Smoke Tests in iOS 11.4 - iPhone8 on 'develop' branch (CUSTOM-RUNNER)
name: E2E Smoke Tests in iOS 11.4 - iPhone8 on 'develop' branch (CUSTOM-RUNNER)# Controls when the action will run.
on:
push:
branches:
- e2e-custom-runner
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: self-hosted
... # List iOS Devices & Platforms
- name: List iOS Devices & Platforms
run: |
xcrun simctl list
# Get XCode Version
- name: Get XCode Version
run: |
xcodebuild -version
# Delete Existing Simulators
- name: Delete Existing Simulators
run: |
xcrun simctl list | awk -F "[()]" '{ for (i=2; i<NF; i+=2) print $i }' | grep '^[-A-Z0–9]*$' | xargs -I uuid xcrun simctl delete uuid
echo "Deleted Existing Simulators"
# Create and Boot iOS Emulator - iPhone8 on iOS 11.4, Update default appium config for iOS
- name: Create and Run iOS Emulator - iPhone8 on iOS 11.4, Update default appium config for iOS
env:
DEVICENAME: 'TestiPhone8'
DEVICEOS: '11.4'
run: |
xcrun simctl create $DEVICENAME com.apple.CoreSimulator.SimDeviceType.iPhone-8 com.apple.CoreSimulator.SimRuntime.iOS-11-4 > deviceid.txt
DEVICEUUID=`cat deviceid.txt`
echo $DEVICEUUID
sed -i -e "s/{IPHONE_UUID}/$DEVICEUUID/g" __tests__/e2e/template_appium_configs_ios.js
sed -i -e "s/{DEVICE_NAME}/$DEVICENAME/g" __tests__/e2e/template_appium_configs_ios.js
sed -i -e "s/{DEVICE_OS}/$DEVICEOS/g" __tests__/e2e/template_appium_configs_ios.js
xcrun simctl boot $DEVICEUUID &

...

Debug Tips/ Explanations:

Just like Android emulator, to avoid the build cache issues, clean the existing Simulators and run the tests on a fresh instance.

Happy Test Automation & Happy Holidays 2020!

--

--