Appium- Android Native app test automation

I. Getting Ready

First, we need download the java libraries:

  1. Appium java client

    – Go to this link to get it: http://mvnrepository.com/artifact/io.appium/java-client/4.0.0java_client

  2. Selenium Standalone

    – Go to this link to get: http://goo.gl/IHP6Qwsele

  3. Google Gson

    http://mvnrepository.com/artifact/com.google.code.gson/gson/2.6.2gson.PNG

  4. Download and install Appium

    http://appium.io/

  5. Download and install Android SDK

    Please find more installation detail in google page below:  https://developer.android.com/sdk/index.html

II. Setup

  1. Appium

    generalSettingFigure2.png

  2. 2. Start Android Emulator

Figure3Figure4

III. How it works …

Step1: Open Appium and Start agent and take a while for Appium create server

Figure5.pngStep2: Create Appium Java Project:

  1. Add list of libraries below for project:
  • java-client
  • selenium-server-standalone
  • google-gson
  • Junit4

2. Add new Junit test case like below:

import io.appium.java_client.AppiumDriver;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import java.io.File;
import java.net.URL;
import java.util.List;
public class AndroidContactsTest {
    public  AppiumDriver driver; 
    @Before
    public void setUp() throws Exception {
        // set up appium
        File classpathRoot = new File(System.getProperty("user.dir"));
        File appDir = new File(classpathRoot, "../../../apps/ContactManager");
        File app = new File(appDir, "ContactManager.apk");
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
        capabilities.setCapability("platformName", "Android");
        capabilities.setCapability("deviceName","Android Emulator");
        capabilities.setCapability("platformVersion", "5.0");
        capabilities.setCapability("app", app.getAbsolutePath());
        capabilities.setCapability("appPackage", "com.example.android.contactmanager");
        capabilities.setCapability("appActivity", ".ContactManager");
        driver = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
    }

    @After
    public void tearDown() throws Exception {
        driver.quit();
    }

    @Test
    public void addContact(){
        WebElement el = driver.findElement(By.name("Add Contact"));
        el.click();
        List<WebElement> textFieldsList = driver.findElementsByClassName("android.widget.EditText");
        textFieldsList.get(0).sendKeys("Some Name");
        textFieldsList.get(2).sendKeys("Some@example.com");
        driver.swipe(100, 500, 100, 100, 2);
        driver.findElementByName("Save").click();
    }
}

Step3: Then Run this test and here is screenshot

Figure8.png

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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