Thursday, October 29, 2015

Appium - Setting on Real Devices

Executing Test on Real Devices - Android Device

For test to run on devices, we need to make sure :

1. USB Debugging is enabled
2. ADB lists your devices into the connected devices
3. Changing the Desired capability as per the hardware


Enabling USB Debugging:

By default, Android devices do not have USB Debugging enabled, these are under Developer Options. To turn them on,

Navigate to Settings app on phone
Scroll down and click on the Developer Options
Turn on the Developer Options and click the USB Debugging.

Settings -> Developer Options -> Debugging -> USB debugging

Start the Appium and in that launch the Android Server.



Automating Gestures:
Gestures play an important role in how your app is being used. With lot of unique gesture supported on mobile devices, automation has its own challenge. Some of the common gestures are:

single tap
double tap
flick (left or right)
pull down to refresh
long press

Appium handles these gestures using TouchActions api they have created. It’s more like Actions class in Selenium. Apart from that they have also enabled JSON wire protocol server extensions.

We can pass in coordinates as parameters and specify the action we want. Sample code would look like as:

JavascriptExecutor js = (JavascriptExecutor) driver;
HashMap swipeObject = new HashMap();
swipeObject.put(“startX”, 0.01);
swipeObject.put(“startY”, 0.5);
swipeObject.put(“endX”, 0.9);
swipeObject.put(“endY”, 0.6);
swipeObject.put(“duration”, 3.0);
js.executeScript(“mobile: swipe”, swipeObject);
When we enter the coordinates in decimal, it actually specifies the percentage. So in above example it means, 1% from x and 50% from y coordinates. Duration basically specifies how long it will tap and is in seconds.

Some of the mobile methods to be used are:

mobile: tap
mobile: flick
mobile: swipe
mobile: scroll
mobile: shake



Exploring UiAutomatorViewer:
UIAutomatorviewer comes packaged with Android sdk and is present under “tools” folder. It’s a tool, which lets you inspect the UI of an application in order to find the layout hierarchy, and view the properties associated with the controls.

While designing your UI automation suite, this tool is very helpful as it exposes the Id and other attributes of an element, which is needed for writing scripts.

Once the android sdk path is set on the machine, open the terminal and type

"uiautomatorviewer"



Exploring Appium Inspector:
In the previous chapter we saw UiAutomatorViewer which comes bundled with Android SDK. Appium has built something like that which makes our work of finding locators very easy.

When you start the Appium app, you would notice the icons at the top (image below), I have highlighted the Apppium Inspector in red.

No comments:

Post a Comment