CALABASH -
JENKINS - GIT
AUTOMATED TESTING
ALL YOU
NEED IS
HOW TO TEST ON LOCAL DEVICE?
https://github.com/calabash/calabash-android
CUCUMBER IS
FOR BEHAVIOUR-
DRIVEN
DEVELOPMENT
Someone on Cucumber Website
CUCUMBER
CUCUMBER SCRIPT
▸ Here’s the example for cucumber script
for create scenario testing in human
level (i mean it :) )
▸ If anyone had experience with ruby this
script already used by ruby on rails
testing method with rspec framework
▸ This cucumber will call and parsed on
real ruby files helper with regex method
CUCUMBER
▸ Rules cucumber script
▸ For advance use please check
CUCUMBER SCRIPT
Ex. Touch something
Then I touch “login” button
Then = Represent do this line after doing something for action in first time you can use “Given” with initial
condition ex. (Given I am on “login” page) while check if “login” page really present on screen
touch = Represent the action of this part of scenario it can be “fill”, “swipe”, “wait”, “scroll”, “rotate”, etc.
login = Represent the target for the action you can get this id from query all element in screen
button = Represent the element to test by the action
* Make sure create make sense action for test the scenario because you can use this for random purpose
https://github.com/calabash/calabash-ios/wiki/02-Predefined-steps
CUCUMBER
ACCESSING THE ID OF VIEW PRESENT
Wildan-Garviandi:~/tmp/android$ calabash-android console login.apk
irb(main):001:0> reinstall_apps
=> nil
irb(main):002:0> start_test_server_in_background
=> nil
To get the id of view of present view you can do it via terminal
The result from query all views is :
irb(main):001:0> query("button")
[{"id"=>"login_button",
"enabled"=>true,
"contentDescription"=>nil,
"text"=>"Login",
"qualified_class"=>"android.widget.Button",
"frame"=>{"y"=>322, "height"=>73, "width"=>84, "x"=>135},
"description"=>"android.widget.Button@40584908",
"class"=>"Button"},
{"id"=>"login_button_slow",
"enabled"=>true,
"contentDescription"=>nil,
"text"=>"Login (slow)",
"qualified_class"=>"android.widget.Button",
"frame"=>{"y"=>322, "height"=>73, "width"=>143, "x"=>234},
"description"=>"android.widget.Button@40585390",
"class"=>"Button"}]
RUBY
DEFINE THE CUCUMBER SCENARIO
▸ calabash_steps.rb
You’ll find more than 2 ruby file first one is :
This is class for parsing cucumber .feature files into ruby action
ex.require 'calabash-android/calabash_steps'
# Given I am on the Login Page
Given(/^I am on the Login Page$/) do
page(LoginPage).on_login_page
end
# Then I touch "countrycode text"
Then(/^I touch ("countrycode text")$/) do
page(LoginPage).touch_country_code
end
RUBY
DEFINE THE CUCUMBER SCENARIO
▸ <feature_name>page.rb
The second one is :
This is class is action for all test process with Calabash ruby API more detail on :
ex.
require 'calabash-android/abase'
class LoginPage < Calabash::ABase
def trait
"* text:'Login Page'"
end
@@editTextSearchCountryCode = "* id:'search_et'"
def touch_search_text
touch(@@editTextSearchCountryCode)
end
def insert_phone_number
enter_text(@@phoneNumber, @@phoneNumberToTest)
end
https://github.com/calabash/calabash-ios/wiki/Calabash-iOS-Ruby-API
TEXT
DEFINE THE CUCUMBER SCENARIO
require 'calabash-android/abase'
class LoginPage < Calabash::ABase
def trait
"* text:'Login Page'"
end
@@editTextSearchCountryCode = "* id:’search_et'"
@@phoneNumber = "* marked:'Input your Mobile Number’"
@@phoneNumberToTest = 81615468105
def touch_search_text
touch(@@editTextSearchCountryCode)
end
def insert_phone_number
enter_text(@@phoneNumber, @@phoneNumberToTest)
end
<— this where the id from query used for
}
JENKINS PROCFILE
JENKINS PROCFILE PROCEDURE
▸ run_android_feature
This config file contain all step to running the feature test on jenkins
PARAMS="-p android"
while getopts ":rd:" OPTION; do
case $OPTION in
r)
PARAMS=$PARAMS" --format json -o cucumber.json"
;;
d)
PARAMS=$PARAMS" ADB_DEVICE_ARG=$OPTARG"
;;
[?]) echo "Usage: $0 [-r] [-d DEVICE_ID].n -r: should create reports.n DEVICE_ID: where to run tests.
exit 1;;
esac
done
# clear old files
rm -rf test_servers
# resign apk
bundle exec calabash-android build "/build/outputs/apk/app-debug.apk"
# run tests
bundle exec calabash-android run "/build/outputs/apk/app-debug.apk"
SO ALL YOU NEED
ONLY …▸ <feature_name>.feature on /features
▸ calabash_steps.rb on /features/step_definitions
▸ <feature_name>Page.rb on
/features/support/<feature_name>
▸ And most importent file for running all test at Jenkins is
run_android_feature
GIT
HOW TO RUN YOUR TEST ON JENKINS?
▸ All you need is just merge your feature branch to branch calabash-
test and wait for the test is pass or failure
▸ For more detail if failure or success you can log in to jenkins page
and see the report
JENKINS
CUCUMBER TEST
RESULT
ths is example of report on jenkins for testing scenario
THAT’S IT
AND

