SlideShare a Scribd company logo
1 of 68
Download to read offline
Behavior Driven
Development with
Calabash for Android
Teresa Holfeld | Ubilabs
Credits
Teresa Holfeld
Head of Mobile @ Ubilabs
@TeresaHolfeld
Selim Salman
Android Evangelist Engineer
@A_SelimS
Behavior Driven Development
Behavior Driven Development
We want to do Scrum.
We have a Product Owner who can’t code.
This Product Owner has to write Acceptance Criteria for our tickets.
We have to show them that the Acceptance Criteria are met.
Can we agree on some format that makes it easier for both of us?
Behavior Driven Development
Ruby: Cucumber
Language: Gherkin
Behavior Driven Development
Ruby: Cucumber
Language: Gherkin Given <some precondition>
When <some action by the actor>
Then <some testable outcome is achieved>
Behavior Driven Development
Ruby: Cucumber
Language: Gherkin
Mobile: Calabash
● Implements Cucumber
● Uses Gherkin
Given <some precondition>
When <some action by the actor>
Then <some testable outcome is achieved>
Behavior Driven Development
Ruby: Cucumber
Language: Gherkin
Mobile: Calabash
● Implements Cucumber
● Uses Gherkin
Android: Calabash-android
Given <some precondition>
When <some action by the actor>
Then <some testable outcome is achieved>
Gherkin
Gherkin
● Simple Domain Specific Language (DSL) with
natural language constructs
Gherkin
● Simple Domain Specific Language (DSL) with
natural language constructs
Given <some precondition>
When <some action by the actor>
Then <some testable outcome is achieved>
Gherkin
● Simple Domain Specific Language (DSL) with
natural language constructs
Scenario: Multiple Givens
Given one thing
Given another thing
Given yet another thing
When I open my eyes
Then I see something
Then I don't see something else
Gherkin
● Simple Domain Specific Language (DSL) with
natural language constructs
Scenario: Multiple Givens
Given one thing
And another thing
And yet another thing
When I open my eyes
Then I see something
But I don't see something else
Cucumber
Cucumber
Cucumber:
● Software tool for writing automated acceptance tests in BDD
● Gherkin: Given - When - Then
● Origin: Ruby
Cucumber
Cucumber:
● Software tool for writing automated acceptance tests in BDD
● Gherkin: Given - When - Then
● Origin: Ruby
● Java, JavaScript, C#, PHP
Cucumber
Keywords:
● Feature
● Scenario
● Given, When, Then, And, But
● Background
● Scenario Outline
● Examples
Cucumber Feature, Scenario
Feature: Load tracks of the releases of a record label.
Scenario: As a user I want to load all tracks for all records of a given record label.
Given I see the record label “Rivulet Records”
And I see the record “Closed Sessions”
And I see the artist “Various”
When I press “Show all tracks”
And I wait for 3 seconds
Then I see “Sigil Magic, How To Lose Orientation, This Is The Game We Play, So Fi Trance,
Closed Session”
Cucumber Background
Feature: Load tracks of the releases of a record label.
Background:
Given I see a search field
When I type “Rivulet Records” into the search field
And I wait for 3 seconds
Then I see “Rivulet Records” # this is the record label
And I see “Closed Sessions” # this is the album
Scenario: As a user I want to load all tracks for all records of a given record label.
Given I see the record label “Rivulet Records”
And I see the record “Closed Sessions”
And I see the artist “Various”
When I press “Show all tracks”
[...]
Cucumber Scenario Outline, Examples
Scenario: As a user I want to load all tracks for the record “Closed Sessions” of the label
“Rivulet Records”.
Given I see the record label “Rivulet Records”
And I see the record “Closed Sessions”
When I press “Show all tracks”
Then I see “Sigil Magic, How To Lose Orientation, This Is The Game We Play, So Fi Trance,
Closed Session”
Scenario: As a user I want to load all tracks for the record “Floating Woven” of the label
“Paradise Now”.
Given I see the record label “Paradise Now”
And I see the record “Floating Woven”
When I press “Show all tracks”
Then I see “Gerold Dub, Meridia 02509, Floating Woven”
Cucumber Scenario Outline, Examples
Scenario: As a user I want to load all tracks for the record “Closed Sessions” of the label
“Rivulet Records”.
Given I see the record label “Rivulet Records”
And I see the record “Closed Sessions”
When I press “Show all tracks”
Then I see “Sigil Magic, How To Lose Orientation, This Is The Game We Play, So Fi Trance,
Closed Session”
Scenario: As a user I want to load all tracks for the record “Floating Woven” of the label
“Paradise Now”.
Given I see the record label “Paradise Now”
And I see the record “Floating Woven”
When I press “Show all tracks”
Then I see “Gerold Dub, Meridia 02509, Floating Woven”
Cucumber Scenario Outline, Examples
Scenario Outline: As a user I want to load all tracks for a given record of a given label.
Given I see the record label <label>
And I see the record <record>
When I press “Show all tracks”
Then I see <tracks>
Examples:
| label | record | tracks |
| Rivulet Records | Closed Sessions | Sigil Magic, [...] |
| Paradise Now | Floating Woven | Gerold Dub, [...] |
https://cucumber.io/docs/reference
Cucumber Step Definitions
Scenario: As a user I want to load all tracks for all records of a given record label.
Given I see the record label “Rivulet Records”
Given(/I see the record label “([^”]*)”$/) do |label|
puts “Record label: #{label}”
end
Calabash
Calabash
Calabash
Calabash
Calabash
Calabash:
● Framework for automated acceptance tests for iOS and Android
● By Xamarin
Calabash-android:
● Calabash testing framework for Android
● Uses Cucumber + Gherkin
● Ruby
Calabash
How does it work?
Android app wrapper around Robotium
Exposes view hierarchy as HTML server
Calabash Ruby framework talks to this HTML server
Calabash
Image source: https://anadea.info/blog/introduction-to-calabash
Calabash
Calabash
show_tracks.feature
Calabash
calabash_steps.rb
Calabash
Calabash console
Calabash
Calabash console
Calabash
Calabash console
Calabash
Canned steps:
steps the framework already implemented for you
Step Definitions:
how to define your own steps
Ruby API:
what you can use for implementing your own steps
Calabash - Canned Steps
Check if text is there:
Then /^I see "([^"]*)"$/
Then /^I should see "([^"]*)"$/
Calabash - Canned Steps
Check if text is there:
Then /^I see "([^"]*)"$/
Then /^I should see "([^"]*)"$/
Check if text is not there:
Then /^I should not see "([^"]*)"$/
Then /^I don't see "([^"]*)"$/
Calabash - Canned Steps
Input actions:
Then /^I toggle checkbox number (d+)$/ do |index|
Then /^I enter "([^"]*)" into input field number (d+)$/ do |text, index|
Calabash - Canned Steps
Input actions:
Then /^I toggle checkbox number (d+)$/ do |index|
Then /^I enter "([^"]*)" into input field number (d+)$/ do |text, index|
Touching:
Then /^I press the "([^"]*)" button$/ do |text|
Then /^I click on screen (d+)% from the left and (d+)% from the top$/ do |x, y|
Calabash - Canned Steps
Input actions:
Then /^I toggle checkbox number (d+)$/ do |index|
Then /^I enter "([^"]*)" into input field number (d+)$/ do |text, index|
Touching:
Then /^I press the "([^"]*)" button$/ do |text|
Then /^I click on screen (d+)% from the left and (d+)% from the top$/ do |x, y|
Buttons:
Then /^I go back$/
Then /^I press the menu key$/
Calabash - Canned Steps
Gestures:
Then /^I swipe left$/
Then /^I scroll down$/
Calabash - Canned Steps
Gestures:
Then /^I swipe left$/
Then /^I scroll down$/
Waiting:
Then /^I wait for (d+) seconds$/ do |seconds|
Then /^I wait up to (d+) seconds for "([^"]*)" to appear$/ do |timeout, text|
Calabash - Canned Steps
Even more:
https://github.com/calabash/calabash-android/blob/master/ruby-gem/lib/calabash-
android/canned_steps.md
Calabash - Step Definitions
Then(/^I see a map$/) do
map_view = element_exists("MapView")
if not map_view
screenshot_and_raise "No map view found!"
end
end
Calabash - Step Definitions
Setting a geolocation:
Then(/^I set my location to (d+).(d+), (d+).(d+)$/) do |arg1, arg2, arg3, arg4|
lat = "#{arg1}.#{arg2}"
long = "#{arg3}.#{arg4}"
set_gps_coordinates(lat, long)
end
Calabash - Advanced Stuff
Referencing steps:
Given(/^I checked if notes are empty$/) do
steps %Q{
Given I see the "Notes" button
When I press the "Notes" button
Then I see "No notes."
}
end
Calabash - Advanced Stuff
Repeating steps:
Given(/^I entered (d+) note(?:s)?$/) do |n|
for i in 1..n.to_i
steps %Q{
Given I see "New Note"
When I press "New Note"
And I enter "Note #{i}" into the note field
And I press "Save"
Then I see "Note #{i}"
}
end
end
Calabash - Ruby API
> query("FrameLayout index:0")
[
[0] {
"id" => "content",
"enabled" => true,
"contentDescription" => nil,
"class" => "android.widget.FrameLayout",
"rect" => {
"center_y" => 617.0,
"center_x" => 384.0,
"height" => 1134,
"y" => 50,
"width" => 768,
"x" => 0
},
"description" => "android.widget.FrameLayout{41f40dc0 V.E..... ........ 0,50-768,1184 #1020002
android:id/content}"
}
]
Calabash - Ruby API
element_exists(uiquery)
element_does_not_exist(uiquery)
Calabash - Ruby API
element_exists(uiquery)
element_does_not_exist(uiquery)
wait_for_elements_exist(elements_arr, options={})
wait_for_elements_exist( ["button marked:'OK'", "* marked:'Cancel'"], :timeout => 2)
Calabash - Ruby API
fail(msg)
fail(msg="Error. Check log for details.")
Calabash - Ruby API
fail(msg)
fail(msg="Error. Check log for details.")
screenshot(options={:prefix=>nil, :name=>nil})
screenshot({:prefix => "/tmp", :name => "my.png"})
Calabash - Ruby API
fail(msg)
fail(msg="Error. Check log for details.")
screenshot(options={:prefix=>nil, :name=>nil})
screenshot({:prefix => "/tmp", :name => "my.png"})
screenshot_and_raise(msg, options)
screenshot_and_raise(msg="Error. Check log for details.",
options={:prefix => "/tmp", :name => "error.png"})
Calabash - Ruby API
And much more:
https://github.com/calabash/calabash-android/blob/master/documentation/ruby_ap
i.md
Calabash - Documentation and Tutorials
Calabash Android GitHub:
https://github.com/calabash/calabash-android
Calabash Ruby API:
https://github.com/calabash/calabash-android/blob/master/documentation/ruby_ap
i.md
Calabash Developer Site:
https://developer.xamarin.com/guides/testcloud/calabash/
Testmunk Documentation and Tutorials:
https://testmunk.readthedocs.io/en/latest/
Behavior Driven Development
Alternatives
● Cucumber-android + Espresso
● Espresso and comments
● JBehave
● Concordion
● JDave
● Easyb
Yay or nay?
+ Serves as a technical documentation
+ Non-tech staff can understand
+ Enforces well-defined acceptance criteria
+ Easy to run, easy to learn
- Comes with overhead: have to develop steps in Ruby
- You have to implement certain things yourself
(e.g. scrolling in RecyclerView)
- You need to convince your Product Owner to write acceptance criteria m(
Teresa Holfeld
Head of Mobile @ Ubilabs
@TeresaHolfeld
www.ubilabs.net/jobs
And also thank you for listening.
Questions welcome!
Calabash - Advanced Stuff
Resuming an Activity:
Then(/^I resume the app$/) do
system("#{default_device.adb_command} shell am start -n
com.example.calabash.MainActivity")
end
Calabash - Canned Steps
Gestures:
Then /^I swipe left$/
Then /^I swipe right$/
Then /^I scroll down$/
Then /^I scroll up$/
Then /^I select "([^"]*)" from the menu$/ do |identifier|
Then /^I drag from (d+):(d+) to (d+):(d+) moving with (d+) steps$/ do
|from_x, from_y, to_x, to_y, steps|
x:y co-ordinates are expressed as percentages of the screen width:height.
Calabash - Canned Steps
Waiting:
Then /^I wait for 1 second$/ # 1 second
Then /^I wait for a second$/ # 1 second
Then /^I wait$/ # 2 seconds
Then /^I wait for (d+) seconds$/ do |seconds| # specified number of seconds
Calabash - Canned Steps
Waiting:
Then /^I wait for 1 second$/ # 1 second
Then /^I wait for a second$/ # 1 second
Then /^I wait$/ # 2 seconds
Then /^I wait for (d+) seconds$/ do |seconds| # specified number of seconds
Then /^I wait for "([^"]*)" to appear$/ do |text|
Then /^I wait up to (d+) seconds for "([^"]*)" to appear$/ do |timeout, text|
Then /^I wait up to (d+) seconds to see "([^"]*)"$/ do |timeout, †ext|

