Below defines the work flow from Cucumber to Selenium web driver:
(1) Cucumber
Defines the system behaviour in plain English
Example:
Scenario: Searching in Google homepage
Given I am on Google homepage
And I enter “blog” in the search box
And I click on “Google Search”
Then I will see the text “Blogger”
(2) Step definitions
- Contains the code that performs the actions of Cucumber
- Uses Capybara for web interaction
- Uses CSS selector or XPath to identify web elements
- Uses RSpec to verify expected result
Given /^I am on Google homepage$/ do
visit(‘http://www.google.com’)
end
– “visit” is a Capybara function
Given /^I enter “([^”]*)” in the search box$/ do |keyword|
fill_in ‘q’, :with => keyword
end
– “fill_in” is a Capybara function
– “q” is the name of the search box element on Google homepage
Given /^I click on “([^”]*)”$/ do |button|
click_button(button)
end
– “click_button” is a Capybara function
Then /^I will see the text “([^”]*)”$/ do |text|
page.should have_content(text)
end
– This is a RSpec matcher function
When you run the tests above, you will get the following output in green if it passed:
It will look like the following if your test fails:
Selenium will also drives the browser to perform the actions as specified.
Leave a Reply