Google+ Followers

Thursday, 27 February 2014

Install: genymotion fastest android emulator on mac(with screenshots)

To open and control genymotion from command line check this link

Copy app and genymotion shell to applications

Log into genymotion to get list of devices

Choose the device to be created

Select and create the emulator

Open genymotion app from applications and launch emulator

Tuesday, 25 February 2014

Speed up mobile automation with fast android emulator using HAXM or genymotion

To speed up android automation there are 2 options 

1) hardware  acceleration using intel Hardware Accelerated Execution Manager
there are 2 ways to install this

  a) Using android SDK manager (preferred method)
  - Launch  Android SDK Manager.
  - select Intel x86 Emulator Accelerator (HAXM) under Extras
  - Install it 

  b)Manually - look for instructions here -

After installing HAXM create AVD(Android virtual device) 
Creating AVD(Android virtual device) - from android SDK manager , select tools and manage AVD 
and create a new AVD with intel CPU and enabling host GPU. Like shown in below picture

2) second fastest simulator is using genymotion 
check installation screenshots here -

calabash-android: Start emulator , Set language/region/locale and quit using command line

  • Wipe emulator and start again
emulator -wipe-data -avd <avd-name>
TO create avd check here -

Check device is launched or wait

adb wait-for-device
echo "device ready now"
  • set country to germany - de and locale to german- de and restart emulator (this command also works on rooted devices)
adb shell 'setprop persist.sys.language de; setprop de; stop; sleep 5; start'
  • Wait until device is ready
adb wait-for-device
echo "device ready now"
  • Run all commands at once
emulator -wipe-data -avd Android-4.2 &
adb wait-for-device;echo "device ready now";sleep 10
adb shell 'setprop persist.sys.language de; setprop de; stop; sleep 5; start'
adb wait-for-device;echo "device ready now";sleep 20

Wednesday, 19 February 2014

Ruby: How to Read value from strings.xml files

Sample XML format
<?xml version="1.0" encoding="UTF-8"?>
  <string name="september">September</string>
  <string name="shortdate">DD.MM.YYYY</string>

Ruby code to read the XML

resources/string in below must be used to represent the parent child heirarchy

#require the gem and module required
require 'rexml/document'  
#Read language strings by default or else read specified file
# filename can be absolute path or relative path
all_strings_hash will be return value which contains strings and values 
def read_xml(filename="xxx/filename.xml")
    doc =
    doc.elements.each("resources/string") do |ele|
    return all_strings_hash

Common Errors : uninitialized constant ReusableMethods::REXML (NameError)
/Users/tejasvi.manmatha/projects/ `read_xml'
/Users/tejasvi.manmatha/projects/ `get_localized_string'

Solution: put this line at beginning of ruby file require 'rexml/document' 

Android : how to capture screen from adb shell and save them on PC MAC Linux

  • Shell script to copy 10 images at interval of 0.1 seconds and save them on device
for VARIABLE in 1 2 3 4 5 .. N
adb shell screencap -p /sdcard/screen$VARIABLE.png
sleep 0.1

  • Shell script to pull the images from devices and save them on PC / MAC / Linux

for VARIABLE in 1 2 3 4 5 .. N
adb pull /sdcard/screen$VARIABLE.png
sleep 0.1

Sunday, 16 February 2014

Starting calabash ios Testing with simple application Source code + Steps + video

Source Code: Download source code for project , lets use an open source project to set up our tests, 

Video : 


First download the app and compile it 
  • Setup calabash using below command (run this command from folder where project is present)
calabash-ios setup

  • open MJTransitionEffect.xcodeproj file and choose MJTransitionEffect-cal scheme and run the application 
  • Verify below message is shown in xcode 
MJTransitionEffect[14968:a0b] Started LPHTTP server on port 37265

  • Using terminal navigate to folder where application is present and type below command
calabash-ios console 
  • Once you see ruby console run below commands and verify output of below command
MJTransitionEffect $: calabash-ios console 
Running irb...
irb(main):001:0> start_test_server_in_background
irb(main):001:0> touch "view marked:'India'"
irb(main):001:0> touch "view marked:'DONE'"

Finally Thanks to mayuur for such a nice project

Tuesday, 11 February 2014

IOS What are rows and sections , Scroll table view using calabash

Table views in IOS

What are rows and sections ??

A table view has only one column and allows vertical scrolling only. It consists of rows in sections. Each section can have a header and a footer that displays text or an image.

For more details  refer here -

