Appium Tutorial on Windows Pain-Free

This article is a comprehensive and pain-free Appium start guide using GenyMotion emulator, TestNG framework, and IntelliJ IDEA. At the end of the article, you can also find how to do mobile automation with real devices.

onur baskirtOnur’s Advice: This post is outdated but it comprises of good information thats why I am keeping it in swtestacademy website but I highly suggest starting to Appium with this Appium Tutorial. If you face any problem, please write a comment and share with us.

Prerequisites

  • Appium for Windows
  • Android SDK
  • JAVA JDK
  • IntelliJ
  • GenyMotion Emulator
  • RapidEE (For changing Windows environmental variables easily.)

Step by Step Instructions

Step-1: Install JAVA JDK

Link: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

It is described in this article at step-4.

Step-2: Install Android SDK (Stand-Alone)

Link:  http://developer.android.com/sdk/index.html

Install SDK Tools Only version.

appium

2

2-1

Then, check below options and install them:

  • Android SDK Platform-tools
  • Android SDK Build-tools
  • Android 4.2.2 (API 17)
  • Intel x86 Emulator Accelerator (HAXM installer) [fusion_builder_container hundred_percent=”yes” overflow=”visible”][fusion_builder_row][fusion_builder_column type=”1_1″ background_position=”left top” background_color=”” border_size=”” border_color=”” border_style=”solid” spacing=”yes” background_image=”” background_repeat=”no-repeat” padding=”” margin_top=”0px” margin_bottom=”0px” class=”” id=”” animation_type=”” animation_speed=”0.3″ animation_direction=”left” hide_on_mobile=”no” center_content=”no” min_height=”none”][It accelerates built-in emulator]

4

5

6

7

Create new environmental variable as ANDROID_HOME and assign it with Android SDK Path.

appium

9

Append Android SDK directory, tools and platform-tools paths to system Path variable.

10

In order to test settings, open command prompt and run adb devices command. You will see below result.

11

Go to, extras\intel\Hardware_Accelerated_Execution_Manager under android SDK folder and install intelhaxm-android.exe . It accelerates built-in emulators.

intelhaxm

Note: If your Intel Virtualization Technology(VT-x) option is enabled in BIOS. You should restart your computer and disable it in your computer’s BIOS.

13

Step-3: Create Built-in Emulator (or you can use GenyMotion (Fast) Emulator ->> Step-4)

Open AVDManager.exe under android SDK path. Then, click “Create” button. After that, set the values as shown in the figure below and click “OK”.

14

You can start emulator by clicking “Start” button.

15

emulator

Step-4: Install and Create Genymotion Emulator (Fast Emulator)

Link: https://www.genymotion.com/

Go to Pricing Page and Select Individual (BASIC) plan and sign-in.

genymotion

Then, click to “with VirtualBox: Download for Windows” button to download it. Then, install it.

18

During installation, trust Oracle Corporation Universal Serial Bus Driver and finish installation and launch Genymotion.

19

20

21

Click “+” sign to add a new device. First, you should sign in.

22

Select a device (I prefer a device with low resolution).

23

24

25

If you want, you can Edit and Delete your emulator anytime you want.

26

Click Start to start emulator. Genymotion is very fast emulator. I highly suggest you to use it.

27

28

Step-5: Install Appium

Link: https://bitbucket.org/appium/appium.app/downloads/

Download the latest release.

29

Extract the zip file and run the installer (appium-installer.exe)

30

Step-6: Open Appium & Emulator and Integrate Them

After Appium installation, right click Appium shortcut and click “Run as administrator

31

Then, Start your Genymotion emulator.

Note: Don’t start Genymotion “Run as administrator” mode!!! If you run as administrator, you cannot drag and drop any item into emulator. Reference link: http://stackoverflow.com/questions/20002138/genymotion-2-0-drag-and-drop

Then, download sample .apk file from here. Andv then save it under “C:\TestApks

33

When you type “adb devices” on the command prompt you will see the Genymotion emulator as shown below.

35

We should install sample apk into our emulator. First, open virtualbox and do the below settings.

39

40

41

Then, download Genymotion-ARM-Translation_v1.1 from the link below.

http://forum.xda-developers.com/attachment.php?attachmentid=2680937&d=1397258016

and download the gapps-jb-20130813-signed.zip from the link below.

