Boilerplate code for starting a new iOS and Android cross-platform BDD project using Cucumber with Calabash.
One set of feature files, one set of step definitions, platform specific page objects and methods.
Run on iOS: cucumber -p ios
Run on Android: calabash-android run build/example.apk -p android
In most cases this code is intended to be self documenting, i.e. there are explanatory comments in many of the files. This Readme focuses on explaining how to run the tests and provides insight into decisions made with regards to structure and naming conventions.
This code was created with the intention of providing a solid base that can be extended into a full BDD test suite for your own cross-platform applications. Example applications – example.apk and example.app have been provided along with a single passing scenario for demo purposes.
To run, you'll need to have a version of Ruby greater than 2.0 installed. I'd recommend using RVM with the latest stable version of Ruby, and creating and using a specific Gemset for running the tests.
- In a terminal, navigate to the project root directory.
- Enter
gem install bundler
to install bundler. - Enter
bundle install
to install required Ruby gems including cucumber, calabash-android and calabash-cucumber (iOS).
- Enter
calabash-android run build/example.apk -p android
to install the built app and run the example scenario.
- Enter
cucumber -p ios
to install the iOS app on a simulator and run the example scenario.
Clone this repository and place the files in your project's root folder, then do the following:
The following files and folders are specific to the example application, or are otherwise not required, and can safely be deleted:
build/
features/example.feature
LICENSE
README.md
features/step_definitions/example_steps.rb
All feature files should be placed in the features/
directory and use the .feature
extension. Features should be UI agnostic, i.e. they don't refer to specific on screen elements, and simultaneously describe the behaviours of the app on both platforms.
Step definitions are platform agnostic, i.e. they are the same for both iOS and Android, and should be placed in the features/step_definitions
directory and use the .rb
extension.
Page objects are platform specific and appear in the features/support/android/screens
or features/support/ios/screens
directories. The HomeScreen object in each can be renamed and used as your own page object. For iOS:
- Rename the file
features/support/ios/screens/home_screen.rb
to match with your own screen name. - In the renamed file, rename the
HomeScreen
class to match your screen name. - In
features/support/ios/screens/_screens.rb
rename thehome
method to the name you want to use for your screen when calling its methods. - Change the line
@home ||= page(HomeScreen)
to reference your method name and class name.
You should create additional page objects with screen specific methods for each new screen/activity/dialog in your application:
- All page objects should be added to the
features/support/ios/screens/
andfeatures/support/android/screens/
directories and use the.rb
extension. - Each page object should contain a single class matching your screen name.
- Add a new method to the platform specific
_screens.rb
file with the name you want to use for your screen when calling its methods. - Add the line
@yourscreen ||= page(YourScreen)
to the new method referencing your page object's class and the name by which you want to refer to the screen.
Copyright (c) 2016 Dan Buckland and Contributors. See LICENSE for details.