Find value of third tableViewCell in table view by using index:
query("tableViewCell index:2 label",:text)

Scrolling down in IOS table view:
 scroll("tableView", :down)
  scroll "scrollView", :down

Scroll to row 3 in table view
  scroll_to_row "tableView", 2
Scroll to first cell:

Scroll to cell options: 

 {:query => "tableView",
 :row => 0,
 :section => 0,
 :scroll_position => :top,
 :animate => true}

Scroll to each cell and print values of labels
  each_cell(:post_scroll=>0) do |row, sec|
  sleep 0.5
  puts query("tableViewCell indexPath:#{row},#{sec} label",:text)

Scroll to row or section till particular text is found
#Scroll to text in table view
  def scroll_table(text)
    scroll_to_cell(:row => 0, :section => 0)  #scroll to top of table
    sleep 1
#Below code loops through each cell to check if the appropriate text was found
    each_cell(:animate => false, :post_scroll => 0.2) do |row, sec|
      if query("tableViewCell indexPath:#{row},#{sec} label", :text).first==text
        break # if text found break from loop

The above code scroll through to table to find text , 
if you want to click on text , add touch command before break

Ruby method to read from excel (calabash helper)

Ruby code to open excel .xls or .xlsx files and then read it into variable

specify absolute or relative path of file 
then run this below code from ruby  
  file_path= <location of excel file>
      workbook ||= RubyXL::Parser.parse(file_path)

Sunday, 9 February 2014

calabash cross platform extended: calabash ios & Android

I have extended my test suite to follow page / screen object model.

have a look at visual representation of the page object pattern and how does it map on to different files in the test suite.


1) Ibase (ios) and Abase( Android) are base classes for IOS / Android
2) Base page extends base classes further  and implements some functionality that can be used by all classes extending it.
3) Welcome page extends base class and implements methods which are specific to welcome page

(in a typical scenario)
  1. Each step in a feature file will have implementation in step definitions folder
  2. Each step definitions will create a corresponding object of a page (ex:
  3. Each page object will call some calabash method to verify elements (ex: query ) or do actions on app (ex: touch)  which is implement  with in page.

Sample Source code:

1) Feature file -
Scenario: Navigate to login page
    Given I am on login page
    Then I verify login page

2)  Step definition-
Given(/^I am on login page$/) do

3) method implementation.
def wait_for_welcome_screen

4)Sample class

class WelcomePage < BasePage

  def trait
    "* marked:'Start blogging in seconds.'"

  def wait_for_welcome_screen


5) Base page
class BasePage < Calabash::ABase
 # Template for adding commond android methods

Wednesday, 5 February 2014

Steps: to set enviroment variables for calabash android on windows (with screenshots)

  1. Right click on my computer
  2. open Advanced settings -> Environment variables
  3. create new variable 
  4. Put value as 'ANDROID_HOME' and set value as path to android SDK ex: c:\xxxfolder\sdk
    All Steps
  5. Set another variable JAVA_HOME with value as path to JAVA JDK folder 
    Env variable
  6. locate platform-tools under android-sdk folder, copy the path and open PATH env variable , Then  add ';' to end of existing value of path variable. then paste the platform-tools path

  7. Set Android Path
  8.  Repeat step 6 for tools folder located under  android-sdk
  9. Now close terminal or command prompt
  10. relaunch command prompt
  11. type SET  and press enter in command prompt to check if env variables are set
  12. also type 'adb devices' and check if adb command is added to existing path.

Monday, 3 February 2014

calabash android: useful commands

1) back arrow & Menu key


2) Enter key on virtual key pad 

3) Swipe right and left / Scroll up down

  performAction('swipe', 'left')
  performAction('swipe', 'right')


4) wait until time_out (seconds) for particular text to be shown ,
if text is shown return true else false

  def wait_for_page_to_load(text, time_out)
      wait_poll({:until_exists => "* marked:'#{text}'", :timeout => time_out}) do
        puts "wait_for_page_to_load: checking text #{text}"
      return false
    return true

5) Scroll up and down

  def scroll_view(dir)
    if (dir=="up")
      performAction('drag', 50, 50, 70, 90, 10)
    elsif (dir=="down")
      performAction('drag', 50, 50, 90, 70, 10)

6) Read test data from excel
require 'rubyXL'

def read_test_data()
workbook = RubyXL::Parser.parse(file_path)
    hash_arr=workbook[1].get_table(["Surname", "Today"])
    return hash_arr[:table]