How to read the text from an Alert(ios) in calabash ?

Hi guys,

It’s been a long time that I don’t post anything about calabash and mobile automation, but I found this in my favorites and I realized that could be useful for someone. I am not sure if doesn’t exist another way to read a text inside an Alert, but this is one of the solutions:

Example of step:

Then I see a popup with latitude 10 and longitude 20



Then /^I see a popup with latitude (\d+) and longitude (\d+)$/ do |lat, lon| 
  msg = "Latitude:#{lat}\nLongitude:#{lon}" 
  should_see_alert_with_text msg 


def should_see_alert_with_text (text) 
wait_poll(:until_exists => 'alertView', :timeout => 5) do
  actual = query('alertView child label', :text).first
  unless actual.eql? text 
    screenshot_and_raise "should see alert view with message '#{text}' 
but found '#{actual}'" 


Thank you ! See you 🙂



Filtering an element using its property in arrays – calabash

Hello again,

More one tip about filtering the element in an array, using some of the properties that you want (text content, position, id, class, html, etc…). In this example, I am finding the array of elements with the specific CSS and after I am returning the element where the property “TextContent” equals a Login.

menu = query("WebView index:0 css:'div li span'").find { |x|
x["textContent"] == "Login" }


menu = query("WebView index:0 css:'div li span'", :textContent).find { |x| 
x == "Login" }

In this other example, I am returning the element which contains specific text inside of the property “html“.

menu_figure = query("WebView index:0 css:'div li span'").find { |x| 
x["html"].include? ("figure") }


menu_figure = query("WebView index:0 css:'div li span'", :html).find { |x| 
x.include? ("figure") }


If you have any question/suggestion, just let me know.

Thank you guys ! See you next week 🙂

Swipe and Drag – Calabash iOS and Android

Hi guys !!
I am writing examples of swipe and drag on mobile devices with calabash today. Some methods that you can use to test, these drags have the same action as the swipe. (If for some reason the swipe don’t work)
  def swipe_page_to_left
    performAction('swipe', 'left')

  def swipe_page_to_right
    performAction('swipe', 'right')

  def scroll_to_right
    performAction('drag', 90, 0, 50, 50, 50)

  def scroll_to_left
    performAction('drag', 0, 90, 50, 50, 50)

def scroll_to_up
   performAction('drag', 88, 80, 90, 90, 5)

 def scroll_to_down
    performAction('drag', 70, 10, 80, 0, 3)

Change to down, left or right:


If you have some question or suggest just write below !
Thank you 🙂

Commands to use running Cucumber

Hi guys, I am writing here the commands to use when you run cucumber on Automation. It is very usefully 🙂

Launching and Customizing launch

Calabash has two ways of launching apps: SimLauncher and Apple’s instruments tool. Each has its own advantages and problems (see below).

For iOS7+ only the instruments launch method is supported. If instruments is not used to automatically launch the app touch events wont work.

Since version 0.9.154, Calabash is using instruments and UIAutomation to launch apps by default. The primary reason for this is two-fold: (a) in iOS7, Apple removed access to APIs previously used to synthesize touch events and we needed a different approach, (b) there are things possible with UIA that are not possible from “inside the app”, i.e., in the Calabash server (like accepting the Access to current location dialog or sending the app to the background).

The launch method can be controlled using environment variables. With Calabash 0.9.157+, the use of environment variables was greatly simplified. If you’re updating from a previous version, it is recommended to try removing all the environment variables, and then adding only the ones you’re sure you need.

  • DEVICE_TARGET controls which device to launch on. When set Calabash uses instruments to launch. The default is ‘simulator’ (see also Testing on Physical iDevices). You can also setDEVICE_TARGET=device or DEVICE_TARGET=UDID_OF_CONNECTED_DEVICE to pick a specific connected device, or DEVICE_TARGET=simulator to force use of instruments and simulator. (You can see the UDID of your device in the Devices tab in Xcode’s Organizer window).
  • SDK_VERSION is only used when running on the simulator. It controls which iOS version of the simulator is launched. Note, SDK_VERSION forces the launch method to be SimLauncher (not instruments). The reason for this is that the instruments tool does not support launching a simulator that is not the latest version.
  • DEVICE=ipad if you want to ensure we launch the iPad simulator. Defaults to ‘iphone’.
  • OS is deprecated and now automatically detected (it was previously used to decide which “recordings” to use for playback).
  • NO_LAUNCH is not supported when running with instruments. It tells Calabash to not automatically launch the app (it is mostly used when you want to start the app yourself – should rarely be used).
  • NO_STOP means don’t stop the app after the test completes. (It is mostly used to leave the app open in case of a test failure and should be used for debugging purposes only).
  • RESET_BETWEEN_SCENARIOS (example: RESET_BETWEEN_SCENARIOS=1) – Reset iOS Simulator between each scenario.


