Initial setup required for Mobile native app automation with Calabash
In this post i am trying to elaborate the overall setup for the ATDD approach along with the Calabash-Cucumber with Ruby as a language.
Background:-
Calabash is very popular, mostly used in all of big giants organisation now a days & its defined as an automated testing technology for Android and IOS native and hybrid applications.It provides you to run cross-platform, supporting Android and iOS native apps. Calabash consists of two libraries calabash-android and calabash-ios. As you can imagine, calabash-android is the automation and testing library for Android, and similarly calabash-ios is for iOS.
Setup:-
=>Need the Xcode 6.1.1(latest version available on appstore) installed on the Mac machine on which you are going to run your test.
=>Need to install the command line tools from the prefrences pane under “Downloads” in Xcode.
-=>If multiple Xcode is install on machine need to switch the latest version by :-
sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
=>Now, Install the Ruby , You will find its already installed on MAC machine, You can check by
ruby -v
, Morover, if you have multiple version of ruby, try to install with the help of rvm & set default ruby in the machine whichever you want.
=>Installation of the gems needed for your project: This can be done in two ways, First you have option to install manually by running multiple installation of gem commands on machine, but for future reference if neeed to setup the same project on other slave machines, its better to use second approach ie:- Use Gemfile to install the gem(for using this you must in need of manual installation of bundler by :- gem install bundler).
Here are the gems needed to setup calabash:-
gem install calabash-cucumber
Note you may need to run sudo gem install calabash-cucumber if you see ERROR: While executing gem … (Gem::FilePermissionError)).
=>To use Calabash for iOS in your app, you must do two things: link with our framework: calabash.framework, and install a ruby gem as described below. You also need to link with Apple’s CFNetwork framework if you are not already using this.
=>For functional testing with Calabash iOS, you should create a whole separate target by duplicating your production target in Xcode.Calabash iOS consists of two parts: a client library written in Ruby, and calabash.framework
, a server framework written in Objective-C (a Clojure/JVM version of the client is coming too). To use calabash you make a special test target in XCode that links with calabash.framework
. The application is otherwise unchanged. The server framework will start an HTTP server inside your app that listens for requests from the client library.
PS: Calabash interacts with the UI elements in your app via accessibility labels. That’s how it knows which button to tap when you issue a command like Then I touch "reply"
. As the author of the feature file, you can determine the labels of the various UI elements using the niftyAccessibility Inspector in the iOS Simulator. To turn it on, follow these steps:
- Run your app in the iOS Simulator via Xcode
- Stop the app
- Swipe from left to right to go to the first screen
- Tap on
Settings
- Tap on
General
- Tap on
Accessibility
- Turn the
Accessibility Inspector
toggleON
Here is the example of one feature file (Login.feature) which we are going to run:-
Feature: Verification of the Login Functionality
Scenario: Login the application with Valid credentials
Given I am on Login screen
When I enter the username "abodeqa" and password "funtesting"
Then I should see the Home screen
The above feature file describes the acceptance criteria for the login feature which is already we have in Login.feature. The cucumber tool executes your feature files which contain steps that are defined either in predefined or custom(user defined) steps definitions. Custom steps are written using the API that the client library exposes. The API methods make HTTP requests to the server, which does things like finding components in the UI and taking actions on them. Here is an illustration:
This generated a features skeleton dir for your tests:
$ tree -L 1 features/
features/
├──Login.feature
├── step_definitions
└── support
Running your Login.feature test now with the cucumber seems like(if app bundle path is in your location) :-
$ cd /path/to/your/iOS/project
$ DEVICE=iphone OS=ios5 NO_LAUNCH=1 cucumber features/Login.feature
Now try running the feature my_first.feature with cucumber.
$ cucumber
Feature: Verification of the Login Functionality
Scenario: Login the application with Valid credentials
Given I am on Login screen
When I enter the username "abodeqa" and password "funtesting"
AndI swipe left
Then I should see the Home screen
Scenario: Login the application with Valid credentials
... #different output here
Given I am on Login screen # features/step_definitions/my_first_steps.rb:1
When I enter the username "abodeqa" and password "funtesting" # features/step_definitions/my_first_steps.rb:20
And I swipe left # calabash-cucumber-0.9.127.pre1/features/step_definitions/calabash_steps.rb:190
Then I should see the Home screen # features/step_definitions/my_first_steps.rb:128
1 scenario (1 passed)
4 steps (4 passed)
0m15.097s
If all went well, You will see the Simulator run with the app, If your app path is somewhere else, You can pass APP_BUNDLE_PATH=/location/of/app/ along with the cucumber command.
NOTE:- For writing step definitions ,Please refer to the coming posts………
HAPPY TESTING…. 🙂
This is a fantastic blog from which people can learn a lot. It is very informative and is explained in…
Thanks for sharing such knowledgeable Content on Automation testing, to know how to enhance the performance of ERP's like Oracle…
Thanks.. this list is much needed.
This one is also good to use. Thanks for sharing this.. Might be we can also add it in list…
How about youtube-dl?