More Related Content

Viewers also liked

Android Test Driven Development
Android Test Driven DevelopmentAndroid Test Driven Development
Android Test Driven DevelopmentArif Huda
 
Android Test Driven Development
Android Test Driven DevelopmentAndroid Test Driven Development
Android Test Driven Developmentsazilla
 
Android testing calabash
Android testing calabashAndroid testing calabash
Android testing calabashkellinreaver
 
iOS and Android Acceptance Testing with Calabash - Xcake Dublin
iOS and Android Acceptance Testing with Calabash - Xcake DubliniOS and Android Acceptance Testing with Calabash - Xcake Dublin
iOS and Android Acceptance Testing with Calabash - Xcake Dublinroland99
 
Calabash, an open-source automated testing technology for native mobile, by K...
Calabash, an open-source automated testing technology for native mobile, by K...Calabash, an open-source automated testing technology for native mobile, by K...
Calabash, an open-source automated testing technology for native mobile, by K...Codemotion
 
Automated Testing with Ruby
Automated Testing with RubyAutomated Testing with Ruby
Automated Testing with RubyKeith Pitty
 
Introduction to Selenium and Ruby
Introduction to Selenium and RubyIntroduction to Selenium and Ruby
Introduction to Selenium and RubyYnon Perek
 

Viewers also liked (7)

