Sunday, August 16, 2015

How to Configure Appium

Prerequisite to use APPIUM:
  1. ANDROID SDK :
    1. Select Stand-alone SDK tools
D:\Rakesh Chityala\Appium\Docmantation\SCREEN SHOTS\Standalone_SDK.png
    1. Click Download SDK now
D:\Rakesh Chityala\Appium\Docmantation\SCREEN SHOTS\Click_on_SDK.png
    1. Based on Platform we need to select the file (mine is windows, so downloading .exe)
D:\Rakesh Chityala\Appium\Docmantation\SCREEN SHOTS\Select_the_platform.png
    1. Accept the terms and conditions and click on Download

D:\Rakesh Chityala\Appium\Docmantation\SCREEN SHOTS\Accept_the_conditions_and_Click_on_Download.png
    1. It will automatically start download file as mentioned below
D:\Rakesh Chityala\Appium\Docmantation\SCREEN SHOTS\Downloading.png
    1. Open containing file of downloaded file
D:\Rakesh Chityala\Appium\Docmantation\SCREEN SHOTS\dowloaded_file.png
    1. Double click on installation file and Follow the mentioned in the dialogue box
D:\Rakesh Chityala\Appium\Docmantation\SCREEN SHOTS\SDK_Tool_Setup1.pngD:\Rakesh Chityala\Appium\Docmantation\SCREEN SHOTS\SDK_Setup_2.pngD:\Rakesh Chityala\Appium\Docmantation\SCREEN SHOTS\SDK_Setup_3.pngD:\Rakesh Chityala\Appium\Docmantation\SCREEN SHOTS\SDK installatio Steps\SDK_setup_4.pngD:\Rakesh Chityala\Appium\Docmantation\SCREEN SHOTS\SDK_Setup_5.pngD:\Rakesh Chityala\Appium\Docmantation\SCREEN SHOTS\SDK_Setup_6.pngD:\Rakesh Chityala\Appium\Docmantation\SCREEN SHOTS\SDK_Setup_7.pngD:\Rakesh Chityala\Appium\Docmantation\SCREEN SHOTS\SDK_Setup_8.pngAfter clicking the finish button it will open the SDK Manger
D:\Rakesh Chityala\Appium\Docmantation\SCREEN SHOTS\SDK_Manager.png  
    1. Select the required tools and API versions to click on Install packages to Install

  1. JDK (Java Development Kit) [Link]:
Make sure java has been installed in you machines. Along with java path in environment variables.
  1. Eclipse [Link]
Create a project
File → New → Java Project → Enter Project Name → Click on Finish
Make Sure JRE version has been picked by default in the JRE section
D:\Rakesh Chityala\Appium\Docmantation\SCREEN SHOTS\Create JAVA Project\Create_JAVA Project.png
Right click on Project Name → New → Package
C:\Users\Admin\Pictures\Screenshots\Screenshot (34).png
Enter package name and Click on Finish
D:\Rakesh Chityala\Appium\Docmantation\SCREEN SHOTS\Create JAVA Project\Create_Pakage.png

Right click on package → New → Class
C:\Users\Admin\Pictures\Screenshots\Screenshot (35).png
Enter Class Name and Click on Finish
D:\Rakesh Chityala\Appium\Docmantation\SCREEN SHOTS\Create JAVA Project\Create_class.png
  1. TestNG [Link]:
  1. Select Help / Install new software.
  2. Search for new features to install.
  3. New remote site.
  4. For Eclipse 3.4 and above, enter http://beust.com/eclipse.
  5. For Eclipse 3.3 and below, enter http://beust.com/eclipse1.
  6. Make sure the check box next to URL is checked and click Next.
  7. Eclipse will then guide you through the process.
  8. After successful installation of TestNG, we create TestNG class
Expand the a project Right click on a class New   Other
C:\Users\Admin\Pictures\Screenshots\Screenshot (37).png

Select Test NG class Click on Next
D:\Rakesh Chityala\Appium\Docmantation\SCREEN SHOTS\Create JAVA Project\Create_Test_NG_class.png

