Skip to content

Commit b44aee0

Browse files
committed
[rb] use options instead of capabilities
1 parent 77c4bf3 commit b44aee0

File tree

7 files changed

+37
-34
lines changed

7 files changed

+37
-34
lines changed

rb/spec/integration/selenium/webdriver/chrome/driver_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@ module Chrome
5858
let(:options) { Chrome::Options.new(args: ['--headless']) }
5959

6060
it 'should return base64 for print command' do
61-
create_driver!(capabilities: options) do |driver|
61+
create_driver!(options: options) do |driver|
6262
driver.navigate.to url_for('printPage.html')
6363
expect(driver.print_page).to include(magic_number)
6464
end
6565
end
6666

6767
it 'should print with valid params' do
68-
create_driver!(capabilities: options) do |driver|
68+
create_driver!(options: options) do |driver|
6969
driver.navigate.to url_for('printPage.html')
7070
expect(driver.print_page(orientation: 'landscape',
7171
page_ranges: ['1-2'],
@@ -74,7 +74,7 @@ module Chrome
7474
end
7575

7676
it 'should save pdf' do
77-
create_driver!(capabilities: options) do |driver|
77+
create_driver!(options: options) do |driver|
7878
driver.navigate.to url_for('printPage.html')
7979

8080
path = "#{Dir.tmpdir}/test#{SecureRandom.urlsafe_base64}.pdf"
@@ -95,7 +95,7 @@ module Chrome
9595
options = Options.new(logging_prefs: {browser: 'ALL',
9696
driver: 'ALL',
9797
performance: 'ALL'})
98-
create_driver!(capabilities: options)
98+
create_driver!(options: options)
9999
driver.navigate.to url_for('errors.html')
100100
end
101101

rb/spec/integration/selenium/webdriver/chrome/options_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ module Chrome
3030
it 'passes emulated device correctly' do
3131
options.add_emulation(device_name: 'Nexus 5')
3232

33-
create_driver!(capabilities: options) do |driver|
33+
create_driver!(options: options) do |driver|
3434
ua = driver.execute_script 'return window.navigator.userAgent'
3535
expect(ua).to include('Nexus 5')
3636
end
@@ -39,7 +39,7 @@ module Chrome
3939
it 'passes emulated user agent correctly' do
4040
options.add_emulation(user_agent: 'foo;bar')
4141

42-
create_driver!(capabilities: options) do |driver|
42+
create_driver!(options: options) do |driver|
4343
ua = driver.execute_script 'return window.navigator.userAgent'
4444
expect(ua).to eq('foo;bar')
4545
end
@@ -48,7 +48,7 @@ module Chrome
4848
it 'passes args correctly' do
4949
options.add_argument('--user-agent=foo;bar')
5050

51-
create_driver!(capabilities: options) do |driver|
51+
create_driver!(options: options) do |driver|
5252
ua = driver.execute_script 'return window.navigator.userAgent'
5353
expect(ua).to eq('foo;bar')
5454
end
@@ -57,7 +57,7 @@ module Chrome
5757
it 'should be able to run in headless mode with #headless!' do
5858
options.headless!
5959

60-
create_driver!(capabilities: options) do |driver|
60+
create_driver!(options: options) do |driver|
6161
ua = driver.execute_script 'return window.navigator.userAgent'
6262
expect(ua).to match(/HeadlessChrome/)
6363
end

rb/spec/integration/selenium/webdriver/edge/driver_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ module Edge
7171
options = Options.new(logging_prefs: {browser: 'ALL',
7272
driver: 'ALL',
7373
performance: 'ALL'})
74-
create_driver!(capabilities: options)
74+
create_driver!(options: options)
7575
driver.navigate.to url_for('errors.html')
7676
end
7777

rb/spec/integration/selenium/webdriver/edge/options_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ module Edge
2828
it 'passes emulated device correctly' do
2929
options.add_emulation(device_name: 'Nexus 5')
3030

31-
create_driver!(capabilities: options) do |driver|
31+
create_driver!(options: options) do |driver|
3232
ua = driver.execute_script 'return window.navigator.userAgent'
3333
expect(ua).to include('Nexus 5')
3434
end
@@ -37,7 +37,7 @@ module Edge
3737
it 'passes emulated user agent correctly' do
3838
options.add_emulation(user_agent: 'foo;bar')
3939

40-
create_driver!(capabilities: options) do |driver|
40+
create_driver!(options: options) do |driver|
4141
ua = driver.execute_script 'return window.navigator.userAgent'
4242
expect(ua).to eq('foo;bar')
4343
end
@@ -46,7 +46,7 @@ module Edge
4646
it 'passes args correctly' do
4747
options.add_argument('--user-agent=foo;bar')
4848

49-
create_driver!(capabilities: options) do |driver|
49+
create_driver!(options: options) do |driver|
5050
ua = driver.execute_script 'return window.navigator.userAgent'
5151
expect(ua).to eq('foo;bar')
5252
end
@@ -55,7 +55,7 @@ module Edge
5555
it 'should be able to run in headless mode with #headless!' do
5656
options.headless!
5757

58-
create_driver!(capabilities: options) do |driver|
58+
create_driver!(options: options) do |driver|
5959
ua = driver.execute_script 'return window.navigator.userAgent'
6060
expect(ua).to match(/HeadlessChrome/)
6161
end

rb/spec/integration/selenium/webdriver/firefox/driver_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ module Firefox
143143

144144
it 'can get and set context' do
145145
options = Options.new(prefs: {'browser.download.dir': 'foo/bar'})
146-
create_driver!(capabilities: options) do |driver|
146+
create_driver!(options: options) do |driver|
147147
expect(driver.context).to eq 'content'
148148

149149
driver.context = 'chrome'

rb/spec/integration/selenium/webdriver/firefox/profile_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ def read_generated_prefs(from = nil)
4040
end
4141

4242
it 'should instantiate the browser with the correct profile' do
43-
create_driver!(capabilities: Options.new(profile: profile)) do |driver|
43+
create_driver!(options: Options.new(profile: profile)) do |driver|
4444
expect { wait(5).until { driver.find_element(id: 'oneline') } }.not_to raise_error
4545
end
4646
end
4747

4848
it 'should be able to use the same profile more than once' do
49-
create_driver!(capabilities: Options.new(profile: profile)) do |driver1|
49+
create_driver!(options: Options.new(profile: profile)) do |driver1|
5050
expect { wait(5).until { driver1.find_element(id: 'oneline') } }.not_to raise_error
51-
create_driver!(capabilities: Options.new(profile: profile)) do |driver2|
51+
create_driver!(options: Options.new(profile: profile)) do |driver2|
5252
expect { wait(5).until { driver2.find_element(id: 'oneline') } }.not_to raise_error
5353
end
5454
end

rb/spec/integration/selenium/webdriver/spec_support/test_environment.rb

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -186,47 +186,50 @@ def check_for_previous_error
186186
end
187187

188188
def create_remote_driver(**opts)
189-
options = opts.delete(:capabilities)
190-
opts[:capabilities] = [WebDriver::Remote::Capabilities.send(browser)]
191-
opts[:capabilities] << options if options
192-
opts[:url] = ENV.fetch('WD_REMOTE_URL', remote_server.webdriver_url)
193-
opts[:http_client] ||= WebDriver::Remote::Http::Default.new
189+
options = opts.delete(:options) { WebDriver::Options.send(browser) }
190+
url = ENV.fetch('WD_REMOTE_URL', remote_server.webdriver_url)
194191

195-
WebDriver::Driver.for(:remote, **opts)
192+
WebDriver::Driver.for(:remote, url: url, options: options, **opts)
196193
end
197194

198195
def create_firefox_driver(**opts)
199196
WebDriver::Firefox.path = ENV.fetch('FIREFOX_BINARY', nil) if ENV.key?('FIREFOX_BINARY')
200-
WebDriver::Driver.for :firefox, **opts
197+
options = opts.delete(:options) { WebDriver::Options.firefox }
198+
options.debugger_address = true
199+
options.web_socket_url = true
200+
options.add_argument('--headless') if ENV['HEADLESS']
201+
WebDriver::Driver.for(:firefox, options: options, **opts)
201202
end
202203

203204
def create_firefox_nightly_driver(**opts)
204205
ENV['FIREFOX_BINARY'] = ENV.fetch('FIREFOX_NIGHTLY_BINARY', nil)
205-
opts[:capabilities] = [
206-
WebDriver::Firefox::Options.new(debugger_address: true),
207-
WebDriver::Remote::Capabilities.firefox(web_socket_url: true)
208-
]
209-
create_firefox_driver(**opts)
206+
options = opts.delete(:options) { WebDriver::Options.firefox }
207+
create_firefox_driver(options: options, **opts)
210208
end
211209

212210
def create_ie_driver(**opts)
213-
opts[:capabilities] = WebDriver::IE::Options.new(require_window_focus: true)
214-
WebDriver::Driver.for :ie, **opts
211+
options = opts.delete(:options) { WebDriver::Options.ie }
212+
options.require_window_focus = true
213+
WebDriver::Driver.for(:ie, options: options, **opts)
215214
end
216215

217216
def create_chrome_driver(**opts)
218217
WebDriver::Chrome.path = ENV.fetch('CHROME_BINARY', nil) if ENV.key?('CHROME_BINARY')
219-
WebDriver::Driver.for :chrome, **opts
218+
options = opts.delete(:options) { WebDriver::Options.chrome }
219+
options.headless! if ENV['HEADLESS']
220+
WebDriver::Driver.for(:chrome, options: options, **opts)
220221
end
221222

222223
def create_safari_preview_driver(**opts)
223224
WebDriver::Safari.technology_preview!
224-
WebDriver::Driver.for :safari, **opts
225+
options = opts.delete(:options) { WebDriver::Options.safari }
226+
WebDriver::Driver.for(:safari, options: options, **opts)
225227
end
226228

227229
def create_edge_driver(**opts)
228230
WebDriver::Edge.path = ENV.fetch('EDGE_BINARY', nil) if ENV.key?('EDGE_BINARY')
229-
WebDriver::Driver.for :edge, **opts
231+
options = opts.delete(:options) { WebDriver::Options.edge }
232+
WebDriver::Driver.for(:edge, options: options, **opts)
230233
end
231234

232235
def extract_browser_from_bazel_target_name

0 commit comments

Comments
 (0)