Saturday, February 6, 2016

OS X Setup and iOS Device Configuration for Mobile Web Test Automation Using Free iOS Provisioning Profile

Requirements:

  • OS X Yosemite 10.10.5
  • Xcode 7.2.1
  • iOS Device (9.2.1)
  • Homebrew
  • Git
  • SafariLauncher
  • Appium (1.4.16)
  • Apple ID with *Provisioning Profile (iOS Development)
*Note: Free iOS Development Provisioning Profile can be created via Xcode 7

I. Create iOS Development Provisioning Profile for SafariLauncher

  • Clone https://github.com/budhash/SafariLauncher.git
  • Open the project in Xcode
    2016-02-06_1915
  • Open Xcode > Preferences > Accounts
  • Add an Apple ID
  • Click the apple id and click View Details
  • Create iOS Development Signing Identities
ios_development_account

II. Create Provisioning Profile for SafariLauncher

  • Using the same xcode project, provide ‘Bundle Identifier’ value.
    i.e.
    com.github.blago.SafariLauncher
  • Fix the issue with Provisioning Profile
    2016-02-06_1551
  • After fixing the issue, provide deployment information
    2016-02-06_1227
  • For Xcode 7.2.1, click Build Settings and edit Code Signing section
    2016-02-06_1230
  • Build and run SafariLauncher on the iOS Device
    2016-02-06_1258
  • Trust the developer of the app in the iOS Device.
    Go to Settings > General > Device Management
    Screenshot 2016.02.06 13.35.13

III. Build SafariLauncher for Real Devices (using appium source)

  • Clone https://github.com/appium/appium.git
    • SHA-1 hash used: 54c2b4e6500eddbca4bb3047116ceb8d177f7294
    • git checkout 54c2b4e6500eddbca4bb3047116ceb8d177f7294
  • Go to the appium directory (clone) and edit reset.sh then provide the BUNDLE_ID used in the provisioning profile
    2016-02-06_1247
  • Run the command inside the appium directory
    ./reset.sh --ios --real-safari --verbose
    
    
    Sample Output
    2016-02-06_1244


IV. Install Homebrew Packages 

  • Do the following command
    brew update
    brew install libimobiledevice libplist libtasn1 usbmuxd openssl ideviceinstaller
    brew install ios-webkit-debug-proxy
    brew install node


V. iOS Device Configuration

  • Enable UI Automation (Settings > Developer)
    Screenshot 2016.02.06 13.06.04
  • Turn on Safari Web Inspector  (Settings > Safari > Advanced)
    Screenshot 2016.02.06 13.07.15


VI. Appium Server Configuration

  • Start ios_webkit_debug_proxy
    ios_webkit_debug_proxy -c <iOS_SERIAL_NUMBER>:27753
    
    
  • Start the sever inside the appium directory
    node . -U <iOS_SERIAL_NUMBER> --app 'safari' --command-timeout 120
    
    
    Note:
    iOS_SERIAL_NUMBER can be found in
    About This Mac > Overview > System Report > Hardware > USB
    2016-02-06_1317

VII. Code Configuration


 String hubUrl = "http://127.0.0.1:4723/wd/hub";  
 String iOSBrowserName = "Safari";  
 String iOSDeviceName = "<iOS_SERIAL_NUMBER>";  
 String iOSVersion = 9.2;  

 DesiredCapabilities capabilities = new DesiredCapabilities();  
 capabilities.setCapability("deviceName", iOSDeviceName);  
 capabilities.setCapability("platformName", "iOS");  
 capabilities.setCapability("platformVersion", iOSVersion);  
 capabilities.setCapability("browserName", iOSBrowserName);  
 WebDriver driver = new RemoteWebDriver(new URL(hubUrl), capabilities); 


VIII. Possible Runtime Errors

  • FBSOpenApplicationErrorDomain error

    info: [debug] [INST STDERR] Instruments Trace Error : Target failed to run: The operation couldn’t be completed. (FBSOpenApplicationErrorDomain error 3.) : Failed to launch process with bundle identifier ‘com.github.blago.SafariLauncher'

    Solution:

    Trust the developer who signed the SafariLauncher app (Settings > General > Device Management)
    Screenshot 2016.02.06 13.35.13
  • ideviceinstaller error

    Error: Command failed: /bin/sh -c ideviceinstaller

    Solution:

    Select the target device in Xcode for the SafariLauncher then restart the appium node.2016-02-06_1620
    2016-02-06_1626

IX. Sample Appium Server Output with iOS Device Screen

  • On standby, waiting for test to run
    2016-02-06_1740
  • Test executed, SafariLauncher started on iOS device.
    2016-02-06_1734
  • Actual test being executed, application under test is m.facebook.com
    2016-02-06_1735

Click here to watch the execution.

Thanks for visiting my blog!