Saturday, January 24, 2015

Run Tests on iOS Device using Appium

Requirement:
Run Tests on iOS Devices using Appium.

Solution:

Make sure you follow the steps described in previous post: Appium Setup on Mac OS
  1. Identify the Device
Connect iOS device to MAC via USB cable, then open iTunes, you should see following window:
Click on ECID as shown in image.
  1. Configure Appium server for our Device
Appium is just an express (NodeJs) server which listens to a specific port for commands.
For more details about Appium Server capabilities take a look at: http://appium.io/slate/en/master/?ruby#appium-server-capabilities
Run in Terminal:
appium --address <your_ip_adress> --port 4723 --udid 185f898c0dd90254847788545b767ca83c3cf687c9  --session-override --tmp /Users/vbragaru/dev/tmp/iphone6plus

IP address of your MAC you can get via command:  ifconfig
  1. Ping Appium server
Open your browser and type in the address bar: <your_ip_adress>:4723/wd/hub
You should see the following page
  1. Run Java Tests on UiCatalog.ipa
Clone the repository on your local machine:
git clone https://github.com/appium/java-client.git
Open locally cloned project in IntelliJ IDEA, it should look like this:
BTW on my environment the client is Windows machine. You have to change the URL selected on the image above as from step 2 and the UiCatalog.ipa path where it is located on the server, in my case it is in:
/Users/vbragaru/Desktop/UICatalog.ipa

  1. Check Appium Logs if commands come from client
On MAC machine where the Appium server is running check the terminal after the Client runs, logs should look like this:
2014-12-15 15:11:15:275 - info: --> POST /wd/hub/session {"desiredCapabilities":{"platformVersion":"7.1","app":"/Users/vbragaru/Desktop/UICatalog.ipa","platformName":"iOS","deviceName":"iPhone 6"}}
2014-12-15 15:11:15:277 - info: Client User-Agent string: Apache-HttpClient/4.3.3 (java 1.5)
2014-12-15 15:11:15:280 - info: [debug] Using local .ipa from desired caps: /Users/vbragaru/Desktop/UICatalog.ipa
2014-12-15 15:11:15:281 - info: [debug] Copying local zip to tmp dir
2014-12-15 15:11:15:332 - info: [debug] /Users/vbragaru/Desktop/UICatalog.ipa copied to /var/folders/l1/wwtx0g6x21j1p6dwrzzjh3jm0000gp/T/1141115-28159-159aqhz/appium-app.zip
2014-12-15 15:11:15:607 - info: [debug] Unzipping /var/folders/l1/wwtx0g6x21j1p6dwrzzjh3jm0000gp/T/1141115-28159-159aqhz/appium-app.zip
2014-12-15 15:11:15:608 - info: [debug] Testing zip archive: /var/folders/l1/wwtx0g6x21j1p6dwrzzjh3jm0000gp/T/1141115-28159-159aqhz/appium-app.zip
2014-12-15 15:11:15:783 - info: [debug] Zip archive tested clean
2014-12-15 15:11:16:568 - info: [debug] Unzip successful
2014-12-15 15:11:16:569 - info: [debug] Using locally extracted app: /var/folders/l1/wwtx0g6x21j1p6dwrzzjh3jm0000gp/T/1141115-28159-159aqhz/Payload/UICatalog.app
2014-12-15 15:11:16:571 - info: [debug] Creating new appium session e5a6193b-4801-4cb1-956e-bcd0fd1105f1
2014-12-15 15:11:16:575 - info: [debug] Removing any remaining instruments sockets
2014-12-15 15:11:16:577 - info: [debug] Cleaned up instruments socket /tmp/instruments_sock
2014-12-15 15:11:16:577 - info: [debug] Setting Xcode folder
2014-12-15 15:11:16:610 - info: [debug] Setting Xcode version
2014-12-15 15:11:16:881 - info: [debug] Setting iOS SDK Version
2014-12-15 15:11:16:991 - info: [debug] Getting sdk version from xcrun with a timeout
2014-12-15 15:11:17:019 - info: [debug] iOS SDK Version set to 8.1
2014-12-15 15:11:17:019 - info: [debug] Not checking whether simulator is available since we're on a real device
...
...
And so on ...

Limitation:
Only one device per Mac can be connected with Appium server. In order to run multiple devices we choose to use many Virtual Mac Machines using VMware Fusion. Each Mac VM will have its Appium server running on corresponding device.
If you want the Device to be connected to VM you have to choose connect to VM option when the Device is connected via USB like in Image bellow:


No comments:

Post a Comment