Skip to content

Using BrowserStack WebDriver

Doug Shamoo edited this page May 16, 2016 · 4 revisions

Teaspoon allows running specs on BrowserStack infrastructure from the rake task or command line interface. This allows you to test on a broader spectrum of browsers.

This page is dedicated to how to get setup and running.

Note The tests are served via a local server. So, The BrowserStackLocal binary must be running in the background to ensure the tests to pass. Download and follow the steps given in the link and then start the tests.

Setup

You'll need to include the selenium-webdriver gem in your Gemfile.

gem "selenium-webdriver"

Configure Teaspoon to use the browserstack driver. You can also pass some options along to Selenium using the driver_options directive.

spec/javascripts/teaspoon_env.rb

Teaspoon.configure do |config|
  config.driver = :browserstack
  config.driver_options = {
    capabilities: [{
      os: "OS X",
      os_version: "El Capitan",
      browser: "chrome",
      browser_version: ""
    }, {
      os: "Windows",
      os_version: "10",
      browser: "firefox",
      browser_version: "44"
    }],
    username: ENV['BROWSERSTACK_USERNAME'],
    access_key: ENV['BROWSERSTACK_ACCESS_KEY'],
    project: 'BrowserStack Project Name',
    build: 'BrowserStack Build Name',
  }
end

You can replace the username and access_key fields with your BrowserStack credentials from your account settings page.

Now when you run rake teaspoon it should run the tests on BrowserStack machines. You can access more details of your tests on BrowserStack dashboard.

Supported keys in config.driver_options (For in-depth explanation of these keys check capabilities):

  • project: The name of the project. Applies to all tests.
  • build: The name of the build. Applies to all tests.
  • username: The username for your BrowserStack account.
  • access_key: The access_key for your BrowserStack account.
  • capabilities: This must be an array of json values. These json values are passed to BrowserStack as-is to configure on per test level. Check here to generate caps for different browser-os combinations.
  • max_parallel: Teaspoon will run your BrowserStack tests in parallel upto max_parallel sessions. Default value 10. Assign 1 to run single test at a time.

Note - Teaspoon appends browserstack.local capability to each test as the javascript page is served locally.

For a sample rails application check this repo