Sunday, January 25, 2015

Run Tests on Android Devices using Appium

Requirement:
Run Tests on Android Devices using Appium.

Solution:
  1. Identify the Device ID
Make sure you follow the steps described in previous post: Appium Setup on Mac OS
Connect Android device to MAC via USB cable, then open Terminal and type:
adb devices
* daemon not running. starting it now on port 5037 *
* daemon started successfully *
List of devices attached
035cd052f0b3666c    device
emulator-5556   device
emulator-5554   device
As you can noticed on my Mac there are two emulator devices and one physical device.
Take the UDID of the desired device and set it to –udid argument of Appium start script.
  1. Configure Appium server for 035cd052f0b3666c 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 4724 --udid 035cd052f0b3666c  --session-override --tmp /Users/vbragaru/dev/tmp/nexus-5

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>:4724/wd/hub
You should see the following page
If you see this, then it’s OK.
  1. Run Java Tests on ApiDemos-debug.apk
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 ApiDemos-debug.apk path where it is located on the server, in my case it is in:
http://172.16.44.32:8080/app-20-gm.apk

  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:
info: --> POST /wd/hub/session {"desiredCapabilities":{"platformVersion":"19","app":"http://172.16.44.32:8080/app-20-gm.apk","platformName":"Android","deviceName":"nexus-5","appActivity":".MainActivity","appPackage":"com.example.android.actionbarcompat.listpopupmenu"}}
info: Client User-Agent string: Apache-HttpClient/4.3.3 (java 1.5)
info: [debug] http://172.16.44.32:8080/app-20-gm.apk downloaded to /var/folders/l1/wwtx0g6x21j1p6dwrzzjh3jm0000gp/T/115019-3685-thgwoi/appium-app.apk
info: [debug] Creating new appium session 576d5d93-38f0-4770-9b6b-b1431d23d38d
info: Starting android appium
info: [debug] Getting Java version
info: Java version is: 1.6.0_65
info: [debug] Using fast reset? true
info: [debug] Preparing device for session
info: [debug] Checking whether app is actually present
info: [debug] Checking whether adb is present
info: [debug] Using adb from /Users/vbragaru/dev/android/android-sdk-macosx/platform-tools/adb
info: Retrieving device
info: [debug] Trying to find a connected android device
info: [debug] Getting connected devices...
info: [debug] executing cmd: /Users/vbragaru/dev/android/android-sdk-macosx/platform-tools/adb devices
info: [debug] 2 device(s) connected
...
...
And so on ...

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:


Friday, January 23, 2015

Appium Setup on Mac OS



Requirement:
Automation test framework for native/hybrid/web Android & iOS application.

Solution: Appium
  1. Installation
    1. Homebrew
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
    1. Node
brew install node      # get node.js
    1. Appium Node npm
npm install -g appium  # get appium
    1. Appium Client
npm install wd         # get appium client
    1. Test Appium Instalation:
> appium
info: Welcome to Appium v1.3.4 (REV c8c79a85fbd6870cd6fc3d66d038a115ebe22efe)
info: Appium REST http interface listener started on 0.0.0.0:4723
info: Console LogLevel: debug
Press CTRL + C to stop Appium.
    1. Install Android SDK for Android Application Tests
SDK Tools Only
Download and unzip it in desired location, in my case it is:
/Users/vbragaru/dev/android/android-sdk-macosx
After that we need to add them to $PATH just run in Terminal:
nano ~/.bash_profile
Our bash profile should look like this:
export ANDROID_HOME=/Users/gmunteanu/dev/android/android-sdk-macosx
export PATH=$ANDROID_HOME/platform-tools:$PATH
export PATH=$ANDROID_HOME/tools:$PATH
export JAVA_HOME=$(/usr/libexec/java_home -v 1.6)
export PATH=/usr/local/bin:$PATH
Press CTRL+O then CTRL+X
Run next command in Terminal to read configurations:
source ~/.bash_profile
Android SDK Tools need some additional packages to be installed, run in Terminal:
android
We have to install green selected packages and optionally orange selected API for device API level to be tested.
    1. Install xCode Command Line Tools for iOS Application Tests
Type in Terminal:
gcc
You’ll see an alert box:
alert Xcode Command Line Tools is required
Click Install and we’re done with xCode command line tools.
Next we have to install ideviceintaller which Appium use to install the .IPA file to device. Run in Terminal:
brew install -v --devel --fresh  automake autoconf libtool wget libimobiledevice

brew install -v --HEAD --fresh --build-from-source ideviceinstaller

    1. Check Appium Installation:
Just run in Terminal:
appium-doctor
You should see the following logs: