The Sauce Labs Cookbook

Sauce Headless

Front End Performance Testing

Insights

External Resources

More Info


Page tree
Skip to end of metadata
Go to start of metadata

This script provides an example of how you might configure your own automated tests to run in the Sauce Labs browser cloud. The sample test uses environment variables for authentication, assigns a tag and build number for test result management, and reports Pass/Fail status to the Sauce Labs dashboard.

Example Only

The code in this topic is presented as an example only, since your tests and testing environments may require specialized scripting. This information should be taken only as an illustration of how you could set up your tests with Sauce Labs, and is not directly supported by Sauce.

What You'll Need

Example Script

The script below navigates to our sample application, enters login credentials, and successfully clicks the login button.

 Click here to view the entire script...

Successful Login Test
# frozen_string_literal: true

#
# This is an example of Imperative Test code to keep things simple
# Your tests should be written declaritively
# This means adding abstractions for Page Objects and Data Objects that will do all of the work.
#
require 'spec_helper'

describe 'Authentication' do
  let(:driver) { @driver }

  before { driver.get 'https://www.saucedemo.com' }

  it 'successful' do
    driver.find_element(css: "[data-test='username']").send_keys 'standard_user'
    driver.find_element(css: "[data-test='password']").send_keys 'secret_sauce'
    driver.find_element(css: "[type='submit']").click

    expect(driver.current_url).to eq 'https://www.saucedemo.com/inventory.html'
  end
end

Environment Setup

  1. Global Dependencies
    1. Install Ruby
    2. Install Git
    3. Clone the demo-ruby repository.

      $ git clone https://github.com/saucelabs-training/demo-ruby.git
    4. Install bundler

      $ gem install bundler
  2. Navigate to the `rspec` directory (`/selenium-examples/rspec/`)

    $cd selenium-examples/rspec
  3. Install the gem packages

    $ bundle install

Running the Tests

  • Run tests in parallel on default configuration:

    $ bundle exec rake
  • Run in parallel on a specific configuration (see /spec/Rakefile` for available tasks)

    $bundle exec rake windows_10_edge
  • Run Sauce Labs Demo, then watch your tests run in the Test Results page in Sauce Labs:

    $bundle exec rake sauce_demo