Showing posts with label hybrid applications. Show all posts
Showing posts with label hybrid applications. Show all posts

Sunday, 17 August 2014

Android Automation With Appium

In previous blogs we saw the process to setup Android Webdriver and Selendroid, which was used to automate Android Web Applications. The process to setup Appium is not much different, we require same set of tools except ‘Appium’ to start automating native, hybrid and mobile web applications.

Little introduction about Appium: Appium is an open source, cross platform test automation tool for mobile applications, hosted with GitHub. It supports Native, Hybrid and Mobile Web Applications. It is based on WebDriver JSON wire protocol.

Automation support for:
  1. iOS Mobile
  2. Android
  3. Firefox mobile OS
Test Modalities:
  1. Android
    1. Real Devices
    2. Emulators
    3. Native Browser
    4. Mobile Chrome
  2. iOS
    1. Real Devices
    2. Simulators
    3. Mobile Safari
Limitations:
  1. Android
  2. iOS
    • Need mac OSX 10.7+, lower versions not supported
Let’s start with the implementation, Following are the pre-requisites to start with:
  1. Java IDE (eg: Eclipse)
  2. Java Development Kit
  3. Maven Plugin for Eclipse (To create a maven project, you can create simple Java project)
  4. TestNG Plugin for Eclipse
  5. Android SDK
  6. Appium Server
Then, we need following configured:
  1. Environment Variables and Path Settings
    1. JAVA_HOME
    2. ANDROID_HOME
    3. MAVEN_HOME
  2. Android platform version 4.2+ must be installed.
Now, we will create a maven project.

Create a Maven project and open the pom.xml file. Add following artifacts to pom.xml and save the project:

image

Navigate to project >> Add a package >> Add a class:

In the below screen-shot as you can see I have created the instance of DesiredCapabilities and added some information to provide the Appium Server. We will see the relevance of each capability mentioned here.

image
  1. capabalities.setCapability("browserName", "") : It is used to tell the server which browser my script is going to use in case of mobile web automation, since we are automating here Native/Hybrid application so we will leave the value blank.
  2. capabalities.setCapability("deviceName", "emulator-5554") : It is used to tell the server on which device your script will run the automation. The value for device name can be achieved by running a command:     image
  3. capabalities.setCapability("platformVersion", "4.4") : It is used to tell the server which platform version is used.
  4. capabalities.setCapability("platformName", "Android") : It is used to tell the server which platform is used such as Android or iOS.
  5. capabalities.setCapability("appPackage", "com.SKSDroid.contactlistapp") : It is used to tell the package name for the application is being automated. To get the application package follow the steps:
    1. Create a folder named ‘app’ in the project created.
    2. Copy the application .apk file and paste in ‘app’ folder.
    3. Now navigate to : Windows >> Open Perspective >> Hierarchy View.
  6. capabalities.setCapability("appActivity", ".MainActivity") : It is used to tell the name of application activity on which will be the landing page for application when it will start.
  7. capabalities.setCapability("appWaitActivity", ".MainActivity") : It is used to tell the server to wait for the activity to appear before running the automation script.
As you can see in the below screen-shot of Hierarchy View, Device is listed with the opened application’s package name and active activity name which we have set in the capability. It will be updated as soon as you navigate to different activities.

image

Now finally it’s time to write test script. See the below code snippet in which we are just asserting a text of an element and clicking on it:

image

As you can see in the snippet we are using ID attribute to identify the element, so the question here is how to get the attributes of an element ? The answer is ‘UI Automator Viewer’. To start the UI Automator Viewer, go to tools directory of android sdk,open command prompt and write the command:

image

It will launch the UI Automator Viewer. Click on Device Screenshot button to generate the XML screenshot, and by hovering on the items you can see the attributes and values available for the element.

image

Once we are done with all above procedures, we will run the script. To run the script we first need to start the Appium Server. To start the Appium Server go to the downloaded folder ‘AppiumForWindows’ and double click on ‘Appium.exe’ to launch it. Click Start button to start the server on default ip address and port which is : 127.0.0.1:4723

image

Go to Eclipse and Run the script as ‘TestNG Test’. It will run the application on emulator and will perform the steps written in test script.

image

Please stay tuned to see more updates.

Facebook Page: https://www.facebook.com/crazzzygig

Friday, 27 June 2014

Selendroid to Test Mobile Web Applications on Android Mobile Device

Selendroid is a test automation framework which drives off the Android native, hybrid and the mobile web applications. All the tests are written using the Selenium 2 client API.

In previous blog we saw that how to use Android Webdriver to automate the mobile web apps, since Android Webdriver has been deprecated and recommended to use Selendroid.

In this article we will see how to setup Selendroid and will also see example of mobile web application automation. Since Selendroid does not provide the facility to create the virtual devices, hence we will use the same instructions we followed in previous article (Mobile Automation With Android WebDriver).

Pre-Requisites:
Download Android SDK
Unzip it and place it somewhere in directory
Go to /android_sdk/eclipse folder
Launch Eclipse and Select a workspace location
Now navigate Windows >> Preferences >> Run/Debug >> String Substitution
Click New button to add a variable


Now open System Properties and add a variable ANDROID_SDK_HOME


Add a user variable ANDROID_HOME


Check if JAVA_HOME variable is not set then add it as well


Steps to Setup Emulator

      1. To list all the available targets run:




2. First create the Android Virtual Device (AVD)

3. Now start the emulator

And it will start the emulator:


Now download the selendroid-standalone (Selendroid-standalone) jar file.

Creation of automation script

1. Start the eclipse from /android_sdk/eclipse location.

2. Create a project and add selendroid-standalone.jar along with Selenium 2 client API.

see the code snippet for the example:


Now run the code as java application.

Output:


In next article we will see how to identify elements of mobile version web applications.

Please like the page if you like it.