Enter Class name and Select the Annotation, Click on Finish
D:\Rakesh Chityala\Appium\Docmantation\SCREEN SHOTS\Create JAVA Project\Test_NG_ClassName.png
  1. Selenium Server JAR [Link]
    1. Download selenium server jar from the selenium
    2. Add this jar files to the respective project
How to Add Jars
  1. Right click on a project Build path Configure Build path
C:\Users\Admin\Pictures\Screenshots\Screenshot (38).png
Click on Add external Jars
D:\Rakesh Chityala\Appium\Docmantation\SCREEN SHOTS\Create JAVA Project\Add_External_Jars.png

Select Selenium server and Selenium Java jars (which we can download from http://www.seleniumhq.org/download/)
D:\Rakesh Chityala\Appium\Docmantation\SCREEN SHOTS\Create JAVA Project\Selenium_Server_Jar.pngD:\Rakesh Chityala\Appium\Docmantation\SCREEN SHOTS\Create JAVA Project\Selenium_Java_Jars.png

Click on ‘Open ’ after selecting the jar and Click on ‘Ok’

  1. Webdriver Language Binding Library [Link]
    1. Download the webdriver jar and add it to the current project
  2. APPIUM For Windows [Link]
Download appium here
D:\Rakesh Chityala\Appium\Docmantation\SCREEN SHOTS\Appium\Download_Appium.png
Click on Download Appium, It will automatically start downloading Appium for windows
Extract the file from file and install the server by double clicking the ‘appium-installer.exe’
  1. How to work with emulators:
Installing Eclipse plug-in click Here
Make sure URL whuch was provided in preferences is matching to where SDK file has been installed.
Window → preferences
C:\Users\Admin\Pictures\Screenshots\Screenshot (39).png
D:\Rakesh Chityala\Appium\Docmantation\SCREEN SHOTS\SDK installatio Steps\Prefrences_.png
After successful installation SDK Manager and AVD icons will be displayed
D:\Rakesh Chityala\Appium\Docmantation\SCREEN SHOTS\Appium\SDk_Manger_and_AVD_icons.png
SDK Manager : It is used manage the API
AVD: Used to create the Virtual devices
  1. Download Appium jar (java) files click here  and Add to the corresponding project
D:\Rakesh Chityala\Appium\Docmantation\SCREEN SHOTS\Appium\Appium_Lib.png

  1. Set Android Home:
set ANDROID_HOME=C:\<installation location>\android-sdks
set PATH=%PATH%;%ANDROID_HOME%\tools;%ANDROID_HOME%\platform-tools
If everything is done perfectly then it will open SDK Manager when we type ‘android’ from cmd
D:\Rakesh Chityala\Appium\Docmantation\SCREEN SHOTS\Appium\Loading_SDK_from_cmd.png
  1. Prerequisites to write Appium Code:
    1. Make sure Android SDK has been installed and Path has been set  in environment variables
    2. Libraries of both selenium and Appium has been Added  into the project
    3. Appium.exe Must be installed in machine
    4. Need to start the server before executing the appium program
    5. UI Automator: To locate the elements


  1. UI Automator:
    1. To analyse the UI components of the application that you want to test, perform the following steps after installing the application given in the example.
  • Connect your Android device/open emulator to your development machine
  • Open a terminal window and navigate to <android-sdk>/tools/  and Run the tool with this command
D:\Rakesh Chityala\Appium\Docmantation\SCREEN SHOTS\UI Automator\UI_automator.png
    1. You will see the following window appear. It is the default window of the UI Automator Viewer.
D:\Rakesh Chityala\Appium\Docmantation\SCREEN SHOTS\UI Automator\UI_Automator_001.png
    1. Open AUT and Click on device icon at the top right corner
D:\Rakesh Chityala\Appium\Docmantation\SCREEN SHOTS\UI Automator\First_winodw.png
    1. It will start taking the UI XML snapshot of the screen currently opened in the device. It would be something like this.
D:\Rakesh Chityala\Appium\Docmantation\SCREEN SHOTS\UI Automator\Capturing_AUT_screen.png

    1. After that, you will see the snapshot of your device screen in the uiautomatorviewer window.
D:\Rakesh Chityala\Appium\Docmantation\SCREEN SHOTS\UI Automator\Captured_screen_of_AUT.png

    1. Need to move the cursor and  click on a particular element to  identify the elements properties
D:\Rakesh Chityala\Appium\Docmantation\SCREEN SHOTS\UI Automator\identifying_the_elements.png


  1. Identifying activity name packagename using  apk file
Method 1:
APK App Info On Google Play [Link]
Method 2:
Step1: Start "adb logcat" in command prompt.
Step2: Open the app (either in emulator or real device) 
D:\Rakesh Chityala\Appium\Docmantation\SCREEN SHOTS\UI Automator\Activity_Name.png
In the above image Activity Name is : com.android.calculator2.Calculator
Package name will be: com.android.calculator2

Method 3:
    1. Open SDK folder and go to build-tools folder.
    2. Open any folder (example: 21.1.2).
    3. Open a command prompt window in this folder ( Shift+ right click – Open command window here).
    4. Run command “aapt list -a “path_to_apk_we_need_to_test”  >manifest.txt” ( this command will write the app manifest in manifest.txt file inside the same folder).
    5. Open the manifest.txt txt file.
    6. At the beginning of the file there should be details about the package including name ( example: com.example.android.contactmanager).
    7. At the end of the file there should be details about activity including name ( example: ContactManager).
Method 4:
We can get package name from the play store URL
D:\Rakesh Chityala\Appium\Docmantation\SCREEN SHOTS\UI Automator\Package_Name.png



  1. Node.js (Not Required - Whenever Appium server is installed, it by default comes with "Node.exe" & NPM. It's included in Current version of Appium.)
  2. Required capabilities before writing the appium code:
    1. Dev ice name
capabilities.setCapability("deviceName","Emulator");

    1. Platform name
capabilities.setCapability("platformName","Android");

    1. Package name
capabilities.setCapability("appPackage", "com.android.calculator2");

    1. Activity Name
capabilities.setCapability("appActivity","com.android.calculator2.Calculator");

    1. Connect with appium serve r using the URL
driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);

  1. Sample Appium code:


package appiumPakage;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
//import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.*;


public class Calculator {
WebDriver driver;

@BeforeClass
public void setUp() throws MalformedURLException{
//Set up desired capabilities and pass the Android app-activity and app-package to Appium
DesiredCapabilities capabilities = new DesiredCapabilities();
//capabilities.setCapability("BROWSER_NAME", "Android");
//capabilities.setCapability("VERSION", "4.4.2");
capabilities.setCapability("deviceName","Emulator");
capabilities.setCapability("platformName","Android");   
  capabilities.setCapability("appPackage", "com.android.calculator2");
// This package name of your app (you can get it from apk info app)
capabilities.setCapability("appActivity","com.android.calculator2.Calculator"); // This is Launcher activity of your app (you can get it from apk info app)

//It will launch the Calculator App in Android Device using the configurations specified in Desired Capabilities
//Create RemoteWebDriver instance and connect to the Appium server
  driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
}

@Test
public void testCal() throws Exception {
  //locate the Text on the calculator by using By.name()
  WebElement two=driver.findElement(By.name("2"));
  two.click();
  WebElement plus=driver.findElement(By.name("+"));
  plus.click();
  WebElement four=driver.findElement(By.name("4"));
  four.click();
  WebElement equalTo=driver.findElement(By.name("="));
  equalTo.click();
  //locate the edit box of the calculator by using By.tagName()
  WebElement results=driver.findElement(By.className("android.widget.EditText"));
//Check the calculated value on the edit box
assert results.getText().equals("6"):"Actual value is : "+results.getText()+" did not match with expected value: 6";

}

@AfterClass
public void teardown(){
//close the app
driver.quit();
}
}