-
-
Save robustdj/ba5a2bec49126e0efb33c7e1a9b7f802 to your computer and use it in GitHub Desktop.
Example BrowserStack rspec test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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