Sunday, March 2, 2014

Android Web App Test Automation

Tool Options :
1. Appium --> only chrome browser
2. Selendroid --> only default browser
3. Chromedriiver with SDK --> only chrome browser

Limitations:
1, Supporting tools are not well developed
2, Device specific gesture are missing
3. Features are not equally supported on all versions

Future:
1. ChromeDriver will become strong contender, as chrome on android is getting more popular
2. Screencast and remote debugging by chromedriver

## Appium
#python-appium >> appium server should be running
from selenium import webdriver
capabilities = {
  'device' : 'Android',
  'platform' : 'WINDOWS',
  'version' : '4.2.2',
  'app': "Chrome"
}
driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', capabilities)
driver.get('http://google.com')
inputElement = driver.find_element_by_name("q")
inputElement.send_keys("cheese!")
inputElement.submit()
driver.save_screenshot("some.png")
driver.quit()

#ruby-appium>>  appium server should be running
require 'selenium-webdriver'
capabilities = {
  'device' => 'Android',
  'platform' => 'WINDOWS',
  'version' => '4.2.2',
  'app' => "Chrome"
}
server_url = "http://127.0.0.1:4723/wd/hub"
driver = Selenium::WebDriver.for(:remote, :desired_capabilities => capabilities, :url => server_url)
driver.get("http://www.google.com")
element = driver.find_element :name => "q"
element.send_keys "Cheese!"
element.submit
driver.save_screenshot "some.png"
driver.quit()

## Selendroid
#python-selendroid  >>  selendroid server should be running
from selenium import webdriver
driver  = webdriver.Remote(desired_capabilities=webdriver.DesiredCapabilities.ANDROID)
driver.get('http://google.com')
inputElement = driver.find_element_by_name("q")
inputElement.send_keys("cheese!")
inputElement.submit()
driver.save_screenshot("some.png")
driver.quit()

#ruby-selendroid >> selendroid server should be running
require 'selenium-webdriver'
driver = Selenium::WebDriver.for :remote, :desired_capabilities => :android
driver.get("http://www.google.com")
element = driver.find_element :name => "q"
element.send_keys "Cheese!"
element.submit
driver.save_screenshot "some.png"
driver.quit()

## ChromeDriver
#python-chromedriver >> chromedriver server and adb server should be running
from selenium import webdriver
capabilities = {
  'chromeOptions': {
    'androidPackage': 'com.android.chrome',
  }
}
driver = webdriver.Remote('http://localhost:9515', capabilities)
driver.get('http://google.com')
inputElement = driver.find_element_by_name("q")
inputElement.send_keys("cheese!")
inputElement.submit()
driver.save_screenshot("some.png")
driver.quit()

#ruby-chromedriver
require 'selenium-webdriver'
capabilities = {
  'chromeOptions'=> {
    'androidPackage' => 'com.android.chrome',
  }
}
server_url = "http://127.0.0.1:9515/wd/hub"
driver = Selenium::WebDriver.for(:remote, :desired_capabilities => capabilities, :url => server_url)
driver.get("http://www.google.com")
element = driver.find_element :name => "q"
element.send_keys "Cheese!"
element.submit
driver.save_screenshot "some.png"
driver.quit()

Wednesday, October 16, 2013

Script-less Test Automation Framework/Tool

What is Script-less?

In Strict Sense--
A Framework that takes a collection of values; objects, methods and data ; runs them through a process that builds a script/code in memory, invokes and execute the underlying Test tool/libraries at run time. The actual script component never exists in the real world it only exists while the process is running.

however the framework does need to allow for scripted(coded) components to be called and run from same process that may not be easy to write in a keyword/code-less manner.Framework does not generate any code/script.

High Level Approach.

A set of libraries and modules that take keywords, objects, methods and data stored in Database and assembles a script in memory at run-time. The libraries and modules already have fine tuned code to handle exceptions and reporting.


Monday, October 14, 2013

Appium on windows - Android automation using ruby

Prerequisite -

  1. Android SDK with API level 17 and above is available.
  2. Ruby 1.9 and selenium - webdriver gem is installed.
  3. OS variable ANDROID_HOME is pointing to SDK folder


Here are Quick Steps to Setup and Run Sample App using ruby selenium webdriver.


  1. Download latest Appium for Windows from https://bitbucket.org/appium/appium.app/ , unzip it.
  2. Start Emulator or Connect your Device using USB.
  3. Download ContactManager.apk from https://github.com/appium/appium/tree/master/sample-code/apps/ContactManager
  4. adb install ContactManager.apk.
  5. Click on Appium.exe from unzipped folder and Start Appium Server by clicking on Launch Button with Default parameters.
  6. Run below ruby code from cmd / irb 

------------------------------------------------------------



require 'selenium-webdriver'

capabilities = {
'device' => 'Android',
  'browserName' => '',
  'platform' => 'WINDOWS',
  'version' => '4.2.2',
  #'app' => 'http://localhost/ContactManager.apk',
'app-package' => 'com.example.android.contactmanager',
'app-activity' => 'ContactManager'
}

server_url = "http://127.0.0.1:4723/wd/hub"

@driver = Selenium::WebDriver.for(:remote, :desired_capabilities => capabilities, :url => server_url)

btadd = @driver.find_element(:name, "Add Contact")
btadd.click()

textfields = @driver.find_elements(:tag_name,"textfield")
textfields[0].send_keys("Android_Appium")
textfields[2].send_keys("Android@Appium.com")
@driver.find_element(:name, "Save").click()

@driver.quit()


-----------------------------------------------




Web Test Automation Framework - Capybara vs Keyword-Driven

Web Test Automation Options - using pre-built DSL like capybara along with Cucumber to make it more collaborative exercise between Functional and Automation experts or creating a framework having collection of constructs(Keywords) to do basic operations on web app and later arranging them in a sequence to perform Test Flow.