Chuan Chuan Law

DevOps | Software Automation | Continuous Integration

Tag: Cucumber

Customised Browser Profile

In cases where your Cucumber tests rely on browser settings, for e.g., security certificates for trusted sites, you can do the following:

  • Go to the website
  • Accept the website as a trusted site
  • Edit features/support/env.rb with the following code
Before(‘@javascript’) do
  Capybara.register_driver :firefox_custom do |app|
    require ‘selenium/webdriver’
    profile_path = File.dirname(__FILE__) + ‘/profile’
    profile =
    profile.assume_untrusted_certificate_issuer = false, {:browser => :firefox, :profile =>profile})
Before(‘@javascript’) do
  • Commit the profile (cert8.db and cert_override.txt) into “features/support”

Headless Cucumber

I get to set up a CI box that is running on a Linux environment with no display. Therefore, Headless Cucumber is the solution.

Under “features/support”, in “env.rb”, add the following piece of code:

require ‘headless’
   headless =

at_exit do

How Cucumber-Selenium Works

Below defines the work flow from Cucumber to Selenium web driver:

(1) Cucumber

Defines the system behaviour in plain English
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” is a Capybara function
Given /^I enter “([^”]*)” in the search box$/ do |keyword|
fill_in ‘q’, :with => keyword
– “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” is a Capybara function
Then /^I will see the text “([^”]*)”$/ do |text|
page.should have_content(text)
– 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.


A BDD and English language way of describing system behaviour.
Its official website is
The most basic cucumber scenario will look like this:
GIVEN – state or input of system
WHEN – action perform with the system
THEN – output of system
Tips to write a good Cucumber tests
  • Keep it straightforward, short, precise, and to the point
  • Make it maintainable (example: check that a text present rather the whole text content)
  • Avoid repetition as this will slow down the CI build (try to reuse existing scenario)
  • Start writing by listing out the scenarios before going into the details
  • Avoid too many comments
  • Write it from the business or perspective rather than technical perspective

© 2019 Chuan Chuan Law

Theme by Anders NorenUp ↑