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 http://www.mobiletestworld.com/2014/03/launch-and-close-genymotion-emulator-from-command-line.html


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 - http://software.intel.com/en-us/android/articles/installation-instructions-for-intel-hardware-accelerated-execution-manager-mac-os-x

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 -http://www.mobiletestworld.com/2014/02/install-genymotion-fastest-android-emulator-on-mac.html


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 - http://www.mobiletestworld.com/2014/02/fast-android-emulator-haxm-or-genymotion.html

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 persist.sys.country 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 persist.sys.country 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"?>
<resources>
  <string name="september">September</string>
  <string name="shortdate">DD.MM.YYYY</string>
</resources>

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 = REXML::Document.new(File.new(filename))
    all_strings_hash={}
    doc.elements.each("resources/string") do |ele|
      all_strings_hash[ele.attributes["name"]]=ele.text
    end
    return all_strings_hash
end


Common Errors : uninitialized constant ReusableMethods::REXML (NameError)
/Users/tejasvi.manmatha/projects/meine.tui.ui-automation/features/common/support/reusable_methods.rb:106:in `read_xml'
/Users/tejasvi.manmatha/projects/meine.tui.ui-automation/features/common/support/reusable_methods.rb:36:in `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
N=10
for VARIABLE in 1 2 3 4 5 .. N
do
adb shell screencap -p /sdcard/screen$VARIABLE.png
sleep 0.1
done

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

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

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 https://github.com/mayuur/MJTransitionEffect to set up our tests, 


Video : 



Steps:

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 https://github.com/mayuur/MJTransitionEffect

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 - https://developer.apple.com/library/ios/documentation/userexperience/conceptual/tableview_iphone/AboutTableViewsiPhone/AboutTableViewsiPhone.html







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

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)
  end


Scroll to row or section till particular text is found
#Scroll to text in table view
  def scroll_table(text)
    section=0
    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
      end
      section=section+1
    end
  end

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)
      strings||=workbook[0].get_table[:table]

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.

Classes

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

BDD
(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: Welcomepage.new)
  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
  WelcomePage.new(self).wait_for_welcome_screen
  WelcomePage.new(self).navigate_to_login
  LoginPage.new(self).await
end


3) method implementation.
def wait_for_welcome_screen
    wait_for_elements_exist([trait])
end

4)Sample class

class WelcomePage < BasePage

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

  def wait_for_welcome_screen
    wait_for_elements_exist([trait])
  end

  end

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

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
performAction('go_back')



performAction('press_menu')

2) Enter key on virtual key pad 
  performAction('send_key_enter')

3) Swipe right and left / Scroll up down

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


  performAction('scroll_down')
  performAction('scroll_up')


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)
    begin
      wait_poll({:until_exists => "* marked:'#{text}'", :timeout => time_out}) do
        puts "wait_for_page_to_load: checking text #{text}"
      end
    rescue
      return false
    end
    return true
  end

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)
    end
  end

6) Read test data from excel
require 'rubyXL'

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