Android Test Driven Development
Android Test Driven DevelopmentAndroid Test Driven Development
Android Test Driven Development
 
Android Test Driven Development
Android Test Driven DevelopmentAndroid Test Driven Development
Android Test Driven Development
 
Android testing calabash
Android testing calabashAndroid testing calabash
Android testing calabash
 
iOS and Android Acceptance Testing with Calabash - Xcake Dublin
iOS and Android Acceptance Testing with Calabash - Xcake DubliniOS and Android Acceptance Testing with Calabash - Xcake Dublin
iOS and Android Acceptance Testing with Calabash - Xcake Dublin
 
Calabash, an open-source automated testing technology for native mobile, by K...
Calabash, an open-source automated testing technology for native mobile, by K...Calabash, an open-source automated testing technology for native mobile, by K...
Calabash, an open-source automated testing technology for native mobile, by K...
 
Automated Testing with Ruby
Automated Testing with RubyAutomated Testing with Ruby
Automated Testing with Ruby
 
Introduction to Selenium and Ruby
Introduction to Selenium and RubyIntroduction to Selenium and Ruby
Introduction to Selenium and Ruby
 

Similar to Behavior driven development with calabash for android

Calabash automated test
Calabash automated testCalabash automated test
Calabash automated testkellinreaver
 
