Docs Code Examples

Documentation for:

Getting Started

You'll need …

Install Selenium 2 ruby bindings

From a terminal:

gem install selenium-webdriver

Code

require 'rubygems'
require "test/unit"
require 'selenium-webdriver'

class ExampleTest < Test::Unit::TestCase
    def setup
        caps = Selenium::WebDriver::Remote::Capabilities.firefox
        caps.version = "5"
        caps.platform = :XP
        caps[:name] = "Testing Selenium 2 with Ruby on Sauce"

        @driver = Selenium::WebDriver.for(
          :remote,
          :url => "http://username-string:access-key-string@ondemand.saucelabs.com:80/wd/hub",
          :desired_capabilities => caps)
    end

    def test_sauce
        @driver.navigate.to "http://saucelabs.com/test/guinea-pig"
        assert @driver.title.include?("I am a page title - Sauce Labs")
    end

    def teardown
        @driver.quit
    end
end

Run your first test

  1. Copy the above code into a file named basic-example.rb
  2. Run the test:
    ruby basic-example.rb
    

  3. The test should now appear in your account page.

Get saucy

  1. Your first test just ran! Check out the results on your Account Page.
  2. Visit our Available Browsers page!
  3. Visit our resources page, and see all the available Sauce integrations.