venerdì 11 luglio 2014

Setup mobile test automation environment for Iphone and Ipad apps with Eclipse, Selenium, Appium and ios_webkit_proxy

The steps are a lot but at the end of the day you can have the environment ready to run a selenium program to test mobile apps on your iOS device.

This is the list of software on this post:

- Eclipse to create a java project to write test automation with Selenium and Appium driver. Eclipse is also here used to build the hybrid app
- Xcode to run the app
- Appium is the proxy to run the the Selenium commands into the device
ios_webkit_proxy is necessary to access to the WEBVIEW where is running the hybrid app

Apple Certificates and Provisioning profiles

As prerequisite it needs to have an apple account and join to apple developer program:

https://developer.apple.com/programs/ios/

Follow these steps necessary to request:
  • User certificate to sign the iOS App code
  • App profile associated to the UDID of an iOS device

1. In the Applications folder on your Mac, open the Utilities folder and launch Keychain Access.

Within the Keychain Access drop down menu, select Keychain Access > Certificate Assistant > Request a Certificate from a Certificate Authority and save the CSR (Certificate Signing Request) file created.

2. Login with apple account to the Apple Developer Member Center

3. Upload the CSR file to request the certificate with this wizard:




4. Once your request is approved by the administrator of the apple developer program you can download the certificate on the mac from the list of certificates:



5. On the Mac open the certificate downloaded and ensure is added on Keychain Access application (under Keychains and category My Certificates)

6. Request to the administrator of the developer program to add your device (iphone/ipad UDID) to the list of the iOS devices.

7. Once the device is added and associated to the app managed by your team you can download the provisioning profile on the Mac. Double click on the profisioning file to import on the mac. To verify that is imported check if under this directory there is the provisioning profile similar to this below, the identifier is in bold:
 /Users/youruser/Library/MobileDevice/Provisioning Profiles
123ABC56-DF78-9G0H-I123-45678L901M23.mobileprovision

8. Similarly log-in in the Apple Developer Member Center with safari on the iPad or iPhone and download and install the same profile. To verify the installation is correct check on the device if the profile is present here: Settings-->General--> Provisioning Profiles


Eclipse setup


On the Mac:

1. Download eclipse for iOS and install on your Mac (I've used this):
http://www.eclipse.org/downloads/packages/release/Kepler/SR2

"Download the source code of your app from your server and build of you app specifying the certificate label and prosioning profile identifier"

Optionally if your app is an hybrid application created with worklight you need to the worklight plugin for eclipse. Install from Help --> Install New Software from this link:
http://public.dhe.ibm.com/ibmdl/export/pub/software/mobile-solutions/worklight/wdeupdate/

Optionally if the source code is stored and managed by Rational Team Concert server you need to install the RTC plugin for eclipse.


Xcode setup

On the Mac install:

1. Install Xcode:

https://developer.apple.com/xcode/

2. Install Command Line Tools for Xcode:
https://developer.apple.com/downloads/index.action

3. Connect the iOS device with the USB cable and wifi

4. Build with eclipse and play your IPA with Xcode in order to verify your app starts on the iOS device.


Starting from here I'm going to describe things related to the enable to run the automation:

Appium and Selenium setup


1. Install Appium (first time you run it needs to install additional tools):
http://appium.io/downloads.html

2. On eclipse create a java project for test automation of the apps.

3. Import into to the classpath the latest version of selenium jars, appium client jar and the google json jar:

http://docs.seleniumhq.org/
http://appium.io/downloads.html
https://code.google.com/p/google-gson/

4. Wrote your test case using Selenium connected to the device using the AppiumDriver in order to test your hybrid application. The java program can inspect and use the WebElement object of the webview where the hybrid app runs.


iOS web kit proxy setup

1. On the Mac open a shell and install the web kit proxy and the prerequisite version of the library mobiledevice:

cd /usr/local
git checkout 7e209f0 Library/Formula/libimobiledevice.rb
brew install libimobiledevice
brew install ios-webkit-debug-proxy

If any problem uninstall and install it again:

brew uninstall libimobiledevice -force
brew unlink libimobiledevice

2. Each time you connect the ipad/iphone with usb run and trust it:

idevicepair pair ===> Trust on the ipad popup and run again this command

3. Start web kit proxy

idevice_id -l ===> Returns the ios UIDI in blue as in the example used in the next row below.
ios_webkit_debug_proxy -c null:9221,0446274ec0a7ae7a4d7e2dc2f8123af00ce0732a:27753 -d

the UIDI is in blue and the listening ports are in black

4. If neeced check if ports are in use:

lsof -i :27753

5. Verify the proxy is connected to the device opening this link http://localhost:9221 on the MAC and check if you can see an output like this:



Verify Appium can use the web proxy

1. Install IPA with itunes (double click on the IPA name on the file system of your Mac)

2. Open Appium and configure:

2.1 iOS Settings:



2.2 General Settings:

Set Prelaunch checked (to avoid to install each time the IPA on the device):



2.3 Developer Settings:

Set enabled and specify Custom Server flags of the application (in a single line):

--command-timeout 60000 --platform-name iOS --app /ipalocation/Demo.ipa




3. Start appium (Launch Button) more than one time if it fails until the app is displayed on the iOS device.

4. Once the App starts on the ipad/iphone, run the inspector (the info icon near launch) to check if WEBVIEW are present like in this screenshot:


If some WEBVIEW appear in the context list it means Appium is able to inspect the web objects of the hybrid app not only the native one. This means you are ready to run the selenium automation on  WebElement objects.

If WEBVIEW does not appearing, it means the web proxy is not running correctly (wrong ports, UIDI) and/or your device is not trusted (remember to run idevicepair pair). Note also that when you disconnect the device or wifi fall down, you have to run again idevicepair pair command and restart web proxy and appium.


Note: keep Xcode always opened during the test automation execution otherwise appium will not work.


4 commenti:

  1. It is a very informative and useful post thanks it is good material to read this post increases my knowledge. Apple Developer Program

    RispondiElimina
  2. Thank you for your articles that you have shared with us. Hopefully you can give the article a good benefit to us. Apple Developer

    RispondiElimina
  3. Thank you for your kind words and thoughtful writing.

    We really appreciate it! Your great insightful analysis of the remarkable writings. Those who come to read your information will find lots of helpful and informative tips. Thanks for enlightening us.

    At Ecofire place! We are the leading supplier of Best Electric Fireplace Inserts In Dublin offering free delivery, and easy installations to all our customers. Call us now to get your free estimates and much more.

    call us at +353 85 1381901 Thanks for your valuable time!

    RispondiElimina