Rugged Driven Development with Gauntlt
Rugged Driven Development with GauntltRugged Driven Development with Gauntlt
Rugged Driven Development with GauntltJames Wickett
 
Cucumber Ru09 Web
Cucumber Ru09 WebCucumber Ru09 Web
Cucumber Ru09 WebJoseph Wilk
 
Strangers In The Night: Ruby, Rack y Sinatra - Herramientas potentes para con...
Strangers In The Night: Ruby, Rack y Sinatra - Herramientas potentes para con...Strangers In The Night: Ruby, Rack y Sinatra - Herramientas potentes para con...
Strangers In The Night: Ruby, Rack y Sinatra - Herramientas potentes para con...Alberto Perdomo
 
Behavior Driven Infrastructure 2011-01
Behavior Driven Infrastructure 2011-01Behavior Driven Infrastructure 2011-01
Behavior Driven Infrastructure 2011-01Jeffrey Hulten
 
Socket applications
Socket applicationsSocket applications
Socket applicationsJoão Moura
 
Monitoring web application behaviour with cucumber-nagios
Monitoring web application behaviour with cucumber-nagiosMonitoring web application behaviour with cucumber-nagios
Monitoring web application behaviour with cucumber-nagiosLindsay Holmwood
 
Acceptance startup fini
Acceptance startup finiAcceptance startup fini
Acceptance startup finiSkills Matter
 
