---
title: Selenium with Cucumber and Capybara | TestingBot Blog
description: |-
  In this post you'll find a small tutorial on how to use Cucumber and Capybara to run Selenium tests on our Selenium grid.


  Cucumber is Aslak Helle...
source_url:
  html: https://testingbot.com/blog/2012/02/19/selenium-cucumber-capybara
  md: https://testingbot.com/blog/2012/02/19/selenium-cucumber-capybara.md
---

# Ruby testing with Cucumber and Capybara

By [Jochen D.](https://testingbot.com/about/jochen-d)2012-02-19

 Share on Facebook 

 Share on Twitter 

 Post on Reddit 

 Share link 

In this post you'll find a small tutorial on how to use Cucumber and Capybara to run Selenium tests on our Selenium grid.

Cucumber is Aslak Hellesøy’s rewrite of RSpec’s "Story runner". It uses plain text DSL (Gherkin), which we mentioned in a previous post ([Behat and Mink](https://testingbot.com/blog/2012/02/10/selenium-testing-with-mink-and-behat)), meaning you can write tests as stories.

Capybara fits nicely together with Cucumber when writing web application tests using Selenium.

To begin, let's create a directory called `features` which will hold all the files Cucumber requires: `$ mkdir features`

Now we'll add a configuration file so Cucumber knows what to do:

```bash
$ mkdir features/support
$ vim features/support/env.rb
```

```ruby
require 'capybara'
require 'capybara/cucumber'
require 'rspec'
require 'selenium/webdriver'

caps = Selenium::WebDriver::Remote::Capabilities.firefox
caps.version = "8"
caps.platform = :WINDOWS

Capybara.default_driver = :selenium
Capybara.register_driver :selenium do |app|
  Capybara::Selenium::Driver.new(app,
    :browser => :remote,
    :url => "http://[KEY]:[SECRET]@hub.testingbot.com:4444/wd/hub",
    :desired_capabilities => caps)
end
```

This file tells Cucumber we will run the Selenium test on TestingBot.com's grid.

Now let's create a story (feature): `$ vim features/youtube.feature`

```bash
Feature: YouTube has a search function.

Background:
  Given I am on YouTube

Scenario: Search for a term
  When I fill in "search_query" with "text adventure"
  And I press "search-btn"
  Then I should see "GET LAMP: The Text Adventure Documentary"
```

If you would now run "cucumber", you would see the following:

```bash
1 scenario (1 undefined)
4 steps (4 undefined)

"You can implement step definitions for undefined steps with these snippets:"
```

You'll know need to specify the step definitions from your feature, create a file `youtube_steps.rb:`

```bash
$ vim features/youtube_steps.rb

Given /^I am on (.+)$/ do |url|
  visit "http://www.youtube.com"
end

When /^I fill in "([^"]*)" with "([^"]*)"$/ do |field, value|
  fill_in(field, :with => value)
end

When /^I press "([^"]*)"$/ do |button|
  click_button(button)
end

Then /^I should see "([^"]*)"$/ do |text|
  page.should have_content(text)
end
```

If you run cucumber again, your test should succeed and a video + screenshots should be available in our [member area](https://testingbot.com/members).

```bash
1 scenario (1 passed)
4 steps (4 passed)
```

We hope this simple tutorial demonstrates how easy it is to start testing your website in minutes. You can find these demo files in our [GitHub repository](https://github.com/testingbot/Cucumber--Selenium-and-Capybara).

[← Previous post Selenium testing with Behat and Mink](https://testingbot.com/blog/2012/02/10/selenium-testing-with-mink-and-behat) [Next post → TestingBot Jenkins Plugin](https://testingbot.com/blog/2012/02/21/testingbot-jenkins-plugin-video-and-screenshots-of-selenium-tests-in-jenkins)

## Sidebar

### TestingBot Cloud Testing

Run automated, manual and visual tests on remote browsers and devices. Sign up for a free trial.

[Free Trial](https://testingbot.com/users/sign_up)

### Latest articles

[![Announcing AI Test Insights](https://testingbot.com/assets/blog/2026/ai-insights.jpg)](https://testingbot.com/blog/ai-test-insights)

#### Announcing AI Test Insights

Use AI Insights to quickly discover why an automated test...

[Read: Announcing AI Test Insights](https://testingbot.com/blog/ai-test-insights)

[![Selenium vs Playwright 2026](https://testingbot.com/assets/blog/2026/selenium-vs-playwright-2026.jpg)](https://testingbot.com/blog/selenium-vs-playwright)

#### Selenium vs Playwright 2026

Comparing Selenium vs Playwright - which is the best test...

[Read: Selenium vs Playwright 2026](https://testingbot.com/blog/selenium-vs-playwright)

[![Maestro Physical Device Testing](https://testingbot.com/assets/blog/2026/maestro-physical.jpg)](https://testingbot.com/blog/maestro-physical-device-testing)

#### Maestro Physical Device Testing

Maestro testing in parallel on physical Android and iOS d...

[Read: Maestro Physical Device Testing](https://testingbot.com/blog/maestro-physical-device-testing)

## Related Articles

[![Selenium vs Playwright 2026](https://testingbot.com/assets/blog/2026/selenium-vs-playwright-2026.jpg)](https://testingbot.com/blog/selenium-vs-playwright "Selenium vs Playwright 2026")

### [Selenium vs Playwright 2026](https://testingbot.com/blog/selenium-vs-playwright)

Comparing Selenium vs Playwright - which is the best test framework for your usecase?

[Read article →](https://testingbot.com/blog/selenium-vs-playwright)

[![Announcing AI Test Insights](https://testingbot.com/assets/blog/2026/ai-insights.jpg)](https://testingbot.com/blog/ai-test-insights "Announcing AI Test Insights")

### [Announcing AI Test Insights](https://testingbot.com/blog/ai-test-insights)

Use AI Insights to quickly discover why an automated test failed.

[Read article →](https://testingbot.com/blog/ai-test-insights)

[![Selenium 20th birthday](https://testingbot.com/assets/blog/2024/selenium20.webp)](https://testingbot.com/blog/selenium-20-years "Selenium 20th birthday")

### [Selenium 20th birthday](https://testingbot.com/blog/selenium-20-years)

Celebrate Selenium's 20th birthday. An overview of the years.

[Read article →](https://testingbot.com/blog/selenium-20-years)

[![Playwright Testing on TestingBot](https://testingbot.com/assets/blog/2023/playwright-testing.jpg)](https://testingbot.com/blog/playwright-testing-introduction "Playwright Testing on TestingBot")

### [Playwright Testing on TestingBot](https://testingbot.com/blog/playwright-testing-introduction)

Learn how Playwright can run your automated tests on a variety of browsers, local or remote browsers on TestingBot.

[Read article →](https://testingbot.com/blog/playwright-testing-introduction)

## More by Jochen D.

[![Announcing AI Test Insights](https://testingbot.com/assets/blog/2026/ai-insights.jpg)](https://testingbot.com/blog/ai-test-insights "Announcing AI Test Insights")
### [Announcing AI Test Insights](https://testingbot.com/blog/ai-test-insights)

Use AI Insights to quickly discover why an automated test failed.

[![Maestro Physical Device Testing](https://testingbot.com/assets/blog/2026/maestro-physical.jpg)](https://testingbot.com/blog/maestro-physical-device-testing "Maestro Physical Device Testing")
### [Maestro Physical Device Testing](https://testingbot.com/blog/maestro-physical-device-testing)

Maestro testing in parallel on physical Android and iOS devices.

[![tvOS Physical Device Testing](https://testingbot.com/assets/blog/2025/appletv.jpg)](https://testingbot.com/blog/tvos-automated-testing "tvOS Physical Device Testing")
### [tvOS Physical Device Testing](https://testingbot.com/blog/tvos-automated-testing)

Run automated tvOS tests on physical AppleTV devices.

[See all posts by Jochen D. →](https://testingbot.com/about/jochen-d)

## Ready to start testing?
[Start a free trial](https://testingbot.com/users/sign_up)
