Monday, September 14, 2015

How to (Cala)bash your applications in iOS


This is the first blog post in a series for getting Calabash-iOS up and running on a Mac with Yosemite.

Some Background...

I was recently asked to kick-start an iOS testing effort for a project here at work.

Unfortunately, I'm not really a Mac person, nor had I used one in quite a while...let alone tested on one.

So what did I do? I immediately made several mistakes.

Mistake 1: Instruments

First, I tried out using Apple's built in tool for automated testing. While it's useful, it's not nearly as friendly as Calabash (thus the name of the post).

Mistake 2: Forgetting others had done this

After asking around, I was reminded that we had another group do work on iOS, including automated tests!

While it was a year or more back for most of the people who had worked with it, I found out through them about Calabash-iOS.

After digging into Calabash, I found it a more intuitive tool.

Basically, Calabash wraps Instruments, hiding some of the uglier parts, while providing some good functionality for testers to hook into.


Putting it all together:

I found an amazingly well-documented pair of blog posts (here and here) for installing everything you need to set up and run Calabash-ios through Ruby. I've copied out the relevant steps below.

Installing RVM and Ruby 

  1. Use CMD+SPACE to open up Spotlight (the equivalent to run in Windows)
  2. Search for Terminal (the Mac equivalent to command line)
  3. In terminal, run the following line
    curl -L https://get.rvm.io | bash -s stable --auto-dotfiles --autolibs=enable --ruby 
  4. Quit and relaunch terminal, then try the following commands:
type rvm | head -1
    rvm -v
    ruby -v
If all was installed correctly, the first command should return 'rvm is a function', and the other two should return their version numbers.

Installing Cucumber and Calabash 

  1. In Terminal, navigate to your project directory
  2. Run the following command to install calabash
  3. gem install calabash-cucumber
  4. Once that is finished, run the following command to generate the files and folders calabash needs
  5. calabash-ios gen
  6. Open your project in xcode, and verify that you now have a duplicate of your scheme with a suffix of '-cal'
  7. In xcode, go to Targets > Build Phases > Link Binary
  8. Add "Security.framework" there
  9. Select the new -cal project, select a simulator, then run it.
  10. There may be a prompt to accept incoming network connections. Allow that if it displays.
  11. The following should appear in the console output. If so, everything is installed correctly:
Creating the server: <LPHTTPServer: 0x8076530>
Started LPHTTP server on port 37265
Bonjour Service Published: domain(local.) type(_http._tcp.) name(Calabash Server)


You should now have a fully-functional set of calabash tools to explore!

I'll make another post about actually writing Calabash tests, and getting them running.