Features

Capybara Automated Testing

See our Cucumber + Capybara example repository.

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 "capybara/cucumber"
require "selenium/webdriver"
require "testingbot"

Capybara.default_max_wait_time = 10
Capybara.default_driver = :selenium

Before do | scenario |
  jobname = "#{scenario.name}"

  Capybara.register_driver :selenium do | app|
    capabilities = Selenium::WebDriver::Options.chrome
    capabilities.browser_version = ENV['version']
    capabilities.platform_name = ENV['platform']
    tb_options = {}
    tb_options[:name] = jobname
    tb_options['selenium-version'] = '3.14.0'
    capabilities.add_option('tb:options', tb_options)
    url = "https://#{ENV['TB_KEY']}:#{ENV['TB_SECRET']}@hub.testingbot.com/wd/hub".strip

    Capybara::Selenium::Driver.new(app,
                                   :browser => :remote, :url => url,
                                   :capabilities => capabilities)
  end

  Capybara.session_name = "#{jobname} - #{ENV['platform']} - " +
    "#{ENV['browserName']} - #{ENV['version']}"

  @driver = Capybara.current_session.driver

  @session_id = @driver.browser.session_id
  puts "TestingBotSessionId=#{@session_id} job-name=#{jobname}"
end

After do | scenario |
  @driver.quit
  api = TestingBot::Api.new(ENV['TB_KEY'], ENV['TB_SECRET'])
  if scenario.exception
    api.update_test(@session_id, { :success => false })
  else
    api.update_test(@session_id, { :success => true })
  end
  Capybara.use_default_driver
end

This module uses a Rake file which contains the browsers we want to run the test on:

Rakefile:
def run_tests(platform, browser, version, junit_dir)
  system("platform=\"#{platform}\" browserName=\"#{browser}\" version=\"#{version}\" JUNIT_DIR=\"#{junit_dir}\" parallel_cucumber features -n 20")
end

task :windows_10_chrome_latest do
  run_tests('Windows 10', 'chrome', 'latest', 'junit_reports/windows_10_chrome_latest')
end

task :bigsur_chrome_latest do
  run_tests('BIGSUR', 'chrome', 'latest', 'junit_reports/bigsur_chrome_latest')
end

multitask :test_testingbot => [
    :windows_10_chrome_latest,
    :bigsur_chrome_latest,
  ] do
    puts 'Running automation'
end

To start the test, please run this command:

bundle exec rake test_testingbot

Specify Browsers & Devices

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

capabilities = Selenium::WebDriver::Options.chrome
capabilities.browser_version = ENV['version']
capabilities.platform_name = ENV['platform']
tb_options = {}
tb_options['selenium-version'] = '3.14.0'
capabilities.add_option('tb:options', tb_options)

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

Testing Internal 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 Capybara 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 securely through the tunnel to TestingBot and back:

env.rb:
url = "http://#{ENV['TB_KEY']}:#{ENV['TB_SECRET']}@localhost:4445/wd/hub".strip
Capybara::Selenium::Driver.new(app, :browser => :remote, :url => url, :capabilities => capabilities)

Run tests in Parallel

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.

To start running tests in parallel, add more browser configurations in the Rakefile:

Rakefile:
def run_tests(platform, browser, version, junit_dir)
  system("platform=\"#{platform}\" browserName=\"#{browser}\" version=\"#{version}\" JUNIT_DIR=\"#{junit_dir}\" parallel_cucumber features -n 20")
end

task :windows_10_chrome_latest do
  run_tests('Windows 10', 'chrome', 'latest', 'junit_reports/windows_10_chrome_latest')
end

task :bigsur_chrome_latest do
  run_tests('BIGSUR', 'chrome', 'latest', 'junit_reports/bigsur_chrome_latest')
end

multitask :test_testingbot => [
    :windows_10_chrome_latest,
    :bigsur_chrome_latest,
  ] do
    puts 'Running automation'
end
Footer

The -n 20 in the example below specifies how many parallel sessions to run.
Usually you would use the same number as the maximum parallel sessions allowed by your TestingBot plan.

To run your tests in parallel, run this command:

bundle exec rake test_testingbot

Queuing

Every plan we provide comes with a limit of parallel tests.
If you exceed the number of parallel tests assigned to your account, TestingBot will queue the additional tests (for up to 6 minutes) and run the tests as soon as slots become available.

Mark tests as passed/failed

As TestingBot has no way to dermine whether your test passed or failed (it is determined by your business logic), we offer a way to send the test status back to TestingBot. This is useful if you want to see if a test succeeded or failed from the TestingBot member area.

You can use our Ruby API client to report back test results.

api = TestingBot::Api.new(key, secret)
api.update_test(driver.session_id, { :name => new_name, :success => true })

Other Ruby Framework examples

  • 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.

  • Test::Unit

    Test-Unit is a xUnit family unit testing framework for Ruby.

  • 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.