Cucumber is an excellent test automation framework / tool together with e.g. Watir. Cucumber scripts serves as documentation for the whole team and they also helps developer to quickly see that they have implemented everything and it works as expected. Cucumber also has good logging / reporting functionality.
Installation
- Download Ruby installer from http://www.rubyinstaller.org and run it. During installation select Ruby to be added to PATH and to associate .rb files to this Ruby installation.
- Download Ruby Devkit from http://www.rubyinstaller.org and extract it. In the extracted folder, run commands ruby dk.rb init and ruby dk.rb install to setup and install it.
- Install Cucumber gem with command: gem install cucumber
- Install Syntax gem with command: gem install syntax
Cucumber scripts usually consists of three files - feature, step definitions and support files. Feature file contains the feature description. Step definitions contains the actual test script code. For each line in the feature file there should be a matching step definition in the step definitions file. The support files can contain code for ramp-up, tear-down and hooks for something to be done before / after steps / scenarios.
How to run scripts
By running following command:
cucumber features (--out <filename>.html --format html)
Example script - feature file - cucumber.feature
Feature: Google
search
In order to find Cucumber homepage using
Google search
As an end user
I need to enter a correct keyword in the
search field
Background:
Given Google search page
Scenario: Search for Cucumber
Given keywords ‘Cucumber’ in search
field
When I submit form
Then a link to Cucumbers’s homepage
is found
Example script - step definitions file - cucumber.rb
Given /^Google search
page$/ do
$browser.goto
‘http://www.google.com’
end
Given /^keyword ‘Cucumber’ in search
field$/ do
$browser.text_field(:name,
"q").set 'Cucumber'
end
When /^I submit
form$/ do
$browser.button(:id, ‘gbqfb’).click
end
Then /^a link to Cucumber’s homepage
is found$/ do
Watir::Wait.until { $browser.text.include? 'Making BDD fun‘ }
end
Example script - support file - env.rb
require 'rubygems'
require 'watir-webdriver'
$browser = Watir::Browser.new(:firefox)
at_exit do
$browser.close
end
More information
http://cukes.info
No comments:
Post a Comment