Calabash and Capybara are both Ruby frameworks for automating UI testing. For anyone who doesn’t know/is new to this thing, Ruby is an interpreted language. Anyone who has Ruby installed can just open up a terminal window and type irb and they will be put into an interactive Ruby console. This is wonderful because it means you can have Calabash or Capybara open in an interactive console. This makes development of tests EXTREMELY easy and fast. There’s no need for an expensive IDE if you can write all of your tests by simply going into interactive mode, typing something in until you get the command you want, and then copy and paste it into your test suite. It’s also a lot of fun to play with interactive mode.
For Calabash, everything is really easy. All you’ll need is your apk (if you’re doing android) and a terminal
Calabash-iOS Interactive Console
First let’s look at iOS because it’s the easiest. Install your Calabash target on your device and open up the app.
All you should have to do (assuming everything is set up correctly for Calabash) is execute the command
1 |
calabash-ios console |
You should now be in an interactive console with your running application.
Calabash-Android Interactive Console
First you’ll need your apk. If the apk is signed with someone else’s certificate (if you got it off of your CI server) then you’ll need to resign it with your certificate
1 |
calabash-android resign <apk> |
This will sign the apk with your development certificate. If you don’t have a development certificate, check out the last bit of my Calabash Setup Guide.
Once you’ve resigned the apk (if needed) then execute the following command
1 |
calabash-android console <apk> |
This will put you into an interactive console, but to actually interact with the application you’ll need to run
1 2 |
reinstall_apps start_test_server_in_background |
The first will reinstall the application and the second will launch the app and launch the server that Calabash uses to interact with the app.
Capybara Interactive Mode
Capybara is a little more difficult because it doesn’t come with a command to do it all for you.
Open up irb and do the following
1 2 3 4 5 6 7 |
require 'selenium-webdriver' require 'capybara' include Capybara::DSL Capybara.default_webdriver = :selenium visit 'http://www.google.com' |
This should open up a Firefox window and load up Google’s homepage. The interactive console will be attached to this page.
One thing I did to make things a bit quicker for me was create a script to do this for me.
1 2 3 4 5 6 7 8 9 10 11 12 |
#! /usr/bin/ruby require 'irb' require 'selenium-webdriver' require 'capybara' include Capybara::DSL Capybara.default_webdriver = :selenium visit 'http://www.google.com' IRB.start |
Then you can just execute that file ./interacive or ruby interactive