Mobile Automation POC

10
ENHANCED MOBILE AUTOMATION TESTING PROOF OF CONCEPT KAUSHIK SADHU AUTOMATION TEST ENGINEER COGNIZANT TECHNOLOGY SOLUTIONS

Transcript of Mobile Automation POC

Page 1: Mobile Automation POC

ENHANCED MOBILE AUTOMATION TESTING PROOF OF CONCEPT

KAUSHIK SADHU AUTOMATION TEST ENGINEER COGNIZANT TECHNOLOGY SOLUTIONS

Page 2: Mobile Automation POC

Introduction

This document provides guidelines for developing automated test scripts in Eclipse IDE with the backbone of Appium and Selenium as core technologies.

Objective:

This document aims at implementing a working testing automation tool chain. The tool chain should include a test management tool for all the test cases, a central repository for the test scripts and a testing framework (automation tool) for running the tests on virtual machines or virtual devices commonly known as emulators. The integration should run all the tests related to the test case when the test run is started in the test management tool. It should pull all the latest test scripts from the central repository and integrate with the Testing tool IDE. After testing is finished, the test results should be combined and collected from the testing framework and finally a report is generated with detailed analysis on the test scenario.

Automated testing

Test automation is one powerful solution, which has been widely accepted all over the world, to reduce the effort and cost of software testing to a reasonable level. Commonly, test automation involves automating a manual process already in place that uses a formalized testing process.

Test Automation Tools

Quick Test Professional - HP

Rational Functional Tester - Rational (IBM Company)

Silk Test - Borland

Test Complete - Automated QA

QA Run (Compuware)

Watir (Open Source)

Selenium (Open Source)

