Getting started with Appium requires a few installs and some configuration, so let’s get to it.
This article assumes you already have Java installed and set to the PATH environment variables.
What you need:
Android Studio (the full fat version with the Android SDK)
HyperVisor / Hyper-V Manager (native to windows)
Once installed you need to look under Tools > Android > SDK. There are several components we need. Namely SDK Tools, SDK Build Tools and SDK Platform Tools.
Once setup you will need to add ANDROID_HOME to your PATH environment variable and point it to your main SDK folder. Note: A reboot may be required for Windows to pick up the change.
Visual Studio Emulator for Android
Now let’s look at Visual Studio Emulator for Android, once installed it should hopefully list a bunch of android API device profiles you can either run (if HyperV is enabled). Start one up and you should be able to interact with the virtual device. Note: If you look in Hyper-V Manager you can see the running emulator and tweak memory usage etc.
If we navigate to our sdk tools we can also see the device running by running
and this will list the device name for our Appium setup. In this instance the device is donatello.
Tip: If you happen to want to install an App you can do so with the command: adb install <path\to\yourapk.apk>
Next download Appium and click the Android icon to configure the server, input the relevant fields and device name then click the start button to run the server.
Installing an SSL Certificate on the device if required
As we are interacting with a website rather than an App for the purposes of this article, it can be useful to store SSL Certs on the devices when connecting. Using Visual Studio Emulator for Android we can setup and SD Card.
Pull from SD card first to a temp folder in order to create the directory structure first, then place the SSL Certificate in an easy to remember place and push to the SD card. Under Settings > Privacy in the Android OS we can then add a trusted certificate to the device.
When doing this, Android will force you to create a passcode for the device, do so and keep it easy to remember.
How do I find Android UI Elements for my tests?
Back over in Android SDK land…. in Sdk/tools/bin there is a batch file called uiautomatorviewer.bat. Open this in a text editor and find the line:
call "%java_exe%" "-Djava.ext.dirs=%javaextdirs%" "-Dcom.android.uiautomator.bindir=%prog_dir%" -jar %jarpath% %*
Then replace it with:
call "%java_exe%" "-Djava.ext.dirs=%javaextdirs%" "-Dcom.android.uiautomator.bindir=C:\DEV\androidSDK\tools" -jar %jarpath% %*
Making sure to set the binding directory to where your SDK tools are installed.
Then run uiautomatorviewer.bat whilst your emulator is running. Clicking the Android screenshot icon (second one from the left) will paint a view of what is currently on the emulator screen, you can then hover over buttons etc in order to find locators and anything else you might need.
Please note, your emulator API must be level 17 and upwards.
Time to Code
We can now write automation to run via this emulator with the usual webdriver goodies. Install the Appium Webdriver NuGet package and create the driver with the desired capabilities.
driver = new AndroidDriver<AndroidElement>(new Uri("http://127.0.0.1:4723/wd/hub"), capabilities, TimeSpan.FromSeconds(180));
Note that browserName “BROWSER” will start the devices’ native Android browser.
We can now start the automation of the site, starting with some very crude Selenium here… :
var element = driver.FindElement(By.Id("Email"));
var element2 = driver.FindElement(By.Id("Password"));
Hopefully this is a an easy enough to follow guide to get you up and running using Appium in your c# dev environment, these are the steps I took to being playing with Appium in more depth. Happy testing!