Capybara Cucumber Code Example

In this Ruby Capybara Cucumber example, the Gridlastic hub endpoint and the video url used is displayed after launching your Gridlastic selenium grid. See documention Selenium Grid Configuration Parameters where to find these credentials and replace with your own.

Get a free account and launch your Gridlastic selenium grid, then run this code locally and test your selenium grid.


Feature: Google search

Scenario: Search for webdriver        
	Given I am on the Google homepage
	Then I will search for "webdriver"
	Then I should see "webdriver"


Given(/^I am on the Google homepage$/) do
    visit ''

Then(/^I will search for "(.*?)"$/) do |searchText|
    fill_in 'q', :with => searchText

Then(/^I should see "(.*?)"$/) do |expectedText|
	expect(page).to have_content(expectedText)


require 'capybara/cucumber'
require 'selenium/webdriver'

capabilities =
capabilities['browserName'] = "chrome"
capabilities['version'] = "latest"
capabilities['platform'] = "VISTA"
capabilities['platformName'] = "windows"
capabilities['video'] = "True"

Capybara.register_driver :selenium do |app|
# Note: starting from selenium version 3.9.1 you must also include "platformName": "windows" in the request when testing with firefox and IE.
# If the requested test environment is not registered with the selenium grid hub
# or busy, allow enough time for the Gridlastic auto scaling
# functionality to launch a node with the requested environment.
  client =
  client.timeout = 1200 #seconds, http_client: client,
    :browser => :remote,
    :url => "",
    :desired_capabilities => capabilities)

Capybara.default_driver = :selenium
Capybara.run_server = false

#VIDEO_URL set to like "".
#Find this VIDEO_URL value in your Gridlastic dashboard.
session_id = Capybara.current_session.driver.browser.instance_variable_get(:@bridge).session_id

#Maximize window. 
# On LINUX/FIREFOX the "manage.window.maximize" option above does not expand browser window to max screen size. Resize as below:
#window = Capybara.current_session.driver.browser.manage.window
#window.resize_to(1920,1080) # width, height
NOTE: Gridlastic auto scaling requires all 3 test environment parameters platform, browser and browser version to be specified in each request in order to launch test nodes to fulfill test demand. Video recording is optional. See test environments for capabilities options.