forked from saucelabs/the-internet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspec_helper.rb
43 lines (38 loc) · 1.29 KB
/
spec_helper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
require 'selenium-webdriver'
require 'sauce_whisk'
RSpec.configure do |config|
config.before(:each) do |example|
ENV['host'] ||= 'saucelabs'
ENV['base_url'] ||= 'http://the-internet.herokuapp.com'
ENV['operating_system'] ||= 'Windows 10'
ENV['browser'] ||= 'firefox'
ENV['browser_version'] ||= '50.0'
case ENV['host']
when 'localhost'
@driver = Selenium::WebDriver.for :chrome
when 'saucelabs'
caps = Selenium::WebDriver::Remote::Capabilities.send(ENV['browser'])
caps[:platform] = ENV['operating_system']
caps[:version] = ENV['browser_version']
caps[:name] = example.metadata[:full_description]
@driver = Selenium::WebDriver.for(
:remote,
url: "http://#{ENV['SAUCE_USERNAME']}:#{ENV['SAUCE_ACCESS_KEY']}@ondemand.saucelabs.com:80/wd/hub",
desired_capabilities: caps)
end
end
config.after(:each) do |example|
begin
if ENV['host'] == 'saucelabs'
if example.exception.nil?
SauceWhisk::Jobs.pass_job @driver.session_id
else
SauceWhisk::Jobs.fail_job @driver.session_id
raise "Watch a video of the test at https://saucelabs.com/tests/#{@driver.session_id}"
end
end
ensure
@driver.quit
end
end
end