Created
July 17, 2015 00:08
-
-
Save DylanLacey/0a189c4896ed85b3b911 to your computer and use it in GitHub Desktop.
Simple RSpec Selenium
This file contains hidden or 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" | |
describe "Google's Search Functionality" do | |
it "can find search results", :run_on_sauce => true do | |
@driver.manage.timeouts.implicit_wait = 10 | |
@driver.navigate.to "http://www.google.com" | |
raise SystemError("Unable to load Google.") unless @driver.title.include? "Google" | |
query = @driver.find_element :name, "q" | |
query.send_keys "Sauce Labs" | |
query.submit | |
puts @driver.title | |
end | |
end |
This file contains hidden or 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 SauceDriver | |
class << self | |
def sauce_endpoint | |
"http://#{ENV["SAUCE_USERNAME"]}:#{ENV['SAUCE_ACCESS_KEY']}@ondemand.saucelabs.com:80/wd/hub" | |
end | |
def caps | |
caps = { | |
:platform => "Mac OS X 10.9", | |
:browserName => "Chrome", | |
:version => "31" | |
} | |
end | |
def new_driver | |
Selenium::WebDriver.for :remote, :url => sauce_endpoint, :desired_capabilities => caps | |
end | |
end | |
end |
This file contains hidden or 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 "sauce_helper" | |
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