BDDfire: Instant Ruby Cucumber Framework
Shashikant Jagtap, @Shashikant86, http://shashikantjagtap.net/
BDDfire is a Ruby library that creates skeleton for the ruby Cucumber Behaviour Driven Development (BDD) framework. Cucumber is very popular BDD framework. Cucumber can be more awesome if we use it with the right tools. BDDfire supports Selenium, PhantonJS, Appium, Saucelabs, Browserstack, Testingbot, Relish, Cuke_Sniffer and many more open source libraries. BDDfire aims to integrate all the friends of Cucumber and make the Cucumber framework stronger.
Website: https://rubygems.org/gems/bddfire
Version: 1.6.0
System Requirement: Ruby 1.9.3 +, NodeJS
License & Pricing: Open Source, MIT License,
Support: Website
BDDfire is an open source tool built around the Cucumber BDD framework for Ruby which supports various popular open-source libraries like Capybara, Selenium-WebDriver, Poltergeist, Relish, Cuke_Sniffer, Rubocop, Appium, Saucelabs, Browserstack and many more. BDDfire will create all the directories and required files to support the latest open-source libraries in the Cucumber framework.
BDDfire Features
Using BDDfire brings many benefits:
- BDDfire will create template directories and files for the Cucumber project.
- Integration with Capybara for executing acceptance scenarios in real and headless browsers.
- Generation of template directories to support RSpec
- BDDfire supports Cuke_Sniffer and Rubocop libraries that detect smell in Cucumber.
- BDDfire supports Relish for the living documentation. Rakefile has been automatically created as a part of BDDfire
- BDDfire supports YARD documentation of the Cucumber project.
- BDDfire allow you write steps using the Page Object Pattern
- BDDfire can run scenarios in the different viewport by specifying screen resolution.
BDDfire Installation and Usage
BDDfire is a RubyGem so you can install it by using a simple command.
$ gem install bddfire
If you already have Gemfile, then just add ‘ bddfire’ in your Gemfile. Once, installed you can see all bddfire options by using command bddfire
$ bddfire
It will display the following options :
Commands:
bddfire fire_cucumber
bddfire fire_rspec
bddfire generate_yard
bddfire help [COMMAND]
bddfire version
This will look like this in the terminal .
Cucumber Framework for Ruby
BDDfire can generate scaffolding for Cucumber by creating the necessary directories and files with relevant code in it. BDDfire has an option ‘fire_cucumber’ which does it all for us
$ bddfire fire_cucumber
Once you run this command, you will have the entire BDD Ruby Cucumber framework setup within a minute. This will create Gemfile with all the required RubyGems and Makefile to execute features with different profiles.
The output will look like this:
Now we have a new ‘Gemfile’ in our project. We need to install all the dependencies with ruby bundler:
$ bundle install
Now that we have all the skeleton directory structure for the Cucumber project, let’s have a look what we got inside the directories and files.
Real and Headless Browser Support
Automated cucumber scenarios can be run with a real browser or with headless browser. BDDfire gives you the option to run them in both. Selenium WebDriver can be used to run automated Cucumber scenarios in real browsers without any additional setup. Selenium driver for Capybara is setup for you with a default Cucumber profile. In the cucumber.yml file, you can see that Selenium WebDriver is setup as default capybara driver. We can run our scenarios in the Firefox browser like this:
$ bundle exec cucumber
In a similar way, we can run the scenarios in headless browsers like PhantomJS using Poltergeist as Capybara driver. The Poltergeist driver is already setup for you in ‘features/support/env.rb’ file. BDDfire also created a profile to run scenarios with headless browser.
$ bundle exec cucumber -p poltergeist
You can see your scenarios executed but you won’t see any browser launched, this helps to run automated Cucumber scenarios faster than with real browsers.
Responsive Test Automation
BDDfire allows automated test scenarios in the different viewport and screen resolutions. BDDfire creates a file 'features/support/responsive.rb' which is the config for the running scenarios with Selenium and Poltergeist driver. The supported screen sizes are 320, 600, 770 and 1026, but you can change this if you need. In order to run scenarios with different screen resolution, we need to set the environment variable DEVICE.
$ DEVICE=320 bundle exec cucumber
This will run automated scenario with Selenium driver and with screen size of 320. We can execute the same with the Poltergeist driver.
$ DEVICE=320 bundle exec cucumber -p poltergeist
Mobile Test Automation and Cloud Testing
BDDfire has a built-in Appium driver setup that allows you to run your automated Cucumber scenarios in mobile devices. Appium is an open source test automation framework for the mobile applications. Using the Appium driver, you can run tests in the Android and iOS devices. In order to run them in the real devices, you need to do the initial ADB setup for Android and UUID setup for iOS. This part is covered in the Appium documentation. Android ADB provides the ADB serial number for the devices attached to the computer. You can use this serial number to run automated cucumber scenarios in the mobile devices.
You need to run npm packages to install Appium locally.
$ npm install
This will install the npm dependencies and you can launch the Appium server
$ ./node_modules/.bin/appium
Now you can execute automated Cucumber scenarios in the attached Android device
$ ADB_SERIAL = XXXXX bundle exec cucumber -p appium
In a similar way, BDDfire gives you an option to run tests in third party cloud testing services like SauceLabs, BrowserStack and TestingBot. In order to use those services, you need to create an account and get an username and assess key. You can then use that access key in ‘features/support/env.rb’ file to run the automated Cucumber scenarios. If you are running tests in the BrowserStack, you will have all the stacks defined in the 'browser.json' file. We can use any of them. We need to configure BrowserStack username and access key in the driver configuration.
$ BS_STACK=osx_firefox bundle exec cucumber -p browserstack
Using the same setup, you can run automated scenarios in the other third party testing services like SauceLabs and TestingBot.
Living Documentation
BDDfire gives you an option to use Relish as living documentation tool. Relish publishes feature files online so that the whole team can read and access them. In order to use Relish, you need to have a Relish account and API TOKEN that can be obtained by visiting 'https://www.relishapp.com/api/token' after logging in.
BDDfire creates a file ‘.relish’ where you need to paste your token. Now you can publish your feature files online by using
$ bundle exec relish push {Publisher}/{project}
Code Quality
BDDfire comes with two code quality checking tools : Rubocop to check Ruby code quality and Cuke_Sniffer to detect smells in the Cucumber features, step definitions and hooks. BDDfire creates a ‘.rubocop.yml’ file with basic Ruby code quality rules. You can change the configuration according to your requirements. With this configuration, you can use Rubocop to detect smell in our Ruby code
$ bundle exec rubocop
In similar way, you can use Cuke_Sniffer to detect smell in the Cucumber project. Cuke_Sniffer runs through all feature files. step definitions, hooks and support code. It finds out dead steps and suggests improvement to write better feature files. You can execute Cuke_Sniffer like this:
cd features
$ bundle exec cuke_sniffer
Continuous Integration
BDDfire creates a ‘ci_script’ file to run automated Cucumber scenarios on continuous integration server like Hudson and Jenkins. It will clear the workspace by deleting old reports, creates YARD documentation for your project and runs Rubocop and Cuke_Sniffer before executing your scenarios. You can also change this file to suit your project need. BDDfire also creates a ‘travis.yml’ file to support execution on TravisCI.
Page Object Pattern
BDDfire allows writing steps using the Page Object Pattern. Page object pattern is a great way to maintain the automation framework by abstracting locators and common methods to the Page classes. BDDfire creates a directory called "features/pages" that has ‘Abstract.rb‘ and ‘HomePage.rb" files. You can create instance of these classes at any point in the steps_definitions like this :
@home_page = HomePage.new(Capybara.current_session)
@home_page.visit_home_page
This makes your step_definitions more stable. You need to change page classes if something changed and step_definitions remains unchanged.
Rspec Framework
BDDfire also creates skeleton directories for the Rspec project as well. It will create necessary directories and files with relevant code in it. Just run
$ bddfire fire_rspec
Summary
BDDfire can add value to the Cucumber BDD framework for ruby by integrating awesome open-source libraries with it. BDDfire can help companies by setting up their Cucumber framework and making it extensible.
Further reading
http://shashikantjagtap.net/category/bddfire/
GitHub: https://github.com/Shashikant86/bddfire
More Software Testing Knowledge
Software Testing Books
Growing Object-Oriented Software, Guided by Tests
Implementing Automated Testing
Click here to view the complete list of tools reviews
This article was originally published in the Winter 2014 issue of Methods & Tools
Methods & Tools Testmatick.com Software Testing Magazine The Scrum Expert |