sauce_bindings 1.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/.rspec +3 -0
- data/.rubocop.yml +49 -0
- data/.travis.yml +7 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +116 -0
- data/Rakefile +8 -0
- data/lib/sauce_bindings.rb +5 -0
- data/lib/sauce_bindings/capybara_session.rb +33 -0
- data/lib/sauce_bindings/options.rb +160 -0
- data/lib/sauce_bindings/session.rb +61 -0
- data/lib/sauce_bindings/version.rb +5 -0
- data/sauce_bindings.gemspec +33 -0
- data/spec/capybara_session_spec.rb +87 -0
- data/spec/options.yml +56 -0
- data/spec/options_spec.rb +470 -0
- data/spec/session_spec.rb +197 -0
- data/spec/spec_helper.rb +10 -0
- metadata +213 -0
@@ -0,0 +1,61 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'sauce_whisk'
|
4
|
+
require 'selenium-webdriver'
|
5
|
+
|
6
|
+
module SauceBindings
|
7
|
+
class Session
|
8
|
+
DATA_CENTERS = {US_WEST: 'ondemand.us-west-1.saucelabs.com',
|
9
|
+
US_EAST: 'ondemand.us-east-1.saucelabs.com',
|
10
|
+
EU_VDC: 'ondemand.eu-central-1.saucelabs.com'}.freeze
|
11
|
+
|
12
|
+
attr_writer :url
|
13
|
+
attr_reader :driver, :options, :data_center
|
14
|
+
attr_accessor :http_client, :listener
|
15
|
+
|
16
|
+
def initialize(options = nil, data_center: nil, http_client: nil, listener: nil)
|
17
|
+
@options = options || Options.new
|
18
|
+
@http_client = http_client
|
19
|
+
@listener = listener
|
20
|
+
|
21
|
+
@username = ENV['SAUCE_USERNAME']
|
22
|
+
@access_key = ENV['SAUCE_ACCESS_KEY']
|
23
|
+
self.data_center = data_center || :US_WEST
|
24
|
+
end
|
25
|
+
|
26
|
+
def start
|
27
|
+
raise ArgumentError, "needs username; use `ENV['SAUCE_USERNAME']`" unless @username
|
28
|
+
raise ArgumentError, "needs access_key; use `ENV['SAUCE_ACCESS_KEY']`" unless @access_key
|
29
|
+
|
30
|
+
@driver = Selenium::WebDriver.for :remote, to_selenium
|
31
|
+
end
|
32
|
+
|
33
|
+
def stop(result)
|
34
|
+
return if @driver.nil?
|
35
|
+
|
36
|
+
SauceWhisk::Jobs.change_status(@driver.session_id, result)
|
37
|
+
@driver.quit
|
38
|
+
end
|
39
|
+
|
40
|
+
def data_center=(data_center)
|
41
|
+
unless DATA_CENTERS.key?(data_center)
|
42
|
+
msg = "#{data_center} is an invalid data center; specify :US_WEST, :US_EAST or :EU_VDC"
|
43
|
+
raise ArgumentError, msg
|
44
|
+
end
|
45
|
+
|
46
|
+
SauceWhisk.data_center = data_center
|
47
|
+
@data_center = data_center
|
48
|
+
end
|
49
|
+
|
50
|
+
def url
|
51
|
+
@url ||= "https://#{@username}:#{@access_key}@#{DATA_CENTERS[data_center]}:443/wd/hub"
|
52
|
+
end
|
53
|
+
|
54
|
+
def to_selenium
|
55
|
+
caps = {url: url, desired_capabilities: options.capabilities}
|
56
|
+
caps[:listener] = listener if listener
|
57
|
+
caps[:http_client] = http_client if http_client
|
58
|
+
caps
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
4
|
+
$LOAD_PATH.unshift lib unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'sauce_bindings/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'sauce_bindings'
|
9
|
+
spec.version = SauceBindings::VERSION
|
10
|
+
spec.authors = ['Titus Fortner']
|
11
|
+
spec.email = ['titusfortner@gmail.com']
|
12
|
+
|
13
|
+
spec.summary = 'Simple interface for interacting with Sauce Labs.'
|
14
|
+
spec.description = 'Reduces complexity in user code for running Selenium tests on Sauce Labs'
|
15
|
+
spec.homepage = 'https://github.com/saucelabs/sauce_bindings'
|
16
|
+
spec.license = 'MIT'
|
17
|
+
|
18
|
+
spec.files = `git ls-files`.split("\n")
|
19
|
+
spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
|
22
|
+
spec.add_development_dependency 'bundler', '~> 2.0'
|
23
|
+
spec.add_development_dependency 'capybara', '~> 3.16'
|
24
|
+
spec.add_development_dependency 'rake', '>= 12.3.3'
|
25
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
26
|
+
spec.add_development_dependency 'rubocop', '~>0.66'
|
27
|
+
spec.add_development_dependency 'rubocop-performance'
|
28
|
+
spec.add_development_dependency 'rubocop-rspec', '~>1.32'
|
29
|
+
spec.add_development_dependency 'webmock', '~> 3.5'
|
30
|
+
|
31
|
+
spec.add_runtime_dependency 'sauce_whisk'
|
32
|
+
spec.add_runtime_dependency 'selenium-webdriver', '~> 3.142.0', '>= 3.142.7'
|
33
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'webmock/rspec'
|
5
|
+
require 'sauce_bindings/capybara_session'
|
6
|
+
|
7
|
+
module SauceBindings
|
8
|
+
describe CapybaraSession do
|
9
|
+
let(:valid_response) do
|
10
|
+
{status: 200,
|
11
|
+
body: {value: {sessionId: '0', capabilities: Selenium::WebDriver::Remote::Capabilities.chrome}}.to_json,
|
12
|
+
headers: {"content_type": 'application/json'}}
|
13
|
+
end
|
14
|
+
let(:default_capabilities) do
|
15
|
+
{browserName: 'chrome',
|
16
|
+
browserVersion: 'latest',
|
17
|
+
platformName: 'Windows 10',
|
18
|
+
'sauce:options': {build: 'TEMP BUILD: 11'}}
|
19
|
+
end
|
20
|
+
|
21
|
+
def expect_request(body: nil, endpoint: nil)
|
22
|
+
body = (body || {desiredCapabilities: default_capabilities,
|
23
|
+
capabilities: {firstMatch: [default_capabilities]}}).to_json
|
24
|
+
endpoint ||= 'https://ondemand.us-west-1.saucelabs.com/wd/hub/session'
|
25
|
+
stub_request(:post, endpoint).with(body: body).to_return(valid_response)
|
26
|
+
end
|
27
|
+
|
28
|
+
before do
|
29
|
+
ENV['BUILD_TAG'] = ''
|
30
|
+
ENV['BUILD_NAME'] = 'TEMP BUILD'
|
31
|
+
ENV['BUILD_NUMBER'] = '11'
|
32
|
+
ENV['SAUCE_USERNAME'] = 'foo'
|
33
|
+
ENV['SAUCE_ACCESS_KEY'] = '123'
|
34
|
+
end
|
35
|
+
|
36
|
+
after do
|
37
|
+
ENV.delete 'BUILD_TAG'
|
38
|
+
ENV.delete 'BUILD_NAME'
|
39
|
+
ENV.delete 'BUILD_NUMBER'
|
40
|
+
ENV.delete 'SAUCE_USERNAME'
|
41
|
+
ENV.delete 'SAUCE_ACCESS_KEY'
|
42
|
+
end
|
43
|
+
|
44
|
+
describe '#new' do
|
45
|
+
it 'registers a Capybara Driver' do
|
46
|
+
CapybaraSession.new
|
47
|
+
|
48
|
+
expect(Capybara.drivers).to include(:sauce)
|
49
|
+
expect(Capybara.current_driver).to eq :sauce
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe '#start' do
|
54
|
+
it 'starts the session with Capybara driver' do
|
55
|
+
expect_request
|
56
|
+
|
57
|
+
driver = CapybaraSession.new.start
|
58
|
+
expect(driver).to eq Capybara.current_session.driver.browser
|
59
|
+
|
60
|
+
Capybara.current_session.driver.instance_variable_set('@browser', nil)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe '#stop' do
|
65
|
+
it 'quits the driver' do
|
66
|
+
cappy_driver = instance_double(Capybara::Selenium::Driver)
|
67
|
+
driver = instance_double(Selenium::WebDriver::Remote::Driver, session_id: '1234')
|
68
|
+
allow(cappy_driver).to receive(:browser).and_return(driver)
|
69
|
+
|
70
|
+
allow(SauceWhisk::Jobs).to receive(:change_status).with('1234', true)
|
71
|
+
|
72
|
+
session = CapybaraSession.new
|
73
|
+
|
74
|
+
allow(Capybara.current_session).to receive(:driver).and_return(cappy_driver)
|
75
|
+
allow(Capybara.current_session).to receive(:quit)
|
76
|
+
|
77
|
+
session.start
|
78
|
+
session.stop(true)
|
79
|
+
|
80
|
+
expect(SauceWhisk::Jobs).to have_received(:change_status).with('1234', true)
|
81
|
+
expect(Capybara.current_session).to have_received(:quit)
|
82
|
+
|
83
|
+
Capybara.current_session.driver.instance_variable_set('@browser', nil)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
data/spec/options.yml
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
example_values:
|
2
|
+
browser_name: 'firefox'
|
3
|
+
browser_version: '123'
|
4
|
+
platform_name: 'Mac'
|
5
|
+
accept_insecure_certs: true
|
6
|
+
page_load_strategy: 'eager'
|
7
|
+
set_window_rect: true
|
8
|
+
unhandled_prompt_behavior: "accept"
|
9
|
+
strict_file_interactability: true
|
10
|
+
timeouts:
|
11
|
+
implicit: 1
|
12
|
+
page_load: 59
|
13
|
+
script: 29
|
14
|
+
avoid_proxy: true
|
15
|
+
build: 'Sample Build Name'
|
16
|
+
capture_performance: true
|
17
|
+
chromedriver_version: '71'
|
18
|
+
command_timeout: 2
|
19
|
+
custom_data:
|
20
|
+
foo: 'foo'
|
21
|
+
bar: 'bar'
|
22
|
+
extended_debugging: true
|
23
|
+
idle_timeout: 3
|
24
|
+
iedriver_version: '3.141.0'
|
25
|
+
max_duration: 300
|
26
|
+
name: 'Sample Test Name'
|
27
|
+
parent_tunnel: 'Mommy'
|
28
|
+
prerun:
|
29
|
+
executable: "http://url.to/your/executable.exe"
|
30
|
+
args:
|
31
|
+
- --silent
|
32
|
+
- -a
|
33
|
+
- -q
|
34
|
+
background: false
|
35
|
+
timeout: 120
|
36
|
+
priority: 0
|
37
|
+
public: 'team'
|
38
|
+
record_logs: false
|
39
|
+
record_screenshots: false
|
40
|
+
record_video: false
|
41
|
+
screen_resolution: '10x10'
|
42
|
+
selenium_version: '3.141.59'
|
43
|
+
tags:
|
44
|
+
- foo
|
45
|
+
- bar
|
46
|
+
- foobar
|
47
|
+
time_zone: 'San Francisco'
|
48
|
+
tunnel_identifier: 'tunnelname'
|
49
|
+
video_upload_on_pass: false
|
50
|
+
|
51
|
+
invalid_option:
|
52
|
+
foo: "bar"
|
53
|
+
browser_name: "firefox"
|
54
|
+
browser_version: "70"
|
55
|
+
platform_name: "MacOS 10.12"
|
56
|
+
record_screenshots: false
|
@@ -0,0 +1,470 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
module SauceBindings
|
6
|
+
describe Options do
|
7
|
+
before do
|
8
|
+
ENV['BUILD_TAG'] = ''
|
9
|
+
ENV['BUILD_NAME'] = 'TEMP BUILD'
|
10
|
+
ENV['BUILD_NUMBER'] = '11'
|
11
|
+
end
|
12
|
+
|
13
|
+
after { ENV.delete 'BUILD_TAG' }
|
14
|
+
|
15
|
+
describe '#new' do
|
16
|
+
let(:default_options) do
|
17
|
+
{'browserName' => 'chrome',
|
18
|
+
'browserVersion' => 'latest',
|
19
|
+
'platformName' => 'Windows 10',
|
20
|
+
'sauce:options' => {'build' => 'TEMP BUILD: 11'}}
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'uses latest Chrome version on Windows 10 by default' do
|
24
|
+
options = Options.new
|
25
|
+
|
26
|
+
expect(options.browser_name).to eq 'chrome'
|
27
|
+
expect(options.browser_version).to eq 'latest'
|
28
|
+
expect(options.platform_name).to eq 'Windows 10'
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'accepts provided values for browser, browser version and platform name' do
|
32
|
+
options = Options.new(browser_name: 'firefox',
|
33
|
+
browser_version: '123',
|
34
|
+
platform_name: 'Mac')
|
35
|
+
|
36
|
+
expect(options.browser_name).to eq 'firefox'
|
37
|
+
expect(options.browser_version).to eq '123'
|
38
|
+
expect(options.platform_name).to eq 'Mac'
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'accepts other w3c values' do
|
42
|
+
proxy = Selenium::WebDriver::Proxy.new(ssl: 'foo')
|
43
|
+
timeouts = {implicit: 1,
|
44
|
+
page_load: 59,
|
45
|
+
script: 29}
|
46
|
+
options = Options.new(accept_insecure_certs: true,
|
47
|
+
page_load_strategy: 'eager',
|
48
|
+
proxy: proxy,
|
49
|
+
set_window_rect: true,
|
50
|
+
unhandled_prompt_behavior: 'accept',
|
51
|
+
strict_file_interactability: true,
|
52
|
+
timeouts: timeouts)
|
53
|
+
|
54
|
+
expect(options.accept_insecure_certs).to eq true
|
55
|
+
expect(options.page_load_strategy).to eq 'eager'
|
56
|
+
expect(options.proxy).to eq proxy
|
57
|
+
expect(options.set_window_rect).to eq true
|
58
|
+
expect(options.unhandled_prompt_behavior).to eq 'accept'
|
59
|
+
expect(options.strict_file_interactability).to eq true
|
60
|
+
expect(options.timeouts).to eq timeouts
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'accepts Sauce Labs specific settings' do
|
64
|
+
custom_data = {foo: 'foo',
|
65
|
+
bar: 'bar'}
|
66
|
+
prerun = {executable: 'http://url.to/your/executable.exe',
|
67
|
+
args: ['--silent', '-a', '-q'],
|
68
|
+
background: false,
|
69
|
+
timeout: 120}
|
70
|
+
tags = %w[foo bar foobar]
|
71
|
+
sauce_options = {
|
72
|
+
avoid_proxy: true,
|
73
|
+
build: 'Sample Build Name',
|
74
|
+
capture_performance: true,
|
75
|
+
chromedriver_version: '71',
|
76
|
+
command_timeout: 2,
|
77
|
+
custom_data: custom_data,
|
78
|
+
extended_debugging: true,
|
79
|
+
idle_timeout: 3,
|
80
|
+
iedriver_version: '3.141.0',
|
81
|
+
max_duration: 300,
|
82
|
+
name: 'Sample Test Name',
|
83
|
+
parent_tunnel: 'Mommy',
|
84
|
+
prerun: prerun,
|
85
|
+
priority: 0,
|
86
|
+
public: 'team',
|
87
|
+
record_logs: false,
|
88
|
+
record_screenshots: false,
|
89
|
+
record_video: false,
|
90
|
+
screen_resolution: '10x10',
|
91
|
+
selenium_version: '3.141.59',
|
92
|
+
tags: tags,
|
93
|
+
time_zone: 'San Francisco',
|
94
|
+
tunnel_identifier: 'tunnelname',
|
95
|
+
video_upload_on_pass: false
|
96
|
+
}
|
97
|
+
|
98
|
+
options = Options.new(**sauce_options)
|
99
|
+
|
100
|
+
expect(options.avoid_proxy).to eq true
|
101
|
+
expect(options.build).to eq 'Sample Build Name'
|
102
|
+
expect(options.capture_performance).to eq true
|
103
|
+
expect(options.chromedriver_version).to eq '71'
|
104
|
+
expect(options.command_timeout).to eq 2
|
105
|
+
expect(options.custom_data).to eq custom_data
|
106
|
+
expect(options.extended_debugging).to eq true
|
107
|
+
expect(options.idle_timeout).to eq 3
|
108
|
+
expect(options.iedriver_version).to eq '3.141.0'
|
109
|
+
expect(options.max_duration).to eq 300
|
110
|
+
expect(options.name).to eq 'Sample Test Name'
|
111
|
+
expect(options.parent_tunnel).to eq 'Mommy'
|
112
|
+
expect(options.prerun).to eq prerun
|
113
|
+
expect(options.priority).to eq 0
|
114
|
+
expect(options.public).to eq 'team'
|
115
|
+
expect(options.record_logs).to eq false
|
116
|
+
expect(options.record_screenshots).to eq false
|
117
|
+
expect(options.record_video).to eq false
|
118
|
+
expect(options.screen_resolution).to eq '10x10'
|
119
|
+
expect(options.selenium_version).to eq '3.141.59'
|
120
|
+
expect(options.tags).to eq tags
|
121
|
+
expect(options.time_zone).to eq 'San Francisco'
|
122
|
+
expect(options.tunnel_identifier).to eq 'tunnelname'
|
123
|
+
expect(options.video_upload_on_pass).to eq false
|
124
|
+
end
|
125
|
+
|
126
|
+
it 'accepts Selenium Capabilities and overrides default browser' do
|
127
|
+
caps = Selenium::WebDriver::Remote::Capabilities.firefox(accept_insecure_certs: true,
|
128
|
+
page_load_strategy: 'eager')
|
129
|
+
options = Options.new(selenium_options: caps)
|
130
|
+
|
131
|
+
expect(options.browser_name).to eq 'firefox'
|
132
|
+
expect(options.accept_insecure_certs).to eq true
|
133
|
+
expect(options.page_load_strategy).to eq 'eager'
|
134
|
+
end
|
135
|
+
|
136
|
+
it 'accepts Selenium Options and overrides default browser' do
|
137
|
+
browser_opts = Selenium::WebDriver::Firefox::Options.new(args: ['--foo'])
|
138
|
+
options = Options.new(selenium_options: browser_opts)
|
139
|
+
|
140
|
+
expect(options.browser_name).to eq 'firefox'
|
141
|
+
expect(options.selenium_options['moz:firefoxOptions']).to eq('args' => ['--foo'])
|
142
|
+
end
|
143
|
+
|
144
|
+
it 'accepts Selenium Capabilities and Options class instances' do
|
145
|
+
caps = Selenium::WebDriver::Remote::Capabilities.chrome(accept_insecure_certs: true,
|
146
|
+
page_load_strategy: 'eager')
|
147
|
+
browser_opts = Selenium::WebDriver::Chrome::Options.new(args: ['--foo'])
|
148
|
+
options = Options.new(selenium_options: [caps, browser_opts])
|
149
|
+
|
150
|
+
expect(options.page_load_strategy).to eq 'eager'
|
151
|
+
expect(options.accept_insecure_certs).to eq true
|
152
|
+
expect(options.selenium_options['goog:chromeOptions']).to eq('args' => ['--foo'])
|
153
|
+
end
|
154
|
+
|
155
|
+
it 'accepts W3C, Sauce, Browser Options and Capabilities at the same time' do
|
156
|
+
caps = Selenium::WebDriver::Remote::Capabilities.chrome(page_load_strategy: 'eager')
|
157
|
+
browser_opts = Selenium::WebDriver::Firefox::Options.new(args: ['--foo'])
|
158
|
+
|
159
|
+
options = Options.new(browser_version: '77',
|
160
|
+
accept_insecure_certs: true,
|
161
|
+
command_timeout: 2,
|
162
|
+
time_zone: 'Alaska',
|
163
|
+
selenium_options: [caps, browser_opts])
|
164
|
+
|
165
|
+
expect(options.browser_name).to eq 'firefox'
|
166
|
+
expect(options.browser_version).to eq '77'
|
167
|
+
expect(options.platform_name).to eq 'Windows 10'
|
168
|
+
expect(options.accept_insecure_certs).to eq true
|
169
|
+
expect(options.command_timeout).to eq 2
|
170
|
+
expect(options.time_zone).to eq 'Alaska'
|
171
|
+
expect(options.page_load_strategy).to eq 'eager'
|
172
|
+
|
173
|
+
expect(options.selenium_options['moz:firefoxOptions']).to eq('args' => ['--foo'])
|
174
|
+
end
|
175
|
+
|
176
|
+
it 'creates a default build value' do
|
177
|
+
options = Options.new
|
178
|
+
expect(options.build).to eq 'TEMP BUILD: 11'
|
179
|
+
end
|
180
|
+
|
181
|
+
it 'raises ArgumentError if parameter is not recognized as valid' do
|
182
|
+
expect { Options.new(foo: 'bar') }.to raise_exception(ArgumentError)
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
describe '#accessors' do
|
187
|
+
it 'parses w3c values' do
|
188
|
+
proxy = Selenium::WebDriver::Proxy.new(ssl: 'foo')
|
189
|
+
timeouts = {implicit: 1,
|
190
|
+
page_load: 59,
|
191
|
+
script: 29}
|
192
|
+
|
193
|
+
options = Options.new
|
194
|
+
|
195
|
+
options.browser_name = 'firefox'
|
196
|
+
options.browser_version = '7'
|
197
|
+
options.platform_name = 'macOS 10.14'
|
198
|
+
options.accept_insecure_certs = true
|
199
|
+
options.page_load_strategy = 'eager'
|
200
|
+
options.proxy = proxy
|
201
|
+
options.set_window_rect = true
|
202
|
+
options.unhandled_prompt_behavior = 'accept'
|
203
|
+
options.strict_file_interactability = true
|
204
|
+
options.timeouts = timeouts
|
205
|
+
|
206
|
+
expect(options.browser_name).to eq 'firefox'
|
207
|
+
expect(options.browser_version).to eq '7'
|
208
|
+
expect(options.platform_name).to eq 'macOS 10.14'
|
209
|
+
expect(options.accept_insecure_certs).to eq true
|
210
|
+
expect(options.page_load_strategy).to eq 'eager'
|
211
|
+
expect(options.proxy).to eq proxy
|
212
|
+
expect(options.set_window_rect).to eq true
|
213
|
+
expect(options.unhandled_prompt_behavior).to eq 'accept'
|
214
|
+
expect(options.strict_file_interactability).to eq true
|
215
|
+
expect(options.timeouts).to eq timeouts
|
216
|
+
end
|
217
|
+
|
218
|
+
it 'parses Sauce values' do
|
219
|
+
custom_data = {foo: 'foo',
|
220
|
+
bar: 'bar'}
|
221
|
+
prerun = {executable: 'http://url.to/your/executable.exe',
|
222
|
+
args: ['--silent', '-a', '-q'],
|
223
|
+
background: false,
|
224
|
+
timeout: 120}
|
225
|
+
tags = %w[foo bar foobar]
|
226
|
+
|
227
|
+
options = Options.new
|
228
|
+
|
229
|
+
options.avoid_proxy = true
|
230
|
+
options.build = 'Sample Build Name'
|
231
|
+
options.capture_performance = true
|
232
|
+
options.chromedriver_version = '71'
|
233
|
+
options.command_timeout = 2
|
234
|
+
options.custom_data = custom_data
|
235
|
+
options.extended_debugging = true
|
236
|
+
options.idle_timeout = 3
|
237
|
+
options.iedriver_version = '3.141.0'
|
238
|
+
options.max_duration = 300
|
239
|
+
options.name = 'Sample Test Name'
|
240
|
+
options.parent_tunnel = 'Mommy'
|
241
|
+
options.prerun = prerun
|
242
|
+
options.priority = 0
|
243
|
+
options.public = 'team'
|
244
|
+
options.record_logs = false
|
245
|
+
options.record_screenshots = false
|
246
|
+
options.record_video = false
|
247
|
+
options.screen_resolution = '10x10'
|
248
|
+
options.selenium_version = '3.141.59'
|
249
|
+
options.tags = tags
|
250
|
+
options.time_zone = 'San Francisco'
|
251
|
+
options.tunnel_identifier = 'tunnelname'
|
252
|
+
options.video_upload_on_pass = false
|
253
|
+
|
254
|
+
expect(options.avoid_proxy).to eq true
|
255
|
+
expect(options.build).to eq 'Sample Build Name'
|
256
|
+
expect(options.capture_performance).to eq true
|
257
|
+
expect(options.chromedriver_version).to eq '71'
|
258
|
+
expect(options.command_timeout).to eq 2
|
259
|
+
expect(options.custom_data).to eq custom_data
|
260
|
+
expect(options.extended_debugging).to eq true
|
261
|
+
expect(options.idle_timeout).to eq 3
|
262
|
+
expect(options.iedriver_version).to eq '3.141.0'
|
263
|
+
expect(options.max_duration).to eq 300
|
264
|
+
expect(options.name).to eq 'Sample Test Name'
|
265
|
+
expect(options.parent_tunnel).to eq 'Mommy'
|
266
|
+
expect(options.prerun).to eq prerun
|
267
|
+
expect(options.priority).to eq 0
|
268
|
+
expect(options.public).to eq 'team'
|
269
|
+
expect(options.record_logs).to eq false
|
270
|
+
expect(options.record_screenshots).to eq false
|
271
|
+
expect(options.record_video).to eq false
|
272
|
+
expect(options.screen_resolution).to eq '10x10'
|
273
|
+
expect(options.selenium_version).to eq '3.141.59'
|
274
|
+
expect(options.tags).to eq tags
|
275
|
+
expect(options.time_zone).to eq 'San Francisco'
|
276
|
+
expect(options.tunnel_identifier).to eq 'tunnelname'
|
277
|
+
expect(options.video_upload_on_pass).to eq false
|
278
|
+
end
|
279
|
+
end
|
280
|
+
|
281
|
+
describe '#merge_capabilities' do
|
282
|
+
it 'loads options from configuration' do
|
283
|
+
timeouts = {implicit: 1,
|
284
|
+
page_load: 59,
|
285
|
+
script: 29}
|
286
|
+
custom_data = {foo: 'foo',
|
287
|
+
bar: 'bar'}
|
288
|
+
prerun = {executable: 'http://url.to/your/executable.exe',
|
289
|
+
args: ['--silent', '-a', '-q'],
|
290
|
+
background: false,
|
291
|
+
timeout: 120}
|
292
|
+
tags = %w[foo bar foobar]
|
293
|
+
|
294
|
+
options = Options.new
|
295
|
+
yaml = YAML.load_file('spec/options.yml')
|
296
|
+
options.merge_capabilities(yaml['example_values'])
|
297
|
+
|
298
|
+
expect(options.browser_name).to eq 'firefox'
|
299
|
+
expect(options.browser_version).to eq '123'
|
300
|
+
expect(options.platform_name).to eq 'Mac'
|
301
|
+
expect(options.accept_insecure_certs).to eq true
|
302
|
+
expect(options.page_load_strategy).to eq 'eager'
|
303
|
+
expect(options.set_window_rect).to eq true
|
304
|
+
expect(options.unhandled_prompt_behavior).to eq 'accept'
|
305
|
+
expect(options.strict_file_interactability).to eq true
|
306
|
+
expect(options.timeouts).to eq timeouts
|
307
|
+
expect(options.avoid_proxy).to eq true
|
308
|
+
expect(options.build).to eq 'Sample Build Name'
|
309
|
+
expect(options.capture_performance).to eq true
|
310
|
+
expect(options.chromedriver_version).to eq '71'
|
311
|
+
expect(options.command_timeout).to eq 2
|
312
|
+
expect(options.custom_data).to eq custom_data
|
313
|
+
expect(options.extended_debugging).to eq true
|
314
|
+
expect(options.idle_timeout).to eq 3
|
315
|
+
expect(options.iedriver_version).to eq '3.141.0'
|
316
|
+
expect(options.max_duration).to eq 300
|
317
|
+
expect(options.name).to eq 'Sample Test Name'
|
318
|
+
expect(options.parent_tunnel).to eq 'Mommy'
|
319
|
+
expect(options.prerun).to eq prerun
|
320
|
+
expect(options.priority).to eq 0
|
321
|
+
expect(options.public).to eq 'team'
|
322
|
+
expect(options.record_logs).to eq false
|
323
|
+
expect(options.record_screenshots).to eq false
|
324
|
+
expect(options.record_video).to eq false
|
325
|
+
expect(options.screen_resolution).to eq '10x10'
|
326
|
+
expect(options.selenium_version).to eq '3.141.59'
|
327
|
+
expect(options.tags).to eq tags
|
328
|
+
expect(options.time_zone).to eq 'San Francisco'
|
329
|
+
expect(options.tunnel_identifier).to eq 'tunnelname'
|
330
|
+
expect(options.video_upload_on_pass).to eq false
|
331
|
+
end
|
332
|
+
|
333
|
+
it 'raises exception if value not recognized' do
|
334
|
+
options = Options.new
|
335
|
+
yaml = YAML.load_file('spec/options.yml')
|
336
|
+
|
337
|
+
msg = 'foo is not a valid parameter for Options class'
|
338
|
+
expect { options.merge_capabilities(yaml['invalid_option']) }.to raise_exception(ArgumentError, msg)
|
339
|
+
end
|
340
|
+
end
|
341
|
+
|
342
|
+
describe '#capabilities' do
|
343
|
+
it 'correctly generates capabilities for w3c values' do
|
344
|
+
proxy = Selenium::WebDriver::Proxy.new(ssl: 'foo')
|
345
|
+
timeouts = {implicit: 1,
|
346
|
+
page_load: 59,
|
347
|
+
script: 29}
|
348
|
+
|
349
|
+
options = Options.new(browser_name: 'firefox',
|
350
|
+
platform_name: 'Mac',
|
351
|
+
accept_insecure_certs: true,
|
352
|
+
page_load_strategy: 'eager',
|
353
|
+
proxy: proxy,
|
354
|
+
set_window_rect: true,
|
355
|
+
unhandled_prompt_behavior: 'accept',
|
356
|
+
strict_file_interactability: true,
|
357
|
+
timeouts: timeouts)
|
358
|
+
|
359
|
+
expect(options.capabilities).to eq('browserName' => 'firefox',
|
360
|
+
'browserVersion' => 'latest',
|
361
|
+
'platformName' => 'Mac',
|
362
|
+
'acceptInsecureCerts' => true,
|
363
|
+
'pageLoadStrategy' => 'eager',
|
364
|
+
'proxy' => {'proxyType' => 'MANUAL', 'sslProxy' => 'foo'},
|
365
|
+
'setWindowRect' => true,
|
366
|
+
'unhandledPromptBehavior' => 'accept',
|
367
|
+
'strictFileInteractability' => true,
|
368
|
+
'timeouts' => {'implicit' => 1,
|
369
|
+
'pageLoad' => 59,
|
370
|
+
'script' => 29},
|
371
|
+
'sauce:options' => {'build' => 'TEMP BUILD: 11'})
|
372
|
+
end
|
373
|
+
|
374
|
+
it 'correctly generates capabilities for sauce values' do
|
375
|
+
custom_data = {foo: 'foo',
|
376
|
+
bar: 'bar'}
|
377
|
+
prerun = {executable: 'http://url.to/your/executable.exe',
|
378
|
+
args: ['--silent', '-a', '-q'],
|
379
|
+
background: false,
|
380
|
+
timeout: 120}
|
381
|
+
tags = %w[foo bar foobar]
|
382
|
+
sauce_options = {avoid_proxy: true,
|
383
|
+
build: 'Sample Build Name',
|
384
|
+
capture_performance: true,
|
385
|
+
chromedriver_version: '71',
|
386
|
+
command_timeout: 2,
|
387
|
+
custom_data: custom_data,
|
388
|
+
extended_debugging: true,
|
389
|
+
idle_timeout: 3,
|
390
|
+
iedriver_version: '3.141.0',
|
391
|
+
max_duration: 300,
|
392
|
+
name: 'Sample Test Name',
|
393
|
+
parent_tunnel: 'Mommy',
|
394
|
+
prerun: prerun,
|
395
|
+
priority: 0,
|
396
|
+
public: 'team',
|
397
|
+
record_logs: false,
|
398
|
+
record_screenshots: false,
|
399
|
+
record_video: false,
|
400
|
+
screen_resolution: '10x10',
|
401
|
+
selenium_version: '3.141.59',
|
402
|
+
tags: tags,
|
403
|
+
time_zone: 'San Francisco',
|
404
|
+
tunnel_identifier: 'tunnelname',
|
405
|
+
video_upload_on_pass: false}
|
406
|
+
|
407
|
+
options = Options.new(**sauce_options)
|
408
|
+
|
409
|
+
prerun_caps = {'executable' => 'http://url.to/your/executable.exe',
|
410
|
+
'args' => ['--silent', '-a', '-q'],
|
411
|
+
'background' => false,
|
412
|
+
'timeout' => 120}
|
413
|
+
|
414
|
+
expect(options.capabilities).to eq('browserName' => 'chrome',
|
415
|
+
'browserVersion' => 'latest',
|
416
|
+
'platformName' => 'Windows 10',
|
417
|
+
'sauce:options' => {'build' => 'Sample Build Name',
|
418
|
+
'avoidProxy' => true,
|
419
|
+
'capturePerformance' => true,
|
420
|
+
'chromedriverVersion' => '71',
|
421
|
+
'commandTimeout' => 2,
|
422
|
+
'customData' => {'foo' => 'foo',
|
423
|
+
'bar' => 'bar'},
|
424
|
+
'extendedDebugging' => true,
|
425
|
+
'idleTimeout' => 3,
|
426
|
+
'iedriverVersion' => '3.141.0',
|
427
|
+
'maxDuration' => 300,
|
428
|
+
'name' => 'Sample Test Name',
|
429
|
+
'parentTunnel' => 'Mommy',
|
430
|
+
'prerun' => prerun_caps,
|
431
|
+
'priority' => 0,
|
432
|
+
'public' => 'team',
|
433
|
+
'recordLogs' => false,
|
434
|
+
'recordScreenshots' => false,
|
435
|
+
'recordVideo' => false,
|
436
|
+
'screenResolution' => '10x10',
|
437
|
+
'seleniumVersion' => '3.141.59',
|
438
|
+
'tags' => %w[foo bar foobar],
|
439
|
+
'timeZone' => 'San Francisco',
|
440
|
+
'tunnelIdentifier' => 'tunnelname',
|
441
|
+
'videoUploadOnPass' => false})
|
442
|
+
end
|
443
|
+
|
444
|
+
it 'correctly generates capabilities for selenium object values' do
|
445
|
+
caps = Selenium::WebDriver::Remote::Capabilities.chrome(accept_insecure_certs: true,
|
446
|
+
page_load_strategy: 'eager')
|
447
|
+
browser_opts = Selenium::WebDriver::Chrome::Options.new(args: ['--foo'])
|
448
|
+
options = Options.new(selenium_options: [caps, browser_opts])
|
449
|
+
|
450
|
+
jwp_defaults = {'cssSelectorsEnabled' => true,
|
451
|
+
'javascriptEnabled' => true,
|
452
|
+
'nativeEvents' => false,
|
453
|
+
'platform' => 'ANY',
|
454
|
+
'rotatable' => false,
|
455
|
+
'takesScreenshot' => false,
|
456
|
+
'version' => ''}
|
457
|
+
|
458
|
+
expected_caps = {'browserName' => 'chrome',
|
459
|
+
'browserVersion' => 'latest',
|
460
|
+
'platformName' => 'Windows 10',
|
461
|
+
'acceptInsecureCerts' => true,
|
462
|
+
'pageLoadStrategy' => 'eager',
|
463
|
+
'sauce:options' => {'build' => 'TEMP BUILD: 11'},
|
464
|
+
'goog:chromeOptions' => {'args' => ['--foo']}}
|
465
|
+
|
466
|
+
expect(options.capabilities).to eq(jwp_defaults.merge(expected_caps))
|
467
|
+
end
|
468
|
+
end
|
469
|
+
end
|
470
|
+
end
|