Skip to content

Commit 42850a7

Browse files
committed
[rb] add BiDi support for Chrome in preparation for Chrome v106
1 parent 58f5833 commit 42850a7

File tree

3 files changed

+38
-15
lines changed

3 files changed

+38
-15
lines changed

rb/lib/selenium/webdriver/chrome/driver.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ module Chrome
2828

2929
class Driver < WebDriver::Driver
3030
EXTENSIONS = [DriverExtensions::HasCDP,
31+
DriverExtensions::HasBiDi,
3132
DriverExtensions::HasCasting,
3233
DriverExtensions::HasNetworkConditions,
3334
DriverExtensions::HasNetworkInterception,

rb/spec/integration/selenium/webdriver/bidi_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121

2222
module Selenium
2323
module WebDriver
24-
describe BiDi, exclusive: {browser: %i[firefox firefox_nightly]} do
24+
describe BiDi, exclusive: {browser: %i[chrome_beta firefox firefox_nightly]} do
2525
it 'gets session status' do
2626
status = driver.bidi.session.status
27-
expect(status.ready).to eq false
28-
expect(status.message).to eq('Session already started')
27+
expect(status).to respond_to(:ready)
28+
expect(status.message).not_to be_empty
2929
end
3030
end
3131
end

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

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -186,24 +186,31 @@ def check_for_previous_error
186186
end
187187

188188
def create_remote_driver(**opts)
189-
options = opts.delete(:options) { WebDriver::Options.send(browser) }
190189
url = ENV.fetch('WD_REMOTE_URL', remote_server.webdriver_url)
190+
options = opts.delete(:options) { WebDriver::Options.send(browser) }
191+
method = "create_#{browser}_options".to_sym
192+
options = send method, options if private_methods.include?(method)
191193

192194
WebDriver::Driver.for(:remote, url: url, options: options, **opts)
193195
end
194196

195197
def create_firefox_driver(**opts)
196-
WebDriver::Firefox.path = ENV.fetch('FIREFOX_BINARY', nil) if ENV.key?('FIREFOX_BINARY')
197-
options = opts.delete(:options) { WebDriver::Options.firefox }
198-
options.web_socket_url = true
199-
options.add_argument('--headless') if ENV['HEADLESS']
198+
options = create_firefox_options(opts.delete(:options))
200199
WebDriver::Driver.for(:firefox, options: options, **opts)
201200
end
202201

203202
def create_firefox_nightly_driver(**opts)
204-
ENV['FIREFOX_BINARY'] = ENV.fetch('FIREFOX_NIGHTLY_BINARY', nil)
205-
options = opts.delete(:options) { WebDriver::Options.firefox }
206-
create_firefox_driver(options: options, **opts)
203+
options = create_firefox_options(opts.delete(:options))
204+
options.binary = ENV['FIREFOX_NIGHTLY_BINARY'] if ENV.key?('FIREFOX_NIGHTLY_BINARY')
205+
WebDriver::Driver.for(:firefox, options: options, **opts)
206+
end
207+
208+
def create_firefox_options(options)
209+
options ||= WebDriver::Options.firefox
210+
options.web_socket_url = true
211+
options.add_argument('--headless') if ENV['HEADLESS']
212+
options.binary ||= ENV['FIREFOX_BINARY'] if ENV.key?('FIREFOX_BINARY')
213+
options
207214
end
208215

209216
def create_ie_driver(**opts)
@@ -212,22 +219,37 @@ def create_ie_driver(**opts)
212219
WebDriver::Driver.for(:ie, options: options, **opts)
213220
end
214221

222+
def create_chrome_beta_driver(**opts)
223+
options = create_chrome_options(opts.delete(:options))
224+
options.web_socket_url = true
225+
service_opts = {args: ['--disable-build-check']}
226+
service_opts[:path] = ENV['CHROMEDRIVER_BINARY'] if ENV.key?('CHROMEDRIVER_BINARY')
227+
service = WebDriver::Service.chrome(**service_opts)
228+
WebDriver::Driver.for(:chrome, options: options, service: service, **opts)
229+
end
230+
215231
def create_chrome_driver(**opts)
216-
WebDriver::Chrome.path = ENV.fetch('CHROME_BINARY', nil) if ENV.key?('CHROME_BINARY')
217-
options = opts.delete(:options) { WebDriver::Options.chrome }
218-
options.headless! if ENV['HEADLESS']
232+
options = create_chrome_options(opts.delete(:options))
219233
WebDriver::Driver.for(:chrome, options: options, **opts)
220234
end
221235

236+
def create_chrome_options(options)
237+
options ||= WebDriver::Options.chrome
238+
options.headless! if ENV['HEADLESS']
239+
options.binary ||= ENV['CHROME_BINARY'] if ENV.key?('CHROME_BINARY')
240+
options
241+
end
242+
222243
def create_safari_preview_driver(**opts)
223244
WebDriver::Safari.technology_preview!
224245
options = opts.delete(:options) { WebDriver::Options.safari }
225246
WebDriver::Driver.for(:safari, options: options, **opts)
226247
end
227248

228249
def create_edge_driver(**opts)
229-
WebDriver::Edge.path = ENV.fetch('EDGE_BINARY', nil) if ENV.key?('EDGE_BINARY')
230250
options = opts.delete(:options) { WebDriver::Options.edge }
251+
options.headless! if ENV['HEADLESS']
252+
options.binary = ENV.fetch('EDGE_BINARY', nil) if ENV.key?('EDGE_BINARY')
231253
WebDriver::Driver.for(:edge, options: options, **opts)
232254
end
233255

0 commit comments

Comments
 (0)