Skip to content

Instantly share code, notes, and snippets.

@robustdj robustdj/browserstack_driver.rb Secret
Last active Jul 8, 2016

Embed
What would you like to do?
Example BrowserStack rspec test
require 'selenium-webdriver'
module BrowserStackDriver
USERNAME = ENV['BROWSERSTACK_USERNAME']
BROWSERSTACK_ACCESS_KEY = ENV['BROWSERSTACK_ACCESS_KEY']
class << self
def browserstack_endpoint
url = "http://#{USERNAME}:#{BROWSERSTACK_ACCESS_KEY}@hub.browserstack.com/wd/hub"
end
def caps
caps = {
"browser": "IE",
"browser_version": "10.0",
"os": "Windows",
"os_version": "7"
}
end
def new_driver
Selenium::WebDriver.for :remote, :url => browserstack_endpoint, :desired_capabilities => caps
end
end
end
require_relative './spec_helper.rb'
require 'selenium-webdriver'
describe "Visiting Sign in page" do
it "loads the form successfully", :run_on_browserstack => 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 'rspec'
require_relative './browserstack_driver.rb'
require 'browserstack/local'
BROWSERSTACK_ACCESS_KEY = ENV['BROWSERSTACK_ACCESS_KEY']
run_local = false
RSpec.configure do |config|
config.around(:example, :run_on_browserstack => true) do |example|
@driver = BrowserStackDriver.new_driver
if run_local
@bs_local = BrowserStack::Local.new
bs_local_args = { "key" => "#{BROWSERSTACK_ACCESS_KEY}", "forcelocal" => true }
@bs_local.start(bs_local_args)
end
begin
example.run
ensure
@driver.quit
if run_local
@bs_local.stop
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.