$ SDK_VERSION=6.1 DEVICE=ipad cucumber 

Explore interactively!

To start-up a console, you can run the command: calabash-ios console and then start a simulator withstart_test_server_in_background for iOS7 to get touch events to work.

Try starting your app using the -cal scheme from Xcode and then run calabash-ios console. This will give you a Calabash console (it is just a Ruby irb with calabash loaded).

From this console you can explore your application interactively.

You can query, touch, scroll, etc from the irb session. This information below also serves as an introduction for the APIs that are available in other place.


If your app have two buttons. Try this from the console:

irb > query("button") 

You should see something like this:

=> [{"class"=>"UIRoundedRectButton", frame"=>
{"y"=>287, "width"=>72, "x"=>100, 
"height"=>37}, "UIType"=>"UIControl", 
"description"=>"<UIRoundedRectButton: 0x7d463d0; 
frame = (100 287; 72 37); opaque = NO; autoresize = RM+BM;
 layer = <CALayer: 0x7d46ae0>>"}, 
{"class"=>"UIRoundedRectButton", "frame"=>
{"y"=>215, "width"=>73, "x"=>109, 
"height"=>37}, "UIType"=>"UIControl", 
"description"=>"<UIRoundedRectButton: 0x7d3a760; 
frame = (109 215; 73 37); opaque = NO; autoresize = RM+BM;
 layer = <CALayer: 0x7d3a8a0>>"}] 

This is actually an array with two objects that are descriptions of the two buttons. For example, the class of the first button is “UIRoundedRectButton”. We can dive into this information using Ruby programming:

irb > result = query("button") ... irb > btn1 = 
result[0] ... irb > class1 = btn1["class"] => 

The query function takes a string query as an argument. The query argument is similar to a css selector, for example we can do:

irb > query("button index:0 label") => 
[{"class"=>"UIButtonLabel", "frame"=>{"y"=>9, 
"width"=>38, "x"=>17, "height"=>19}, "UIType"=>"UIView", 
"description"=>"<UIButtonLabel: 0x7d41120; frame = 
(17 9; 38 19); text = 'other'; clipsToBounds = YES; opaque 
= NO; userInteractionEnabled = NO; layer = <CALayer: 

This means “find the first button, and then inside of that find all labels”.

Query may also take parameters that are mapped to Objective-C selectors on the found object.

irb > query("button index:0 label", :text) => 

Query is very powerful, but the full syntax and power of query is beyond the scope of the Getting started guide on GitHub.


Anything that can be found using query can also be touched. Try this while you watch the iOS Simulator:

irb > touch("button index:0") 

Notice that the button is touched (turns blue), although this button doesn’t do anything.

You can also touch the tab bars:

irb > touch("tabBarButton index:1") 

The filter: index:1 means that it is the second tab-bar button that should be touched.

Setting accessibility

Identifiers and accessibility


In general UI views are found using accessibility ids or labels. Go to the “First” tab in simulator, and then in your console session try this:

# query for the switch on the "First" tab irb > 
query("view marked:'switch'") [ [0] { "class" => 
"UISwitch", "frame" => { "y" => 148, "width" => 
79, "x" => 106, "height" => 27 }, "UIType" => 
"UIControl", "description" => "<UISwitch: 0x7d3ffb0; 
frame = (106 148; 79 27); <snip> >>" } ] 

You can set the accessibility attributes of UIView from the Interface Builder or programmatically.

In some cases the UIKit framework will set the accessibilityLabel for you if you don’t explicitly set the value.

For example, UITabBarButton will have an accessibility label that is the same as title of the tab bar button.

irb > query("tabBarButton marked:'Second'") [ [0] {
 "class" => "UITabBarButton", "id" => nil, "rect" 
=> { "center_x" => 120, "y" => 520, "width" =>
 76, "x" => 82, "center_y" => 544, "height" => 48 
}, "frame" => { "y" => 1, "width" => 76, "x" =>
 82, "height" => 48 }, "label" => "Second", 
"description" => "<UITabBarButton: 0x857e010; frame = 
(82 1; 76 48); <snip> >" } ] 

Whenever possible, you should use the accessibilityIdentifier of UIView and reserve the accessibilityLabel for providing localized Accessibility traits.

- (void) viewDidLoad { [super viewDidLoad]; UISwitch 
*switch = self.wantsCoffeeSwitch; # ex. queries # query 
"view marked:'wants coffee'" # query "switch 
{accessibilityIdentifier LIKE 'wants coffee'}" # query 
"switch marked:'wants coffee'" 
switch.accessibilityIdentifier = @"wants coffee"; # 
accessibilityLabels should be localized and follow the 
conventions # described by Apple's Accessibility 
documentation if (switch.isOn == YES) { 
switch.accessibilityLabel = NSLocalizedString(@"Wants 
coffee"); } else { switch.accessibilityLabel = 
NSLocalizedString(@"Does not want coffee"); } } 


Thank you guys ! If you have any question, just write below. Bye !!

Cucumber and the steps

Hello everybody !

Now you can write your steps in cucumber and implement in ruby and calabash… I am using Sublime, but you can use whatever IDE that supports ruby to write the features and the rb.

Steps – Example:

Feature: Search – True And False Results      # This is the name of the feature

Scenario Outline: Search                                 # This is the name of scenario

And look for: something                              # This is one step

And save the file like Search.feature -> in the folder features (Remember the folders of calabash have to stay inside of project’s folder), in this case I wrote a case of search of an app.

If you run now, without write the ruby file, the console will show the step you have to use in the ruby file, the calabash changes somethings of your feature to run in ruby.

And the code in ruby is:

#encoding: utf-8
require ‘calabash-cucumber’
require ‘calabash-cucumber/keyboard_helpers’

Given look for: something do                     # This is the step of the feature
tapicon openmenu‘                                   # This is the command to tap in something in your app, you have to know first a id or label (I will explain how you can take this informations in a next post)
sleep 3                                                       # This command is to stop the execution for 3 seconds
touch(Label text:buscar‘”)                       # This command is to touch, like the tap, but you can use this command with querys too, different of tap that just use label or id
keyboard_enter_text something             # This command is to write something in the field wich you touched in the last command
end                                                            # This finalize this step, you have to write this every final of step

Save the file like Search.rb inside the folder step_definitions. Don’t forget the words in bold, every file of ruby and calabash have to have this words on head. This means that you have to import the lib of cucumber in this file and the file will accept the words of your feature file.

Run cucumber in the terminal, you have to inside of the project’s folder.

If the simulator don’t open, you have to write the local that your app is inside the param APP_BUNDLE_PATH. So will stay like this:

APP_BUNDLE_PATH=”Local of your app” cucumber 

If you wants open the console, the command is:

calabash-ios console

If the console don’t open for the same reason in the step here, you have to write the param of APP_BUNDLE_PATH again.

APP_BUNDLE_PATH=”Local of your app” calabash-ios console

If you wants install another lib in ruby you have to install in your terminal. I had to install a lib to generate a CPF. The command is:

gem install cpf_cnpj

After this, I just had import in the file of ruby like we did with cucumber, and stay like this:

require ‘cpf_cnpj

For now it is this 🙂  I will write many things about this in next time !

Bye Bye !!

Cucumber – First Steps

Hello Guys !

I hope that you didn’t had any problem with installation, BUT how I had, I will put some solutions and some things that I discovered using everyday.

1 – The calabash don’t support IOS 7, you have to start with instruments (But I still didn’t get) and nevertheless you can’t use the tool record and play for the drag gesture.

2 – If your app isn’t generated in the root folder, you have to write in the inside the Support’s folder where is your app builded with framework. Like, I generated with my user, rafaela, so the initial folder is: Users/rafaela/Library… and for calabash find the app alone, you have to builded the app in /var/root/Library….

3 – When I have to start the app with console, I have to write the folder where it is, for the same reasons in the step before, like: APP_BUNDLE_PATH=”XXX/XxxxxX/DerivedData/” calabash-ios console