If you have followed my series on Installing Appium on Windows then you should have Appium installed on your machine now but you are probably wondering what you are supposed to do next, and how exactly do you go about writing automated tests? Fear not! The next posts in this series on Appium from Scratch are going to guide you through preparing your app for automation, by first teaching you how to interrogate your app.

In this post we are going to continue with our focus on Android on a Windows environment, but look out for a post that covers iOS and Mac in the near future. To be honest, the concepts are very similar on iOS (you need a .IPA file instead of a .APK) file, but the nature of Apple Software Development makes for a few other hurdles that have to be jumped through…

Anyway let’s get started! To inspect your Android app, there are two options available to you; The Appium Inspector and the UIAutomatorViewer. It is actually recommended by the Appium team to use the UIAutomatorViewer, but for completeness I have included instructions for them both. In these examples we are going to use a calculator app . Go ahead and download that APK file now before continuing.

THE APPIUM INSPECTOR

We will begin with the Appium Inspector. First launch the Appium application, you should be able to find it on the Start menu, mine is located at “C:\Program Files\Appium\Appium.exe” . The Appium console should launch as in the screenshot:

Now let’s change a few settings so that we can launch our app through Appium, and get ready to inspect it!

Your settings should look similar to the screenshot on the right hand side.

Now click on the WHEEL icon to open the General Settings.

We need to make sure that “Pre-Launch application” is checked.

Everything else we should be able to just leave the same.

Here is a screenshot of those options on the left.

That’s it, we should be ready to go! Click the PLAY button in the Appium console. You should see a wall of text appear and start to scroll through, and eventually the AVD will launch. After the AVD has started (it could take a few minutes depending on your machine spec) the app should be installed and will launch automatically.

Now let’s launch the Appium inspector. Click on the MAGNIFYING GLASS in the Appium Console and the inspector is launched. Once the inspector has loaded, click REFRESH. All of the elements from the page will be loaded into the Appium inspector. We can browse down the tree structure to find the details of the element that we are interested in, for example in the screenshot we are locating the details for the “7” button.

UIAUTOMATOR VIEWER

The Appium inspector is critical for interogatting iOS apps, but for Android applications it is actually recommended even by the Appium team themselves to use the Android UIAUTOMATORVIEW tool. Fortunately, we will have already installed this tool when we setup Android Automation on our environment, so let’s look how to get it running!

The first thing we need to do is to launch our AVD and install our APK to it. So go ahead and launch your AVD (see this post if you need help on that) and once the AVD has fully loaded open a command prompt, browse to the folder that you downloaded the APK to and type the following:

adb install Calculator_v1.2.3_apkpure.com.apk

This will install the app for us on the virtual device. On the AVD, go ahead and click the options menu button then find the Calculator application and launch it. Now we need to open the UIAutomatorViewer application. In a command prompt, type the following:

cd %ANDROID_HOME%/tools
uiautomatorviewer.bat

This will launch the UIAutomatorViewer application. Once it has loaded, click on the “Device Screenshot” icon to load the details of the currently displayed page:

After a few seconds, an image of the current screen will load in the UIAutomatorViewer and you can use the mouse to click on any element, to see the details of that element. You can also use the hierarchical tree in the top right to browse to a particular element. Again in the screenshot we can see what it looks like when we target the number 7:

For Android automation, the UIAutomatorViewer is the way to go, as it gives us extra control by being able to click on elements. Go ahead and click on a few different elements on the screen and have a look at the details that are updated for each element.

To summarise this post, we have made an important step on our journey to automate our apps, by learning how to interrogate our app to find the details of the various elements that are displayed. However, we still don’t know what we need to do to actually target those elements in the code. In the next post we will explore how we can use the detail of elements identified in the Appium Inspector / UIAutomatorViewer to begin writing XPath code that will ultimately target the elements in our code. See you there!

Tags:

Hi James,
Great blog.
Now is it appium’s fault that google decided to come up with new framework 17+? Also there are couple of projects underway to merge selendroid into appium, or using espresso. If you are motivated enough, you could create implement a page object design pattern and use selendroid and appium in the same test suite.

Yes it is a significant time investment but what are the alternatives? Not do mobile test automation?

Thanks for your comment. Which method and technology you use will depend on your requirements, but the great advantage of using Appium is that you can reuse existing WebDriver code for both iOS and Android. Of course there are pros and cons with the various approaches available, but in my experience Appium is certainly the most mature of everything that is on offer. It is important to remember that mobile development in general (not to mention automation) is still very much in its infancy, and until it becomes a W3C standard there will be ambiguity. The launch of Selenium 3.0 , which should be standardised, might help in regard to this…

James

http://www.swipeclock.com Mark Webster

Hi James,
How do you get the AVD devices to show up, when checking the ‘Launch AVD’ selection box in Android settings? I’ve created two AVDs (using Android Studio’s AVD Manager).