Appium and Cucumber – Managing different iOS and device configurations

Usually you will want to run your cucumber appium test suite on a few different configurations.

For example, you may want to run it on an iPhone 6 9.0 simulator and you also may want to run it on an iPad Air 8.4 simulator. So how do you do this?
Well it’s easy. First you use your cucumber.yml file to list the different configurations. So if we use our example above
we could create two profiles, lets call them iphonesim and ipadsim.
They would look like this in the cucumber.yml file:

ipadsim: IDEVICENAME='ipad simulator'
iphonesim: IDEVICENAME='iphone simulator'

We then need to create two different appium.txt files. One for the ipadsim configuration and one for ipadsim configuration. For example, the iphonesim appium.txt one would look like this.

[caps]
platformName = "ios"
deviceName = "iPhone 6"
platformVersion = "9.0"
app = "../../../apps/TestApp/build/release-iphonesimulator/myApp.app"

[appium_lib]
sauce_username = false
sauce_access_key = false

Save theiphonesim appium.txt file in a folder under Features/Support called “iphonesim” and theipadsim appium.txt under in a folder under Features/Support called “ipadsim”.

Then in env.rb tell Appium where to go to pick up the correct appium.txt based on which profile you have started your tests with.
Do this by adding something like this to your env.rb file

if ENV['IDEVICENAME']=='ipad simulator'
caps = Appium.load_appium_txt file: File.expand_path("./../ipadsim/appium.txt", __FILE__), verbose: true
elsif ENV['IDEVICENAME']=='iphone simulator'
caps = Appium.load_appium_txt file: File.expand_path("./../iphonesim/appium.txt", __FILE__), verbose: true
else
caps = Appium.load_appium_txt file: File.expand_path('./', __FILE__), verbose: true
end

Lastly, to run with your selected profile, cd into your cucumber folder and do the following:
To run the iPhone configuration execute:

cucumber -p iphonesim

To run the iPad configuration execute:

cucumber -p ipadsim

What does this actually do?

Well, if we use “cucumber -p iphonesim” as an example, firstly, the -p flag indicates to cucumber that you want to use a specific profile, so it looks up the profile in the cucumber.yml and sees IDEVICENAME=’ipad simulator’.
Cucumber then looks at the env.rb file and sees that when IDEVICENAME=’ipad simulator’ it should use the appium.txt file in the phonesim folder.
Appium then launches the simulator with the capabilites defined in the Features/Support/iphonesim/appium.txt.

This allows us to switch around configurations without changing anything other than our initial cucumber -p command.

Neat eh?

2 thoughts on “Appium and Cucumber – Managing different iOS and device configurations

  1. Hi Jane,

    Thank you for your blog, I´ve found a lot of useful information. I followed your instructions of how to get calabash to work with Appium, but unfortunately I have a problem:
    I can execute the arc console and my app works in simulator launched by appium, but when I try to launch calabash with the profile “iphonesim”, it throws an error
    kristinaste$ RESET_BETWEEN_SCENARIOS=0 cucumber -p ios -p en -p common -p iphonesim features/chats/chat_personal.feature
    uninitialized constant Appium (NameError)

    I guess that there are some other steps I should do to teach calabash how to launch appium. Could you please give me some advice?

    Cheers, Kristina

  2. Hi Kristina. My blog posts were not showing how to launch appium from calabash, instead they were showing two different set-ups. One set of blog posts to set up calabash and another set of blog posts to set-up appium.
    I suggest you create two separate projects, once for calabash and one for appium. Each project should have it’s own gemfile and you should use bundle to execute – this will ensure that you are calling the correct cucumber gem.
    For example, my appium gemfile contains:

    source ‘https://rubygems.org’
    gem ‘selenium-webdriver’, ‘>= 2.41.0’
    gem ‘appium_lib’, ‘~> 6.0.0’
    gem ‘rest-client’, ‘~> 1.6.7’
    gem ‘rspec’, ‘~> 2.14.1’
    gem ‘cucumber’, ‘~> 1.3.15’
    gem ‘rspec-expectations’, ‘~> 2.14.5’
    gem ‘spec’, ‘~> 5.3.4’
    gem ‘sauce_whisk’, ‘~> 0.0.13’
    gem ‘test-unit’, ‘~> 2.5.5’ # required for bundle exec ruby xunit_android.rb

    while my calabash gemfile contains:

    source “https://rubygems.org”
    gem ‘calabash-cucumber’, ‘0.16.4’
    gem ‘calabash-android’, ‘0.5.14’
    gem ‘xamarin-test-cloud’, ‘1.1.2’
    gem ‘selenium-webdriver’, ‘2.48.0’

    With your gemfiles in place and bundle installed you need run the command “bundle install” for each project.
    Then to run your calabash tests, go to your calabash project and run the command: bundle exec cucumber -p oneOfMyAppiumProfiles. Likewise for appium go to your appium project and run” bundle exec cucumber -p oneOfMyCalabashProfiles.

Please leave a comment - any questions or feedback welcome.