Calabash automated test

  • 1.
    CALABASH - JENKINS -GIT AUTOMATED TESTING
  • 2.
    ALL YOU NEED IS HOWTO TEST ON LOCAL DEVICE? https://github.com/calabash/calabash-android
  • 3.
  • 4.
    CUCUMBER CUCUMBER SCRIPT ▸ Here’sthe example for cucumber script for create scenario testing in human level (i mean it :) ) ▸ If anyone had experience with ruby this script already used by ruby on rails testing method with rspec framework ▸ This cucumber will call and parsed on real ruby files helper with regex method
  • 5.
    CUCUMBER ▸ Rules cucumberscript ▸ For advance use please check CUCUMBER SCRIPT Ex. Touch something Then I touch “login” button Then = Represent do this line after doing something for action in first time you can use “Given” with initial condition ex. (Given I am on “login” page) while check if “login” page really present on screen touch = Represent the action of this part of scenario it can be “fill”, “swipe”, “wait”, “scroll”, “rotate”, etc. login = Represent the target for the action you can get this id from query all element in screen button = Represent the element to test by the action * Make sure create make sense action for test the scenario because you can use this for random purpose https://github.com/calabash/calabash-ios/wiki/02-Predefined-steps
  • 6.
    CUCUMBER ACCESSING THE IDOF VIEW PRESENT Wildan-Garviandi:~/tmp/android$ calabash-android console login.apk irb(main):001:0> reinstall_apps => nil irb(main):002:0> start_test_server_in_background => nil To get the id of view of present view you can do it via terminal The result from query all views is : irb(main):001:0> query("button") [{"id"=>"login_button", "enabled"=>true, "contentDescription"=>nil, "text"=>"Login", "qualified_class"=>"android.widget.Button", "frame"=>{"y"=>322, "height"=>73, "width"=>84, "x"=>135}, "description"=>"android.widget.Button@40584908", "class"=>"Button"}, {"id"=>"login_button_slow", "enabled"=>true, "contentDescription"=>nil, "text"=>"Login (slow)", "qualified_class"=>"android.widget.Button", "frame"=>{"y"=>322, "height"=>73, "width"=>143, "x"=>234}, "description"=>"android.widget.Button@40585390", "class"=>"Button"}]
  • 7.
    RUBY DEFINE THE CUCUMBERSCENARIO ▸ calabash_steps.rb You’ll find more than 2 ruby file first one is : This is class for parsing cucumber .feature files into ruby action ex.require 'calabash-android/calabash_steps' # Given I am on the Login Page Given(/^I am on the Login Page$/) do page(LoginPage).on_login_page end # Then I touch "countrycode text" Then(/^I touch ("countrycode text")$/) do page(LoginPage).touch_country_code end
  • 8.
    RUBY DEFINE THE CUCUMBERSCENARIO ▸ <feature_name>page.rb The second one is : This is class is action for all test process with Calabash ruby API more detail on : ex. require 'calabash-android/abase' class LoginPage < Calabash::ABase def trait "* text:'Login Page'" end @@editTextSearchCountryCode = "* id:'search_et'" def touch_search_text touch(@@editTextSearchCountryCode) end def insert_phone_number enter_text(@@phoneNumber, @@phoneNumberToTest) end https://github.com/calabash/calabash-ios/wiki/Calabash-iOS-Ruby-API
  • 9.
    TEXT DEFINE THE CUCUMBERSCENARIO require 'calabash-android/abase' class LoginPage < Calabash::ABase def trait "* text:'Login Page'" end @@editTextSearchCountryCode = "* id:’search_et'" @@phoneNumber = "* marked:'Input your Mobile Number’" @@phoneNumberToTest = 81615468105 def touch_search_text touch(@@editTextSearchCountryCode) end def insert_phone_number enter_text(@@phoneNumber, @@phoneNumberToTest) end <— this where the id from query used for }
  • 10.
    JENKINS PROCFILE JENKINS PROCFILEPROCEDURE ▸ run_android_feature This config file contain all step to running the feature test on jenkins PARAMS="-p android" while getopts ":rd:" OPTION; do case $OPTION in r) PARAMS=$PARAMS" --format json -o cucumber.json" ;; d) PARAMS=$PARAMS" ADB_DEVICE_ARG=$OPTARG" ;; [?]) echo "Usage: $0 [-r] [-d DEVICE_ID].n -r: should create reports.n DEVICE_ID: where to run tests. exit 1;; esac done # clear old files rm -rf test_servers # resign apk bundle exec calabash-android build "/build/outputs/apk/app-debug.apk" # run tests bundle exec calabash-android run "/build/outputs/apk/app-debug.apk"
  • 11.
    SO ALL YOUNEED ONLY …▸ <feature_name>.feature on /features ▸ calabash_steps.rb on /features/step_definitions ▸ <feature_name>Page.rb on /features/support/<feature_name> ▸ And most importent file for running all test at Jenkins is run_android_feature
  • 12.
    GIT HOW TO RUNYOUR TEST ON JENKINS? ▸ All you need is just merge your feature branch to branch calabash- test and wait for the test is pass or failure ▸ For more detail if failure or success you can log in to jenkins page and see the report
  • 13.
    JENKINS CUCUMBER TEST RESULT ths isexample of report on jenkins for testing scenario
  • 14.