Sahi (Open Source With context to this POC, we will be considering Selenium as a suite of tools for automating web browsers. Selenium is supported by many programming languages (C#, Java, Perl, Python etc.) and testing frameworks (Bromine, Junit, Nunit, Rspec, Robot Framework etc.).

Page 3: Mobile Automation POC

In regards to Mobile Automation Testing, we will consider Appium, Selenium IDE, Selenium RC/WebDriver and Android SDK to test a sample scenario. The below figure shows how the Selenium Core is integrated with the application test in concern. It’s a Simplified Selenium architecture diagram.

Selenium WebDriver is a more advanced version of Selenium Remote Control. The main

difference between them is that selenium RC uses JavaScript functions for running all the supported browsers and finding the correct elements from websites, while WebDriver uses each browsers built-in support for automation, running the browser directly instead of using JavaScript. This makes it more reliable to test dynamic websites where the content can change without the page being reloaded.

Page 4: Mobile Automation POC

Selenium Remote Control (RC) is a website testing tool. It consists of two parts, Selenium Server and Selenium Core. Selenium Server acts as a receiver between Selenium Core and the testing program like Robot Framework;

Test Development

Selenium Test Case Development using JAVA

Required tools:

Selenium RC Server jar file, Selenium Java Client Driver jar file, JDK 1.6 +, Eclipse (or any other

IDE), Junit jar and TESTNG Jar file.

To connect an android device and use it for mobile testing you need Appium and Android SDK preinstalled. You can also use the built in AVD (Android Virtual Device) Emulator for testing your apps.

Setting Up the Workspace

• Download the “Eclipse IDE for Java Developers” from the link: http://www.eclipse.org/downloads/ (preferably JUNO)

• Create a folder say (selenium) in any one of the directory and change the workspace location to the directory created by you. Create a New project and give a name.

• Download junit-4.8.1.jar, selenium-java-client-driver.jar, selenium-server.jar, testng-5.12.jar, Jasmine.jar files.

• Add these jar files by navigating to: Right click on project>Build Path>Configure Build Path>Libraries>Add External Jars.

• Click Ok and then create a new package and inside that create a new class file.

Page 5: Mobile Automation POC

Setting up Appium.

Download the latest version of Appium from: https://bitbucket.org/appium/appium.app/downloads/ and install it.

Start Appium Server by clicking on start button at the top right corner.

Connect your android device or start a virtual emulator using android SDK.

Setup Environment Variable for ANDROID_HOME and JAVA_HOME pointing to your Android SDK folder and JAVA SDK/JRE folder in C: drive.

Once Appium Server is ON and ECLIPSE is setup, you can run your scripts for automation.

Components of Selenium Test Script

SetUp method This method prepares the selenium server to run the test. This method basically hooks to the selenium server and opens up the base URL of the application

Test function() method The methods with the name test will actually run the tests on the application. There can be any number of test methods in the app

tearDown method This method will run after the end of the test. This test will disconnect with the server and makes room for the next tests to run the tests.

Page 6: Mobile Automation POC

A Basic Intro to Appium Appium is used to automate tests on devices with the main objective of allowing users to write tests once, and run them on different platforms and devices with no further effort.

Connecting to Android Virtual Device and using an Emulator to test apps.

• Open Android AVD Manager from SDK directory and start the emulator. • Use any device properties (preferably Android 6.0 API level 23)

• Navigate to C:\Program Files\Android\android-sdk\platform-tools • Open Command Prompt Window inside the above directory. • Type the command: adb devices • A list of connected devices or the id of the emulator will be visible in cmd prompt

window. Take a note of the emulator name or device id. • Make Sure Google Play services or Google Play Store is installed for the below

scenario. “Write a selenium script on android phone that fetches any free application like jarvis, flipkart etc from app store.”

• Also make sure Selenium WebDriver client is installed in the emulator. • Once installed run the WebDriver from the emulator.

Page 7: Mobile Automation POC

Appium and AVD Environment

Code to automate the app from emulator:

package googleplay; //package name

import java.net.MalformedURLException;

import java.net.URL;

import java.util.List;

import java.io.File;

import org.openqa.selenium.By;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.remote.CapabilityType;

import org.openqa.selenium.remote.DesiredCapabilities;

import org.junit.*;

import io.appium.java_client.AppiumDriver;

import io.appium.java_client.android.AndroidDriver;

All the necessary library files need to be included in the class file which we created earlier.

Page 8: Mobile Automation POC

public class test { //class name test

//

private AndroidDriver driver; //android driver client for emulator

@SuppressWarnings("rawtypes")

@Before

public void setUp() throws MalformedURLException{

File classpathRoot = new File(System.getProperty("user.dir"));

File appDir = new File(classpathRoot, "/GooglePlay");

File app = new File(appDir, "PlayStore.apk");

DesiredCapabilities capabilities = new DesiredCapabilities();

capabilities.setCapability(CapabilityType.BROWSER_NAME, "");

capabilities.setCapability("platformName", "Android");

capabilities.setCapability(CapabilityType.VERSION, "6.0");

capabilities.setCapability("deviceName", "emulator-5554"); //name of emulator

capabilities.setCapability("app", app.getAbsolutePath());

capabilities.setCapability("appPackage",

"com.android.vending.AssetBrowserActivity");

capabilities.setCapability("appActivity", ".AssetBrowserActivity");

driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),

capabilities);

}

@Test

public void openplaystore() throws Exception {

WebElement setappname = driver.findElement(By.id("gbqfq"));

setappname.click();

driver.findElement(By.id("gbqfq")).sendKeys("flipkart");

driver.findElement(By.cssSelector("span.preview-overlay-

container")).click();

driver.findElement(By.xpath("//div[@id='body-

content']/div[2]/div/div/div/div/div/div/div[3]/div/div/span/span/button")).c

lick();

driver.findElement(By.id("sign-in-button")).click();

driver.findElement(By.id("Email")).clear();

driver.findElement(By.id("Email")).sendKeys("[email protected]");

driver.findElement(By.id("next")).click();

driver.findElement(By.id("Passwd")).clear();

driver.findElement(By.id("Passwd")).sendKeys("Password");

driver.findElement(By.id(“sign-in-button”).click();

}

}

Page 9: Mobile Automation POC

Selenium Script to install Jarvis app from Play store:

package com.googleApp;

import com.thoughtworks.selenium.Selenium;

import org.openqa.selenium.firefox.FirefoxDriver;

import org.openqa.selenium.WebDriver;

import com.thoughtworks.selenium.webdriven.WebDriverBackedSelenium;

import org.junit.After;

import org.junit.Before;

import org.junit.Test;

@SuppressWarnings("deprecation")

public class PlayStore {

private Selenium selenium;

@Before

public void setUp() throws Exception {

WebDriver driver = new FirefoxDriver();

String baseUrl = "https://play.google.com/";

selenium = new WebDriverBackedSelenium(driver, baseUrl);

}

@Test

public void testUntitled() throws Exception {

selenium.open("/store");

selenium.type("id=gbqfq", "jarvis");

selenium.click("id=gbqfb");

selenium.click("css=span.preview-overlay-container");

selenium.click("//div[@id='bodycontent']/div[2]/div/div/div/div/div/div/div[3]/div/div/span/

span/button");

selenium.click("id=sign-in-button");

selenium.type("id=Passwd", "*****");

Page 10: Mobile Automation POC

selenium.click("id=signIn");

selenium.click("//div[@id='bodycontent']/div/div/div/div/div/div/div/div[3]/div/div/span/span/span/

button[2]");

selenium.click("id=purchase-ok-button");

selenium.click("id=close-dialog-button");

selenium.waitForPageToLoad("30000");

selenium.waitForPageToLoad("30000");

selenium.waitForPageToLoad("30000");

}

@After

public void tearDown() throws Exception {

selenium.stop();

}

}

Now you can automate the apps by writing the test scripts in Eclipse IDE.