Mobile Software Test Automation: Setting up dependencies (Part 2)

Now that we installed Android Studio and Xcode last week, we are ready to finish setting up dependencies.

Create/Modify .bash_profile

Having a good .bash_profile is essential in making your life easier in terms of setting up aliases for use in the terminal, and is necessary to set your GEM_HOME, ANDROID_HOME, and a few others so that calabash works properly.  But you may not be able to see this file because it is hidden. So the first step is to go into the terminal and type:

$ defaults write AppleShowAllFiles YES

Press the return key to run the command.  Next, hold down the Option/alt key and right click (or two finger tap) on the Finder icon.  In the menu that comes up, click the 'Relaunch' option. This will show all the hidden files which you need access to.  If you don't want to always show these files, you can create an alias to toggle them, and instructions to do so can be found

Now that you can see all the hidden files, look in your home folder for a file titled .bash_profile.  If one does not exist, I will help you create one from the terminal.  You also have the option of opening a text editor and pasting in the lines below, and saving the file to your home folder with .bash_profile as the title, but where is the fun in that?  So once again, open the terminal and type:

$ nano .bash_profile

This command will open the file (or create one for you) in the nano text editor using the terminal.  Now type the following lines into the nano text editor within the terminal:

export GEM_HOME=~/.calabash
export GEM_PATH=~/.calabash
export ANDROID_HOME=~/Library/Android/sdk
export PATH="$PATH:$HOME/.calabash/bin:/usr/bin:/usr/local/bin"
export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools

source ~/.profile

Save your changes by pressing ctrl +o and hit return to save.  Then you can exit nano by pressing ctrl +x .  You will want to restart the terminal so that these changes can take effect.   

Install Ruby

Next you need to install Ruby.  You should already have an older version of Ruby on your Mac, so really we will be updating your version.  When I was first getting started, I read a lot of articles that wanted me to use homebrew and rbenv to update.  Do yourself a favor and DON'T use it.  By comparison, it is much more difficult, and still doesn't work consistently.  Instead, use rvm. You will thank me later.  So first, you will need to cd into your project directory (or create one if you don't have one already).  This is where all of your automation project code will live.  I choose to have a folder titled 'mobile-automation' in my documents so it's easy to get to, but you can put it wherever you want.  Once it's created, point the terminal at that folder by typing:

$ cd ~/path/to/my/project/folder

Press return and your terminal should now be pointed at your project folder.  Now type:

$ ruby -v

This will give you the current ruby version on your machine.  It will likely be somewhere between 1.8 and 2.0, depending on what OS shipped with your Mac.  Now, in the terminal, type:

$ \curl -sSL | bash -s stable --ruby

When this completes, there will be a line that states: 

* To start using RVM you need to run  `source /Users/nsanjines/.rvm/scripts/rvm` in all your open shell windows

Run the script as suggested.  Note that your output will differ slightly from mine.  Once run, you will need to close out of the terminal, relaunch, and then cd back into your project directory.  From here, run ruby -v again to see the output.  You should be running 2.2 or higher.

Install Calabash Gems and dependencies

Hang in there...we are almost done setting up dependencies!  I know this has been a really long post, but i wanted all this information to be in once place.  So here are the final steps.

You should already be in your project directory.  So now type the following in the terminal to install calabash:

curl -sSL | bash

Once complete, you will need to restart the terminal once again, then cd into your project folder.  Now, you could install the calabash ios and android gems one at a time, and then resolve all the dependencies, but there is a much easier way...Bundler.  I wish I had known about this when I was first getting started, as it would have saved me loads of time, but this is why I'm passing it along for you.  So assuming the terminal is pointing at your project directory, type:

$ gem install bundler

Next, you want to create a gemfile in your project directory.  This is done in the terminal by typing:

$ bundler init

This will create a mostly blank gemfile in your project folder.  The first line tells bundler where to find the gems you are specifying.  The rest of the lines declare the dependencies for bundler to maintain.  Each line contains the gem name as well as the version number to install.  You will want to install the most recent version of each gem listed, which can be found at  Since we already learned a little about nano, we will use it again to update the previously generated gemfile.  In the terminal, type:

$ nano Gemfile

Next, you will want to replace everything that is in that gemfile with what i have below.  The only difference being you will want to ensure that the version numbers for you are the most recent, which can be found here:  calabash-android, calabash-cucumber, run_loop, and minitest.

source ''

gem 'calabash-android', '0.5.14'
gem 'calabash-cucumber', '0.16.4'
gem 'run_loop', '1.5.6'
gem 'minitest', '5.8.1'

Once you paste in the above into the nano shell, press ctrl +o and then return to save, and then ctrl +x to exit...same as before.  Now everything is ready for the final step!  Assuming you are still in your project directory, type the following in the terminal: 

$ bundle install

Watch as all the rubygems and their dependencies effortlessly install/update on your machine!  This is so much easier than determining the dependencies and installing each one individually, isn't it?!?  Basically, bundler installed the requested gems along with their necessary dependencies.  When bundler is finished, it will create another file in your project directory called Gemfile.lock, which keeps track of all the gems and dependencies that were installed.  These files should be included in your source control, but do not manually modify the Gemfile.lock file, as it is maintained by bundler.

Well that's it for this week, and wraps up the section on dependency setup.  Next we will generate a calabash project and talk about the project's structure.  See you next week!