Features

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

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.


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 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:


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

common_caps:
  "screenrecorder": true

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

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, 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

Queuing

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.

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.