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 🙂

Javascript and CSS – Testing on hybrid apps

Hello everyone 🙂

I am testing a hybrid app these days and I am learning a lot…Ok, but what is a hybrid app ?
Like native apps, run on the device, and are written with web technologies (HTML5, CSS and JavaScript). Hybrid apps run inside a native container, and leverage the device’s browser engine (but not the browser) to render the HTML and process the JavaScript locally. A web-to-native abstraction layer enables access to device capabilities that are not accessible in Mobile Web applications, such as the accelerometer, camera and local storage.

Summarising…. You have to test native elements mixed with web elements… Cool, don’t you think ? HaHa Hard work !

This post have some examples of a query using CSS and an action (click) using Javascript(IOS and Android platform):

Using Javascript to click: (Example)

query("webView index:1", :stringByEvaluatingJavaScriptFromString 'document.getElementsByTagName("iframe")[0].contentWindow.document.getElementByTag("a").click()')

This example, you have to write first the WebView hat contains the HTML and after put that conversor from String to Javascript. Finally, put your code in Javascript 🙂
I don’t know many things about javascript, but you can use the console of the inspector of Chrome or Safari to identify web elements in mobiles (iphone,ipad,tablet).

Examples – CSS:

query("SlidePanelWebView index:2 css:'#articleContainer .currentPanel figure .video-play-button'")

query("SlidePanelWebView index:4 css:'#article_1 .data-copy p strong a'")

element_does_not_exist("WebView css:'.inner a'")

Below the explanation of each part to form a CSS query on Calabash:

query("WebView index:4 css:'#article_1 .data-copy p strong a [style=\'Font:Tahoma\']'")

First: Put the element and the index that contains the element that you want. How you discover this ? You can try each index according with the position where is your element. Like in the end of a page… more chances to be the last index of the element.

Second: Write css:

– Third: Inside each you will choose what properties, class, id or tag you want to use to find the element.

Fourth: When you know the id of the div or the element, you can write here. Put and then the id of the div… If the element that you want was not found until this point, you can use the id of the first div in the hierarchy. Like:

<div id:first>

<div id: second>

<element id: third></element>



In this example, you can use the id of the first div instead of the id’s element. And try writing the way to find the element with the tags or classes provided.

Fifth: Class, here you can use the class element. To identify that this is a class you need to put a . before the name of the class… And I used to write only the last name of the class when this has more then one class name. Example:

<div id:first>

<div class: class name second>



Sixth: The last thing that you should know it is about the tag name. Like <p>, <a href>, <strong>… When you want to find a tag you just write the tag names separated by space. Like:  div p a , following the example bellow.

<div class: first>


<a href: third></a>



Seventh: When you want to find a property in the middle of the css.You need to put [name of property=value of property] Like when you want to search a specific value for href: [href=], following the example bellow.

<a href:></a>


More examples of queries calabash with CSS:

query("WebView index:4 css:'#three .scrollable [data-component=buttonBlock] .sectionList li span'")

query("PanelWebView css:'#article .data-copy p strong a'")

query("View index:3 css:'.viewInactive'")


If you have any suggestion, questions or comments just write below please !

Bye !!

Calabash-Android Install Example Project

Hello guys,

Today I will post about install calabash-android in your machine. And for this I will use the project sample of this git repository:

You can do the download too if you don’t have a project neither an apk file.

Download and install ruby and RVM:

\curl -sSL | bash -s stable --ruby
rvm install ruby 1.9.3
Install calabash-android:
sudo gem install calabash-android


Install bundler unless you already have it installed:

gem install bundler

(or sudo gem install bundler)

Install gems in the Gemfile:

bundle install


To run the iOS tests, make sure Xcode 5.1 is installed with command line tools.


bundle exec cucumber -p ios


To run the Android tests, ensure a recent Android SDK is installed, and that

  • environment variable ANDROID_HOME is set to point to the sdk folder, for example/Users/krukow/android/adt/sdk

PS: This an example of a project with generated key and certificates, so you don’t need assign the app.


bundle exec calabash-android run prebuilt/Android-debug.apk -p android

This example you must to install bundle too. If you have any question or comment, just write below. Thank you again 🙂