Acceptance testing in the land of the startup
Acceptance testing in the land of the startupAcceptance testing in the land of the startup
Acceptance testing in the land of the startupJoseph Wilk
 
CoffeeScript-Ruby-Tuesday
CoffeeScript-Ruby-TuesdayCoffeeScript-Ruby-Tuesday
CoffeeScript-Ruby-TuesdayEddie Kao
 
Writing Software not Code with Cucumber
Writing Software not Code with CucumberWriting Software not Code with Cucumber
Writing Software not Code with CucumberBen Mabey
 
Ruby on Rails survival guide of an aged Java developer
Ruby on Rails survival guide of an aged Java developerRuby on Rails survival guide of an aged Java developer
Ruby on Rails survival guide of an aged Java developergicappa
 
Hosting Your Own OTA Update Service
Hosting Your Own OTA Update ServiceHosting Your Own OTA Update Service
Hosting Your Own OTA Update ServiceQuinlan Jung
 

Similar to Behavior driven development with calabash for android (20)

Calabash automated test
Calabash automated testCalabash automated test
Calabash automated test
 
Rugged Driven Development with Gauntlt
Rugged Driven Development with GauntltRugged Driven Development with Gauntlt
Rugged Driven Development with Gauntlt
 
Sprockets
SprocketsSprockets
Sprockets
 
Cucumber Ru09 Web
Cucumber Ru09 WebCucumber Ru09 Web
Cucumber Ru09 Web
 
How to eat Cucmber
How to eat CucmberHow to eat Cucmber
How to eat Cucmber
 
Intro to Rails
Intro to RailsIntro to Rails
Intro to Rails
 
Strangers In The Night: Ruby, Rack y Sinatra - Herramientas potentes para con...
Strangers In The Night: Ruby, Rack y Sinatra - Herramientas potentes para con...Strangers In The Night: Ruby, Rack y Sinatra - Herramientas potentes para con...
Strangers In The Night: Ruby, Rack y Sinatra - Herramientas potentes para con...
 
Cucumbered
CucumberedCucumbered
Cucumbered
 
Behavior Driven Infrastructure 2011-01
Behavior Driven Infrastructure 2011-01Behavior Driven Infrastructure 2011-01
Behavior Driven Infrastructure 2011-01
 
Git::Hooks
Git::HooksGit::Hooks
Git::Hooks
 
Laravel Day / Deploy
Laravel Day / DeployLaravel Day / Deploy
Laravel Day / Deploy
 
Socket applications
Socket applicationsSocket applications
Socket applications
 
Monitoring web application behaviour with cucumber-nagios
Monitoring web application behaviour with cucumber-nagiosMonitoring web application behaviour with cucumber-nagios
Monitoring web application behaviour with cucumber-nagios
 
Acceptance startup fini
Acceptance startup finiAcceptance startup fini
Acceptance startup fini
 
Acceptance testing in the land of the startup
Acceptance testing in the land of the startupAcceptance testing in the land of the startup
Acceptance testing in the land of the startup
 
CoffeeScript-Ruby-Tuesday
CoffeeScript-Ruby-TuesdayCoffeeScript-Ruby-Tuesday
CoffeeScript-Ruby-Tuesday
 
Writing Software not Code with Cucumber
Writing Software not Code with CucumberWriting Software not Code with Cucumber
Writing Software not Code with Cucumber
 
Ruby on Rails survival guide of an aged Java developer
Ruby on Rails survival guide of an aged Java developerRuby on Rails survival guide of an aged Java developer
Ruby on Rails survival guide of an aged Java developer
 
Hosting Your Own OTA Update Service
Hosting Your Own OTA Update ServiceHosting Your Own OTA Update Service
Hosting Your Own OTA Update Service
 
Cucumber & BDD
Cucumber & BDDCucumber & BDD
Cucumber & BDD
 

