Running a test on actual iOS devices

Until now, we have largely built the code base for Android, but most of it remains the same for iOS. We need to create a similar project for iOS apps and use an .app or .ipa file to deploy the app on device/simulator. The current project we have developed is Android-specific; however, we can reuse the feature file. Locators might be different in the case of the iOS app, but the steps largely remains the same to obtain the locator.

However, when it comes to running tests on iOS devices, we need to go through the following series of steps before triggering the test.

The first major requirement is to have a macOS as your machine and, second, to have the iOS app under test signed with a development provisioning profile.
I
f we are using a physical device, we need to enable UI automation in the developer options in the iPhone device. These are the steps to do this:

  1. Switch off the iDevice.
  2. Connect it to the Mac running Xcode.
  3. Switch it back on to have Developer options appear under device Settings.
  4. Tap on the Developer option.
  5. Enable UI automation.

Now, the device is ready to run any Appium tests. The next step to run the Appium test is to get the UDID of the devices. The following steps help you obtain the UDID of iOS devices:

  1. Connect your iOS Device to your Mac and launch iTunes.
  2. In the left pane, go to Devices > Select your Device.
  3. In the right pane, reveal the identifier by clicking on Serial Number. It's a clickable element that toggles.
  4. Copy the device identifier and save it.

We need to have a couple of libraries installed before we run the test. Run the following commands to install these libraries:

  • ios-webkit-debug-proxy: It proxies requests from the usbmuxd daemon over a websocket connection. It allows you to send commands to MobileSafari and UIWebViews on real and simulated iOS devices:
      brew install ios-webkit-debug-proxy
  • libmobiledevice: It's a cross-platform software library that talks the protocols to support Apple devices. It supports iOS devices natively:
      brew install libimobiledevice
  • usbmuxd: It stands for USB multiplexing daemon and is in charge of multiplexing connections over USB to an iOS device:
      brew install usbmuxd
  • carthage: It's a dependency manager for a Cocoa application. Appium uses the Facebook WebDriver agent, which in turn needs carthage as a dependency manager:
      brew install carthage
  • ios-deploy: ideviceinstaller doesn't work with iOS 10 yet. Hence, we need to use the ios-deploy library to interact with real devices. Use this line to implement it:
      npm install -g ios-deploy


These are the steps to follow before triggering a test on an iOS physical device:

  1. Launch the Terminal.
  2. Run ios-webkit-debug-proxy by running the following command. This command restricts the proxy to just one device identified by its UDID:
      ios_webkit_debug_proxy -c <UDID>:27753
  1. Assuming that the test is starting the Appium server, run the Appium test. A sample of the desired capabilities will look like this:
      capabilities.setCapability("platformName", "iOS");
capabilities.setCapability("platformVersion", "9.3");
capabilities.setCapability("deviceName", "iPhone");
capabilities.setCapability("udid",
"2b6f0cc904d137be2e1730235f5664094b831186");

So, the preceding steps will help run the Appium test on physical iOS devices. For running the test on physical iOS devices, udid is a must; we don't need the udid as a desired capability but the deviceName has to match the simulator name for iOS simulators.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.164.24