iOS Automation - Getting Started

abstract This section helps you quickly get started with iOS Automation. To automate an IOS Devices/Simulators using Sahi Pro Classic, refer iOS Automation - Getting Started.


Introduction

Sahi iOS testing is available as part of the Sahi Pro Mobile Add-on module. It allows automation of both iOS devices and simulators having iOS version 9.3 and above. It provides the familiar Sahi features and API paradigm available for browser testing. This includes the ability to record and playback scripts, edit scripts using the Editor, run suites etc.

Pre-requisites

Download and Install Sahi Pro Mobile Add-on

You need to install Sahi Pro Mobile Add-on before you can proceed with the Quick Tutorial

Quick Tutorial

This tutorial involves automating a sample app on an iOS simulator. Sahi Pro Mobile Add-on ships with a few iOS Test Apps. We will use SahiTestApp in this tutorial. We will be running the tutorial on iOS 16.4 - iPhone 14 Pro Max Simulator. But this can be run on any Simulator having version iOS 9.3 or above.

Connect Session and Element Identification

  1. Start the Simulator
    Start a simulator explicitly using the Simulator app. We can also start it with start_simulator.sh detailed in Testing on a Simulator. But we will just use the Simulator app for now.
    • Start the Simulator app from the Xcode menu - Xcode -> Open Developer Tool -> Simulator.
    • Start the specific simulator from the Simulator app menu - Hardware->Device->iOS 16.4->iPhone 14 Pro Max
    • Note down the Simulator UUID. This is needed to install SahiTestApp, in the next step.
      • To get the Simulator UUID, open a Terminal shell, and run xcrun simctl list devices
      • You should see output similar to the following. NOTE that the output will have simulators for different iOS versions, and also different OS types like tvOS, watchOS etc.
        NOTE that your Simulator UUIDs will be different.
      • From the output, locate the iOS 16.4 - iPhone 14 Pro Max simulator entry. It looks like this. As you can see, this shows up as Booted.
  2. Install the Test App
    SahiTestApp needs to be installed on the booted Simulator, before we can automate it.
    • Sahi provides a shell script, install_testapps_on_simulator.sh, to install all Sahi iOS test apps in one go.
    • Open a Terminal shell and navigate to <SAHI_INSTALLATION_FOLDER>/userdata/bin/iOS/testapps folder.
    • Type ./install_testapps_on_simulator.sh <SIMULATOR_UUID> where <SIMULATOR_UUID> is the Simulator UUID you noted above.
      Based on the specific xcrun output above, this will look like

      ./install_testapps_on_simulator.sh 26E1E4C9-70D9-42A2-918E-AD5B21DE5D74

      NOTE again that your Simulator UUID will be different.
    • All the test apps should now get installed on your booted simulator.
  3. Now that we have installed SahiTestApp on the Simulator, start Sahi Dashboard and click on the Flowcharts.
  4. On the Flowcharts window, click on the dropdown arrow next to Launch and then select Launcher Settings.

  5. Launcher Settings dialog opens.

  6. Description of the image labeling:

    1. Select the Mode: IOS
    2. The Device Info: dropdown lists all the Simulators installed on the Mac machine. The booted Simulator will have a (Booted) suffix. IfDevice Info is not populated automatically, choose the booted Simulator from the dropdown.
    3. Type com.sahipro.ios.test.SahiTestApp in the Application BundleId textbox. You will notice that a bunch of suggested apps comes up, but Sahi test apps are not part of the suggestions. So, we need to manually type it the first time. Sahi will remember it from the next time onwards.

  7. Click on Launch to launch the Application.
  8. This will bring up the iOS Viewer in the default browser.
  9. Click on Connect Session
  10. This will start the SahiTestApp application on the Simulator, and the iOS Viewer will display the screenshot of the application.
cdcd

Automating a Keyword

This is similar to automating a Sahi Pro Flowcharts keyword for normal browser testing.
  1. To automate a Keyword, click on a node from the Sahi Pro Flowcharts page, click on the Automate, click on Start Record button, Actions done on the application in IOS Simulator are recorded automatically.
  2. Steps can also be recorded from the Flowcharts Controller.
    • A. You can use Click, Set, Assert, choose 'Other Actions' to perform an action on the Application on the IOS Simulator.

      B. You will need to record these steps explicitly by clicking on 'Add Step'.
info
  • If you see the keyboard appearing, toggle the keyboard twice by clicking on [Hardware->Keyboard->Toggle Software Keyboard] from the Simulator app menu twice. This will first hide the keyboard and show it again.
  • If you do NOT see the keyboard appearing, toggle the keyboard once by clicking on [Hardware->Keyboard->Toggle Software Keyboard] from the Simulator app menu once. This will simply show the keyboard once.

Playback

  1. On the Automate dialog click on Runbutton.
  2. The Run Settings dialog opens. Select the Mode IOS and click RUN.
  3. infoWhen the flow is being played back, you CANNOT see the playback happening on the IOS Viewer. The IOS Viewer does not get refreshed during playback.

View Report

  1. Click on the Reports button..
  2. The Report opens in a new browser tab.
  3. Click on Disconnect Session button in the Viewer to disconnect the session.
infoRefer Run Flowchart for a better understanding.

Further Reading

iOS Automation in Detail
iOS Accessor APIs
Mobile APIs
Working with Multiple Modes in a Single Script