Instantly share code, notes, and snippets.

Embed
What would you like to do?
Example CrossBrowserTesting rspec test
require "selenium/webdriver"
module CrossBrowserTestingDriver
class << self
def cbt_endpoint
username = 'yourusername'
authkey = 'yourauthkey'
"http://#{username}:#{authkey}@hub.crossbrowsertesting.com:80/wd/hub"
end
def caps
caps = Selenium::WebDriver::Remote::Capabilities.new
caps["name"] = "Selenium Test Example"
caps["build"] = "1.0"
caps["browser_api_name"] = "IE10"
caps["os_api_name"] = "Win7x64-C2"
caps["screen_resolution"] = "1024x768"
caps["record_video"] = "true"
caps["record_network"] = "true"
caps
end
def new_driver
Selenium::WebDriver.for :remote, :url => cbt_endpoint, :desired_capabilities => caps
end
end
end
require_relative "spec_helper"
describe "Visiting Sign in page" do
it "loads the form successfully", :run_on_cbt => 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 "cross_browser_testing_driver"
RSpec.configure do |config|
config.around(:example, :run_on_cbt => true) do |example|
@driver = CrossBrowserTestingDriver.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