Capybara Automated Testing

TestingBot supports Selenium testing using Capybara. Before we start with the example, please make sure you have Capybara installed:

gem install capybara

Now let's start with a simple Capybara test case.


# Google Feature
Feature: Google Search Functionality

Background:
  Given I am on https://www.google.com/ncr

Scenario: Can find search results
  When I fill in "q" found by "name" with "TestingBot"
  And I submit
  Then I should see title "TestingBot - Google Search"

# Google Steps
Given /^I am on (.*)$/ do |url|
  visit url
end

When /^I fill in "([^\"]*)" found by "([^\"]*)" with "([^\"]*)"$/ do |value, type, keys|
  fill_in(value, :with => keys)
end

When /^I submit$/ do
  find_field('q').native.send_key(:enter)
end
 
Then /^I should see title "([^\"]*)"$/ do |title|
  expect(page).to have_title title
end

Integrate with TestingBot

Please use this module to run Capybara tests on TestingBot:


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

# monkey patch to avoid reset sessions
class Capybara::Selenium::Driver < Capybara::Driver::Base
  def reset!
    if @browser
      @browser.navigate.to('about:blank')
    end
  end
end

TASK_ID = (ENV['TASK_ID'] || 0).to_i
CONFIG_NAME = ENV['CONFIG_NAME'] || 'single'

CONFIG = YAML.load(File.read(File.join(File.dirname(__FILE__), "../../config/#{CONFIG_NAME}.config.yml")))
CONFIG['key'] = ENV['TESTINGBOT_KEY'] || CONFIG['key']
CONFIG['secret'] = ENV['TESTINGBOT_SECRET'] || CONFIG['secret']


Capybara.register_driver :testingbot do |app|
  @caps = CONFIG['common_caps'].merge(CONFIG['browser_caps'][TASK_ID])

  Capybara::Selenium::Driver.new(app,
    :browser => :remote,
    :url => "http://#{CONFIG['key']}:#{CONFIG['secret']}@#{CONFIG['server']}/wd/hub",
    :desired_capabilities => @caps
  )
end

Capybara.default_driver = :testingbot
Capybara.run_server = false

This module uses a configuration file which contains credentials and the browser we want to run the test on:


single.config.yml:
server: "hub.testingbot.com"
key: "api_key"
secret: "api_secret"

common_caps:
  "screenrecorder": true

browser_caps:
  -
    "browserName": "chrome"
    "version": "latest"
    "platform" : "WIN10"
    

To start the test, please run this command:

bundle exec rake single

Configuring capabilities

To run your existing tests on TestingBot, your tests will need to be configured to use the TestingBot remote machines.


To let TestingBot know on which browser/platform you want to run your test on, you need to specify the browsername, version, OS and other optional options in the capabilities field.


Capybara::Selenium::Driver.new(app,
    :browser => :remote,
    :url => "http://#{CONFIG['user']}:#{CONFIG['key']}@#{CONFIG['server']}/wd/hub",
    :desired_capabilities => @caps
)

To see how to do this please select a combination of browser version and platform in the drop-down menus below


1. Select a Platform
2. Select a Browser


Testing Internal/Staged Websites

We've built TestingBot Tunnel, to provide you with a secure way to run tests against your staged/internal webapps.
Please see our TestingBot Tunnel documentation for more information about this easy to use tunneling solution.


The example below shows how to easily run a Ruby WebDriver test with our Tunnel:


1. Download our tunnel and start the tunnel:

java -jar testingbot-tunnel.jar key secret

2. Adjust your test: instead of pointing to hub.testingbot.com/wd/hub like the example above - change it to point to your tunnel's IP address.
Assuming you run the tunnel on the same machine you run your tests, change to localhost:4445/wd/hub. localhost is the machine running the tunnel, 4445 is the default port of the tunnel.


This way your test will go securily through the tunnel to TestingBot and back:


single.config.yml:
server: "localhost:4445"
key: "api_key"
secret: "api_secret"

common_caps:
  "screenrecorder": true

browser_caps:
  -
    "browserName": "chrome"
    "version": "latest"
    "platform" : "WIN10"
        

Other Options

We offer many other test options, for example: disable video recording, specifying a custom Firefox Profile, loading Chrome/Firefox/Safari extensions, running an executable before your test starts, uploading files, ...
See our list of test options for a full list of options to customize your tests.

Parallel Testing

Parallel Testing means running the same test, or multiple tests, simultaneously. This greatly reduces your total testing time.

You can run the same tests on all different browser configurations or run different tests all on the same browser configuration.
TestingBot has a large grid of machines and browsers, which means you can use our service to do efficient parallel testing. It is one of the key features we provide to greatly cut down on your total testing time.


Queueing

Every plan we provide comes with a limit of concurrent VMs (how many tests you can run in parallel).
For example: if you have a plan with 5 concurrent VMs, it is possible to start more tests. TestingBot will queue the additional tests and run the tests as soon as slots become available.


To start running tests in parallel, modify the config file with more browsers:

parallel.config.yml:
server: "hub.testingbot.com"
key: "api_key"
secret: "api_secret"

common_caps:
  "screenrecorder": true

browser_caps:
  -
    "browserName": "chrome"
    "version": "latest"
    "platform" : "WIN10"
  -
    "browserName": "firefox"
    "version": "latest-1"
    "platform" : "WIN7"
  -
    "browserName": "safari"
    "version": "latest"
    "platform" : "MAC"
        

To run your tests in parallel, run this command:

bundle exec rake parallel
  • Capybara

    Capybara is an integration testing tool for rack based web applications.

  • Cucumber

    Cucumber is a Ruby based test tool for BDD.

  • RSpec

    RSpec is a behavior-driven development (BDD) framework, inspired by JBehave.

  • Minitest

    Minimal (mostly drop-in) replacement for test-unit.

  • Watir

    Watir, pronounced water, is an open-source (BSD) family of Ruby libraries for automating web browsers.