Behavior driven development with calabash for android

  • 1. Behavior Driven Development with Calabash for Android Teresa Holfeld | Ubilabs
  • 2. Credits Teresa Holfeld Head of Mobile @ Ubilabs @TeresaHolfeld Selim Salman Android Evangelist Engineer @A_SelimS
  • 4. Behavior Driven Development We want to do Scrum. We have a Product Owner who can’t code. This Product Owner has to write Acceptance Criteria for our tickets. We have to show them that the Acceptance Criteria are met. Can we agree on some format that makes it easier for both of us?
  • 5. Behavior Driven Development Ruby: Cucumber Language: Gherkin
  • 6. Behavior Driven Development Ruby: Cucumber Language: Gherkin Given <some precondition> When <some action by the actor> Then <some testable outcome is achieved>
  • 7. Behavior Driven Development Ruby: Cucumber Language: Gherkin Mobile: Calabash ● Implements Cucumber ● Uses Gherkin Given <some precondition> When <some action by the actor> Then <some testable outcome is achieved>
  • 8. Behavior Driven Development Ruby: Cucumber Language: Gherkin Mobile: Calabash ● Implements Cucumber ● Uses Gherkin Android: Calabash-android Given <some precondition> When <some action by the actor> Then <some testable outcome is achieved>
  • 10. Gherkin ● Simple Domain Specific Language (DSL) with natural language constructs
  • 11. Gherkin ● Simple Domain Specific Language (DSL) with natural language constructs Given <some precondition> When <some action by the actor> Then <some testable outcome is achieved>
  • 12. Gherkin ● Simple Domain Specific Language (DSL) with natural language constructs Scenario: Multiple Givens Given one thing Given another thing Given yet another thing When I open my eyes Then I see something Then I don't see something else
  • 13. Gherkin ● Simple Domain Specific Language (DSL) with natural language constructs Scenario: Multiple Givens Given one thing And another thing And yet another thing When I open my eyes Then I see something But I don't see something else
  • 15. Cucumber Cucumber: ● Software tool for writing automated acceptance tests in BDD ● Gherkin: Given - When - Then ● Origin: Ruby
  • 16. Cucumber Cucumber: ● Software tool for writing automated acceptance tests in BDD ● Gherkin: Given - When - Then ● Origin: Ruby ● Java, JavaScript, C#, PHP
  • 17. Cucumber Keywords: ● Feature ● Scenario ● Given, When, Then, And, But ● Background ● Scenario Outline ● Examples
  • 18. Cucumber Feature, Scenario Feature: Load tracks of the releases of a record label. Scenario: As a user I want to load all tracks for all records of a given record label. Given I see the record label “Rivulet Records” And I see the record “Closed Sessions” And I see the artist “Various” When I press “Show all tracks” And I wait for 3 seconds Then I see “Sigil Magic, How To Lose Orientation, This Is The Game We Play, So Fi Trance, Closed Session”
  • 19. Cucumber Background Feature: Load tracks of the releases of a record label. Background: Given I see a search field When I type “Rivulet Records” into the search field And I wait for 3 seconds Then I see “Rivulet Records” # this is the record label And I see “Closed Sessions” # this is the album Scenario: As a user I want to load all tracks for all records of a given record label. Given I see the record label “Rivulet Records” And I see the record “Closed Sessions” And I see the artist “Various” When I press “Show all tracks” [...]
  • 20. Cucumber Scenario Outline, Examples Scenario: As a user I want to load all tracks for the record “Closed Sessions” of the label “Rivulet Records”. Given I see the record label “Rivulet Records” And I see the record “Closed Sessions” When I press “Show all tracks” Then I see “Sigil Magic, How To Lose Orientation, This Is The Game We Play, So Fi Trance, Closed Session” Scenario: As a user I want to load all tracks for the record “Floating Woven” of the label “Paradise Now”. Given I see the record label “Paradise Now” And I see the record “Floating Woven” When I press “Show all tracks” Then I see “Gerold Dub, Meridia 02509, Floating Woven”
  • 21. Cucumber Scenario Outline, Examples Scenario: As a user I want to load all tracks for the record “Closed Sessions” of the label “Rivulet Records”. Given I see the record label “Rivulet Records” And I see the record “Closed Sessions” When I press “Show all tracks” Then I see “Sigil Magic, How To Lose Orientation, This Is The Game We Play, So Fi Trance, Closed Session” Scenario: As a user I want to load all tracks for the record “Floating Woven” of the label “Paradise Now”. Given I see the record label “Paradise Now” And I see the record “Floating Woven” When I press “Show all tracks” Then I see “Gerold Dub, Meridia 02509, Floating Woven”
  • 22. Cucumber Scenario Outline, Examples Scenario Outline: As a user I want to load all tracks for a given record of a given label. Given I see the record label <label> And I see the record <record> When I press “Show all tracks” Then I see <tracks> Examples: | label | record | tracks | | Rivulet Records | Closed Sessions | Sigil Magic, [...] | | Paradise Now | Floating Woven | Gerold Dub, [...] | https://cucumber.io/docs/reference
  • 23. Cucumber Step Definitions Scenario: As a user I want to load all tracks for all records of a given record label. Given I see the record label “Rivulet Records” Given(/I see the record label “([^”]*)”$/) do |label| puts “Record label: #{label}” end
  • 28. Calabash Calabash: ● Framework for automated acceptance tests for iOS and Android ● By Xamarin Calabash-android: ● Calabash testing framework for Android ● Uses Cucumber + Gherkin ● Ruby
  • 29. Calabash How does it work? Android app wrapper around Robotium Exposes view hierarchy as HTML server Calabash Ruby framework talks to this HTML server
  • 34.
  • 38. Calabash Canned steps: steps the framework already implemented for you Step Definitions: how to define your own steps Ruby API: what you can use for implementing your own steps
  • 39. Calabash - Canned Steps Check if text is there: Then /^I see "([^"]*)"$/ Then /^I should see "([^"]*)"$/
  • 40. Calabash - Canned Steps Check if text is there: Then /^I see "([^"]*)"$/ Then /^I should see "([^"]*)"$/ Check if text is not there: Then /^I should not see "([^"]*)"$/ Then /^I don't see "([^"]*)"$/
  • 41. Calabash - Canned Steps Input actions: Then /^I toggle checkbox number (d+)$/ do |index| Then /^I enter "([^"]*)" into input field number (d+)$/ do |text, index|
  • 42. Calabash - Canned Steps Input actions: Then /^I toggle checkbox number (d+)$/ do |index| Then /^I enter "([^"]*)" into input field number (d+)$/ do |text, index| Touching: Then /^I press the "([^"]*)" button$/ do |text| Then /^I click on screen (d+)% from the left and (d+)% from the top$/ do |x, y|
  • 43. Calabash - Canned Steps Input actions: Then /^I toggle checkbox number (d+)$/ do |index| Then /^I enter "([^"]*)" into input field number (d+)$/ do |text, index| Touching: Then /^I press the "([^"]*)" button$/ do |text| Then /^I click on screen (d+)% from the left and (d+)% from the top$/ do |x, y| Buttons: Then /^I go back$/ Then /^I press the menu key$/
  • 44. Calabash - Canned Steps Gestures: Then /^I swipe left$/ Then /^I scroll down$/
  • 45. Calabash - Canned Steps Gestures: Then /^I swipe left$/ Then /^I scroll down$/ Waiting: Then /^I wait for (d+) seconds$/ do |seconds| Then /^I wait up to (d+) seconds for "([^"]*)" to appear$/ do |timeout, text|
  • 46. Calabash - Canned Steps Even more: https://github.com/calabash/calabash-android/blob/master/ruby-gem/lib/calabash- android/canned_steps.md
  • 47. Calabash - Step Definitions Then(/^I see a map$/) do map_view = element_exists("MapView") if not map_view screenshot_and_raise "No map view found!" end end
  • 48. Calabash - Step Definitions Setting a geolocation: Then(/^I set my location to (d+).(d+), (d+).(d+)$/) do |arg1, arg2, arg3, arg4| lat = "#{arg1}.#{arg2}" long = "#{arg3}.#{arg4}" set_gps_coordinates(lat, long) end
  • 49. Calabash - Advanced Stuff Referencing steps: Given(/^I checked if notes are empty$/) do steps %Q{ Given I see the "Notes" button When I press the "Notes" button Then I see "No notes." } end
  • 50. Calabash - Advanced Stuff Repeating steps: Given(/^I entered (d+) note(?:s)?$/) do |n| for i in 1..n.to_i steps %Q{ Given I see "New Note" When I press "New Note" And I enter "Note #{i}" into the note field And I press "Save" Then I see "Note #{i}" } end end
  • 51. Calabash - Ruby API > query("FrameLayout index:0") [ [0] { "id" => "content", "enabled" => true, "contentDescription" => nil, "class" => "android.widget.FrameLayout", "rect" => { "center_y" => 617.0, "center_x" => 384.0, "height" => 1134, "y" => 50, "width" => 768, "x" => 0 }, "description" => "android.widget.FrameLayout{41f40dc0 V.E..... ........ 0,50-768,1184 #1020002 android:id/content}" } ]
  • 52. Calabash - Ruby API element_exists(uiquery) element_does_not_exist(uiquery)
  • 53. Calabash - Ruby API element_exists(uiquery) element_does_not_exist(uiquery) wait_for_elements_exist(elements_arr, options={}) wait_for_elements_exist( ["button marked:'OK'", "* marked:'Cancel'"], :timeout => 2)
  • 54. Calabash - Ruby API fail(msg) fail(msg="Error. Check log for details.")
  • 55. Calabash - Ruby API fail(msg) fail(msg="Error. Check log for details.") screenshot(options={:prefix=>nil, :name=>nil}) screenshot({:prefix => "/tmp", :name => "my.png"})
  • 56. Calabash - Ruby API fail(msg) fail(msg="Error. Check log for details.") screenshot(options={:prefix=>nil, :name=>nil}) screenshot({:prefix => "/tmp", :name => "my.png"}) screenshot_and_raise(msg, options) screenshot_and_raise(msg="Error. Check log for details.", options={:prefix => "/tmp", :name => "error.png"})
  • 57. Calabash - Ruby API And much more: https://github.com/calabash/calabash-android/blob/master/documentation/ruby_ap i.md
  • 58. Calabash - Documentation and Tutorials Calabash Android GitHub: https://github.com/calabash/calabash-android Calabash Ruby API: https://github.com/calabash/calabash-android/blob/master/documentation/ruby_ap i.md Calabash Developer Site: https://developer.xamarin.com/guides/testcloud/calabash/ Testmunk Documentation and Tutorials: https://testmunk.readthedocs.io/en/latest/
  • 60. Alternatives ● Cucumber-android + Espresso ● Espresso and comments ● JBehave ● Concordion ● JDave ● Easyb
  • 61. Yay or nay? + Serves as a technical documentation + Non-tech staff can understand + Enforces well-defined acceptance criteria + Easy to run, easy to learn - Comes with overhead: have to develop steps in Ruby - You have to implement certain things yourself (e.g. scrolling in RecyclerView) - You need to convince your Product Owner to write acceptance criteria m(
  • 62. Teresa Holfeld Head of Mobile @ Ubilabs @TeresaHolfeld
  • 63.
  • 64. www.ubilabs.net/jobs And also thank you for listening. Questions welcome!
  • 65. Calabash - Advanced Stuff Resuming an Activity: Then(/^I resume the app$/) do system("#{default_device.adb_command} shell am start -n com.example.calabash.MainActivity") end
  • 66. Calabash - Canned Steps Gestures: Then /^I swipe left$/ Then /^I swipe right$/ Then /^I scroll down$/ Then /^I scroll up$/ Then /^I select "([^"]*)" from the menu$/ do |identifier| Then /^I drag from (d+):(d+) to (d+):(d+) moving with (d+) steps$/ do |from_x, from_y, to_x, to_y, steps| x:y co-ordinates are expressed as percentages of the screen width:height.
  • 67. Calabash - Canned Steps Waiting: Then /^I wait for 1 second$/ # 1 second Then /^I wait for a second$/ # 1 second Then /^I wait$/ # 2 seconds Then /^I wait for (d+) seconds$/ do |seconds| # specified number of seconds
  • 68. Calabash - Canned Steps Waiting: Then /^I wait for 1 second$/ # 1 second Then /^I wait for a second$/ # 1 second Then /^I wait$/ # 2 seconds Then /^I wait for (d+) seconds$/ do |seconds| # specified number of seconds Then /^I wait for "([^"]*)" to appear$/ do |text| Then /^I wait up to (d+) seconds for "([^"]*)" to appear$/ do |timeout, text| Then /^I wait up to (d+) seconds to see "([^"]*)"$/ do |timeout, †ext|