http://en.osdn.jp/projects/sfnet_rommirrors/downloads/gapps-jb-20130813-signed.zip/

Then, follow the guide here to flash the emulator with these files.

Here is the video that shows how to do this: https://www.youtube.com/watch?v=vZKiqJyLBkU

After these settings, go to Settings on the emulator and apply the below settings:

42

Then drag and drop the BitbarSampleApp.apk into Genymotion.

43

Click Android Settings on the Appium window.

32

And then, do the below settings as shown below.

34

Then, Click settings icon and set the below settings.

54

Then, click to the Run icon on Appium.

36

You should see the below window.

37

After clicking magnifier icon, inspector window will open, and then click “Refresh” button. You will see our test application on the inspector window.

44

Alternative Way to Locate Elements: We can also go to “C:\Program Files (x86)\Android\android-sdk\tools” and open “uiautomatorviewer.bat

45

When UI Automator Viewer opens, click the highlighted icon to capture the current view of the application for inspecting elements.

UI Automator is much better option for locating elements.

46

47

Step-7: Writing Test Code with TestNG and IntelliJ

Select New Project

In the New Project window, select Maven on the left side of the screen.

Then, fill the GorupId, ArtifactId as shown below.

48

Copy and paste the below the line in your pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>myAppiumProject</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>2.53.0</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>htmlunit-driver</artifactId>
            <version>2.20</version>
        </dependency>
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.9.9</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.appium</groupId>
            <artifactId>java-client</artifactId>
            <version>3.4.1</version>
            <scope>test</scope>
        </dependency>
    <dependencies>
</project>

Test Scenario:

  • Open the bitBarSample.apk
  • Click the second radio button
  • Write “SW Test Academy” on the text area
  • Click the “Answer” button
  • Wait and Check the expected text on the next page

Test Code:

import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;

/**
 * Created by Onur Baskirt on 05.04.2016.
 */
public class AppiumBitBarTest {

    private AndroidDriver driver;
    private WebDriverWait wait;

    @BeforeClass
    public void setUp() throws MalformedURLException {
        //Setup Appium
        DesiredCapabilities caps = DesiredCapabilities.android();
        caps.setCapability(MobileCapabilityType.APP, "C:/TestApks/BitbarSampleApp.apk");
        caps.setCapability(MobileCapabilityType.DEVICE_NAME,"EmulatorMotoX");
        caps.setCapability("platformName", "Android");
        caps.setCapability("VERSION", "4.4.2");
        //caps.setCapability("        newCommandTimeout", 600);
        driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), caps);
        wait= new WebDriverWait(driver,20);
    }

    @Test
    public void appiumBitBarTest() throws MalformedURLException, InterruptedException,URISyntaxException {
        //Click second radio button
        driver.findElement(By.name("Use Testdroid Cloud")).click();

        //Write SW Test Academy to the text area
        driver.findElement(By.className("android.widget.EditText")).sendKeys("SW Test Academy");

        //Hide Keyboard
        driver.hideKeyboard();

        //Click Answer Button
        driver.findElement(By.name("Answer")).click();

        //Synchronization after click and check the expected text
        wait.until(ExpectedConditions.presenceOfElementLocated(By.name("You are right!")));
    }

    @AfterClass
    public void teardown(){
        //Teardown operation
        driver.quit();
    }
}

Test Results:

Testing with Real Device

Download your phone’s driver. I am using Samsung Grand NEO

Link: http://www.driverscape.com/download/gt-i9060

After driver installation, you will see the below figure on the device manager.

49

Then, connect your device and run the following commands

Adb kill-server

Adb start-server

Adb devices

And you will see the below result.

50

After that, Change android settings in Appium.

52

Start Appium Server.

53

Then, run the same test on IntelliJ.

Here is the video of the execution:

7 thoughts on “Appium Tutorial on Windows Pain-Free”

    • Hi Siddharth,

      I also used official Android Studio’s emulators but they also behave weirdly. I could not run my tests effectively. Especially, I got many Element Not Found exceptions on XPath declarations. However, the same code runs on real devices without any problem. Thus, if you have a chance to run your tests in real devices, please go in this way.

      Reply
  1. Merhaba Onur Bey,

    Cloudbees kullanmadan Jenkins ile Linux makinada mobil test otomasyonu nasıl çalıştırabiliriz?

    Saygılarımla,
    Burak A. Türkpencesi

    Reply

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.