Requirement:
Run Tests on Android Devices using Appium.
Solution:
- 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.
- 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
- 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.
- Run Java Tests on ApiDemos-debug.apk
Go to github: https://github.com/appium/java-client
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
- 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 ...