Mobile Software Test Automation: Creating iOS page support

Now it's time to start coding page support for the iOS project.  Do you remember when we did this for Android?  There are a few more setup steps before we can get to the irb console, so lets get started.

Moving the app to the project folder

Since we built and ran the iOS app last week, an application file was created for that build. This is essentially the packaged app that will be loaded onto the device.  This can be found in a couple locations.  The easiest way to find this is to open in finder from Xcode. In the leftmost navigator pane, select the project navigator icon and then select the calabash product from the projects dropdown.  Then in the utilities pane on the right side, you will see the full path, with an arrow icon.  Click this to open finder to this location.  Or, you could open finder to this location from the terminal using open followed by the filepath, or simply navigate to this folder manually through finder.  

Now that you have this app file, copy it and paste it inside your project folder.  I like to put this in a separate folder so it is organized.  Once done, your project folder should look something like the image below.  I added the build number 1.0 to the end of the app name to differentiate it from different builds.  Although not important for this sample, it is for the apps you will be automating.

Starting up the irb console

This is a little more cumbersome than starting up the Android console, mainly because we need to set some environment variables to run.  Some of these are not required when running in the simulator, but they are when we get to running on a physical device, which is why I am trying to get you in the habit of including them.  So for starters, here are the variables we need:

DEVICE_TARGET='iPhone 6s (9.2)'

The APP_BUNDLE_PATH variable is the location of the .app file with relation to your project folder.  You could have skipped the step of moving the app to your project folder and specified the long path that is auto-generated, but that can get confusing when you start getting a lot of builds, which is why we did it this way.  The BUNDLE_ID variable is the bundle identifier of your app, and is found in the editor portion of Xcode, at the top of the general tab.  We only have one, so this may not be needed, but when you have a couple different apps on the phone for different environments, this is a must.  The DEVICE_TARGET variable is the name of the simulator, or the UDID of the physical device.  Yours may look a little different from mine, depending on the device/simulator version you are running on.  Also, there is the DEVICE_ENDPOINT variable, which is the ip address of the physical device.  It is not needed for a simulator, but is for a physical device, and follows the format shown above.  You can find your ip address on your physical device by going to settings, WIFI, and selecting the more information icon next to the network you are connected to.

So to start the console, first launch the terminal, cd into your project folder, and then type the following, changing the variables as needed for your situation.

$ APP_BUNDLE_PATH=calculator-ios-app/ BUNDLE_ID=com.mglagola.Calculator-Calabash DEVICE_TARGET='iPhone 6s (9.2)' bundle exec calabash-ios console

Press enter and you should see something like this:

Now, type in the familiar (hopefully) command: 


After pressing enter, your terminal should look like the following, and the simulator should open, and the app launched:

Page Support for iOS

Since we already went through the console locator techniques for Android, I won't revisit those again, since they are exactly the same.  The easiest way to make sure we don't miss any methods is to create a new file under the iOS pages folder with the same name we used for Android (landingPage.rb) and copy the page file we created for Android, and paste this into the newly created iOS page.  You will need to change the first two lines to match the following:

require 'calabash-cucumber/ibase'
class LandingPage < Calabash::IBase

Now find the needed elements, which for our test are only the trait and button definitions.  When you are done, the iOS page file named landingPage.rb should look like this:

You will notice that most of this page is the same as its Android counterpart.  Since there are some minor differences between these apps, I also had to make some changes to the calabash_steps.rb file.  In short, those changes are determining which platform is being run, and will either execute code (Android, for the ad popup), or do nothing (iOS, since no ad popup is present).  We will go more into these types of things later on, but for now, you can see it in action below, with the changes boxed in red:

Now we are done coding page support for the iOS app!  Good job getting this far!  Next week we will walk through running the test on a simulator, as well as on a physical device. See you next week.