Skip to content

Commit

Permalink
[rb] add BiDi support for Chrome in preparation for Chrome v106
Browse files Browse the repository at this point in the history
  • Loading branch information
titusfortner committed Sep 26, 2022
1 parent 58f5833 commit 42850a7
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 15 deletions.
1 change: 1 addition & 0 deletions rb/lib/selenium/webdriver/chrome/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ module Chrome

class Driver < WebDriver::Driver
EXTENSIONS = [DriverExtensions::HasCDP,
DriverExtensions::HasBiDi,
DriverExtensions::HasCasting,
DriverExtensions::HasNetworkConditions,
DriverExtensions::HasNetworkInterception,
Expand Down
6 changes: 3 additions & 3 deletions rb/spec/integration/selenium/webdriver/bidi_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@

module Selenium
module WebDriver
describe BiDi, exclusive: {browser: %i[firefox firefox_nightly]} do
describe BiDi, exclusive: {browser: %i[chrome_beta firefox firefox_nightly]} do
it 'gets session status' do
status = driver.bidi.session.status
expect(status.ready).to eq false
expect(status.message).to eq('Session already started')
expect(status).to respond_to(:ready)
expect(status.message).not_to be_empty
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,24 +186,31 @@ def check_for_previous_error
end

def create_remote_driver(**opts)
options = opts.delete(:options) { WebDriver::Options.send(browser) }
url = ENV.fetch('WD_REMOTE_URL', remote_server.webdriver_url)
options = opts.delete(:options) { WebDriver::Options.send(browser) }
method = "create_#{browser}_options".to_sym
options = send method, options if private_methods.include?(method)

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

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

def create_firefox_nightly_driver(**opts)
ENV['FIREFOX_BINARY'] = ENV.fetch('FIREFOX_NIGHTLY_BINARY', nil)
options = opts.delete(:options) { WebDriver::Options.firefox }
create_firefox_driver(options: options, **opts)
options = create_firefox_options(opts.delete(:options))
options.binary = ENV['FIREFOX_NIGHTLY_BINARY'] if ENV.key?('FIREFOX_NIGHTLY_BINARY')
WebDriver::Driver.for(:firefox, options: options, **opts)
end

def create_firefox_options(options)
options ||= WebDriver::Options.firefox
options.web_socket_url = true
options.add_argument('--headless') if ENV['HEADLESS']
options.binary ||= ENV['FIREFOX_BINARY'] if ENV.key?('FIREFOX_BINARY')
options
end

def create_ie_driver(**opts)
Expand All @@ -212,22 +219,37 @@ def create_ie_driver(**opts)
WebDriver::Driver.for(:ie, options: options, **opts)
end

def create_chrome_beta_driver(**opts)
options = create_chrome_options(opts.delete(:options))
options.web_socket_url = true
service_opts = {args: ['--disable-build-check']}
service_opts[:path] = ENV['CHROMEDRIVER_BINARY'] if ENV.key?('CHROMEDRIVER_BINARY')
service = WebDriver::Service.chrome(**service_opts)
WebDriver::Driver.for(:chrome, options: options, service: service, **opts)
end

def create_chrome_driver(**opts)
WebDriver::Chrome.path = ENV.fetch('CHROME_BINARY', nil) if ENV.key?('CHROME_BINARY')
options = opts.delete(:options) { WebDriver::Options.chrome }
options.headless! if ENV['HEADLESS']
options = create_chrome_options(opts.delete(:options))
WebDriver::Driver.for(:chrome, options: options, **opts)
end

def create_chrome_options(options)
options ||= WebDriver::Options.chrome
options.headless! if ENV['HEADLESS']
options.binary ||= ENV['CHROME_BINARY'] if ENV.key?('CHROME_BINARY')
options
end

def create_safari_preview_driver(**opts)
WebDriver::Safari.technology_preview!
options = opts.delete(:options) { WebDriver::Options.safari }
WebDriver::Driver.for(:safari, options: options, **opts)
end

def create_edge_driver(**opts)
WebDriver::Edge.path = ENV.fetch('EDGE_BINARY', nil) if ENV.key?('EDGE_BINARY')
options = opts.delete(:options) { WebDriver::Options.edge }
options.headless! if ENV['HEADLESS']
options.binary = ENV.fetch('EDGE_BINARY', nil) if ENV.key?('EDGE_BINARY')
WebDriver::Driver.for(:edge, options: options, **opts)
end

Expand Down

0 comments on commit 42850a7

Please sign in to comment.