Vous êtes sur la page 1sur 10

Getting Started with Appium

XBOSoft- Appium Tutorial 2

Appium Tutorial- A Guide forGetting Started in Windows

Appium is proving to be a hot tool for mobile automation as it allows forcross platform automation tests foriOS,
Android,and FirefoxOS applications. This whitepaper is a basic AppiumTutorial to help you get up and running with
this tool.

AthoughAppiumis most commonly usedon Macintosh and Linux, many use it on Windows. This tutorialprovides basic
instructions and tips for setting up Appium on Windows.A test script is also provided in JAVA written for beginners to
start up quickly.

More reasons forselectingAppium;quoteddirectly from http://appium.io/getting-started.html.

1. You don't have to recompile your app or modify it in any way, due to use of standard automation APIs on all platforms.

2. You can write tests with your favorite dev tools using any WebDriver-compatible language such as Java, Objective-C,
JavaScript with Node.js (in both callback and yield-based flavours), PHP, Python, Ruby, C#, Clojure, or Perl with the
Selenium WebDriver API and language-specific client libraries.

3. You can use any testing framework.

For most people, their first step in learning Appium and knowing how to setup in Windows is to Google and find the
following link:

This is the official site, but it is severely out of date. Therefore, its very hard for most people to accomplish what
they want using the information found on this site.

For example, it guides you to install ANT, Maven, and Git; but in fact they are not necessary.
Additionally, many explanations are not clear enough for a beginner to understand.

For example; You must supply the --no-reset and --full-reset flags currently for android to work on Windows.

After going through this whole process, deciphering the directions and figuring out what actually is and is not required,
weve documented the simplest ways to set up Appium on Windows.

www.xbosoft.com 408-350-0508
XBOSoft- Appium Tutorial 3

Setting up Appium in Windows

1 Install JDK 1.7 into your Windows 7; configure JAVA_HOME in your environment variable.

2 Install the Android SDK. Make sure you have an API Level 17 or higher. Set ANDROID_HOME to be your Android SDK
path;add the tools and platform-tools folders to your PATH variable.

3 Download AppiumForWindows.zip from https://bitbucket.org/appium/appium.app/downloads/. Extract it to C:\.

OK, now youve completed the Appium setup. Wasnt that quick?

Lets run a sample script to get a good feel for how it works.

www.xbosoft.com 408-350-0508
XBOSoft- Appium Tutorial 4

Run Appium Script from Eclipse

1 Find Appium.exe from the folder you just extracted in Step 3 above. Double click Appium.exe to invoke Appium. (You
need at least .Net Framework 4.0 installed; but we suggest .Net 4.5.)

You will see the following window.

2 Check Perform Full Reset setting.

www.xbosoft.com 408-350-0508
XBOSoft- Appium Tutorial 5

3 Click File > Preferences, check Reset Application State After Each Session setting.

4 Click the Launch button.
If you can see the following information, congratulations, youve started Appium successfully.

5 Download needed files:Junit jar file from https://github.com/junit-team/junit/wiki/Download-and-Install. Selenium jar
file from http://docs.seleniumhq.org/download/.

www.xbosoft.com 408-350-0508
XBOSoft- Appium Tutorial 6

6 In Eclipse, create a JAVA project named TestAppium. Then, add the newly downloaded Junit and Selenium jar files to
the Referenced Libraries.

7 Now you can write automation scripts for your application. Weve pasted a sample script here for your reference. File
name: androidExampleJunit.java

import java.net.URL;



WebDriverdriver = null;

publicvoidsetUp() throws Exception
FileappDir = newFile("C://Users//xbosoft//Desktop");

www.xbosoft.com 408-350-0508
XBOSoft- Appium Tutorial 7

File app = newFile(appDir, "HelloAndroid.apk");
DesiredCapabilities capabilities = newDesiredCapabilities();
capabilities.setCapability("device", "Android");
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
capabilities.setCapability(CapabilityType.VERSION, "4.2.2");
capabilities.setCapability(CapabilityType.PLATFORM, "WINDOWS");

capabilities.setCapability("app-package", "com.example.helloandroid");
capabilities.setCapability("app-activity", "com.example.helloandroid.MainActivity");
capabilities.setCapability("app", app.getAbsolutePath());

driver = newRemoteWebDriver(new URL(""), capabilities);
driver.manage().timeouts().implicitlyWait(80, TimeUnit.SECONDS);

publicvoidappiumTestSample() throws Exception


publicvoidtearDown() throws Exception

8 Prepare the device.

Scripts can be run on both real devices and virtual devices.Virtual devices can be created in Android SDK Tools > AVD
Manager. Considering that a virtual device needs a Windows machine with at least 8 GB RAM to perform smoothly,
we recommend using a real device.

Get a mobile device with Android version equal to or higher than 4.2.2 and connect to your Windows machine with a
USB cable.

Remember to set the USB Debugging setting to ON in your mobile device. Click OK if you see the following
dialog box.

www.xbosoft.com 408-350-0508
XBOSoft- Appium Tutorial 8

To check if the device is really ready, you can use adb devices command to verify.

9 Prepare the APK file.
The script showed above is specifically for the attached application HelloAndroid.apk. Download and put it onto
your desktop; make sure the path in the line FileappDir = newFile("C://Users//xbosoft//Desktop"); is correct
in your machine.

Everything is ready. Now you can run the script in your Eclipse environment.

www.xbosoft.com 408-350-0508
XBOSoft- Appium Tutorial 9

This basic script will first install the application onto your device; invoke it; click the Test button; click OK button in the
confirmation window, and finally close it.

Now you can use this as a base for your test scripts. Just Copy and modify the script for your needs and you can run
your first Hello Android for your own application.

www.xbosoft.com 408-350-0508
XBOSoft- Appium Tutorial 10


As you can see, once you get around the installation maze, its easy to use Appium for multi-platform mobile
automation tasks.Compared with test automation on a PC/Web platform, the mobiles screen is much smaller making
manual input and operationmuch harder and more prone to errors not only for end users but also for testers!

With mobile test automation, you can automatically handlemanual testing activities that require a lot of manual input
and put into yoursmoke and regression testing.This will save both time and your eyesight.

Photo Reference:
Cover photo courtesy of Richard Leone http://www.flickr.com/photos/richardleonard/104833424/

www.xbosoft.com 408-350-0508