Instantly share code, notes, and snippets.

@robustdj /login_spec.rb Secret
Created Jul 8, 2016

Embed
What would you like to do?
Example SauceLabs rspec test
require_relative "spec_helper"
describe "Visiting Sign in page" do
it "loads the form successfully", :run_on_sauce => true do
@driver.manage.timeouts.implicit_wait = 10
@driver.navigate.to "https://pdt-browserstack.pagerduty.com"
raise "Unable to load PagerDuty." unless @driver.title.include? "PagerDuty"
query = @driver.find_element :id, "user_email"
query.send_keys ENV['username']
query = @driver.find_element :id, "user_password"
query.send_keys ENV['password']
query.submit
expect(@driver.title).to eql("Incidents - PagerDuty")
header = @driver.find_element :css, '.page-header h1'
expect(header.text).to eql("Incidents on All Teams")
end
end
require "selenium/webdriver"
module SauceDriver
class << self
def sauce_endpoint
"http://YOUR_SAUCELABS_USERNAME:YOUR_SAUCELABS_ACCESS_KEY@ondemand.saucelabs.com:80/wd/hub"
end
def caps
caps = {
:platform => "Windows 7",
:browserName => "internet explorer",
:version => "10.0"
}
end
def new_driver
Selenium::WebDriver.for :remote, :url => sauce_endpoint, :desired_capabilities => caps
end
end
end
require "rspec"
require_relative "sauce_driver"
RSpec.configure do |config|
config.around(:example, :run_on_sauce => true) do |example|
@driver = SauceDriver.new_driver
begin
example.run
ensure
@driver.quit
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment