diff --git a/rb/lib/selenium/webdriver/bidi.rb b/rb/lib/selenium/webdriver/bidi.rb index 4c8ca37b4f8d2..f0faa1df1bd56 100644 --- a/rb/lib/selenium/webdriver/bidi.rb +++ b/rb/lib/selenium/webdriver/bidi.rb @@ -31,8 +31,8 @@ class BiDi autoload :InterceptedAuth, 'selenium/webdriver/bidi/network/intercepted_auth' autoload :InterceptedItem, 'selenium/webdriver/bidi/network/intercepted_item' - def initialize(url:) - @ws = WebSocketConnection.new(url: url) + def initialize(url:, **) + @ws = WebSocketConnection.new(url: url, **) end def close diff --git a/rb/lib/selenium/webdriver/common/options.rb b/rb/lib/selenium/webdriver/common/options.rb index bddb91063737b..e89f0b51a33e8 100644 --- a/rb/lib/selenium/webdriver/common/options.rb +++ b/rb/lib/selenium/webdriver/common/options.rb @@ -26,6 +26,8 @@ class Options GRID_OPTIONS = %i[enable_downloads].freeze + WEBSOCKET_OPTIONS = %i[web_socket_timeout web_socket_interval].freeze + class << self attr_reader :driver_path @@ -52,7 +54,7 @@ def safari(**) end def set_capabilities - (W3C_OPTIONS + GRID_OPTIONS + self::CAPABILITIES.keys).each do |key| + (W3C_OPTIONS + GRID_OPTIONS + WEBSOCKET_OPTIONS + self::CAPABILITIES.keys).each do |key| next if method_defined? key define_method key do @@ -108,6 +110,8 @@ def as_json(*) downloads = options.delete(:enable_downloads) options['se:downloadsEnabled'] = downloads unless downloads.nil? + options['ws:response_timeout'] = options.delete(:web_socket_timeout) if options[:web_socket_timeout] + options['ws:response_interval'] = options.delete(:web_socket_interval) if options[:web_socket_interval] w3c_options = process_w3c_options(options) browser_options = self.class::CAPABILITIES.each_with_object({}) do |(capability_alias, capability_name), hash| diff --git a/rb/lib/selenium/webdriver/common/websocket_connection.rb b/rb/lib/selenium/webdriver/common/websocket_connection.rb index 26f02ebc9bf1c..1ecf8a7e6fb7d 100644 --- a/rb/lib/selenium/webdriver/common/websocket_connection.rb +++ b/rb/lib/selenium/webdriver/common/websocket_connection.rb @@ -32,9 +32,12 @@ class WebSocketConnection MAX_LOG_MESSAGE_SIZE = 9999 - def initialize(url:) + def initialize(url:, options: {}) @callback_threads = ThreadGroup.new + @response_timeout = options.fetch(:response_timeout, RESPONSE_WAIT_TIMEOUT) + @response_interval = options.fetch(:response_interval, RESPONSE_WAIT_INTERVAL) + @session_id = nil @url = url @@ -147,7 +150,7 @@ def callback_thread(params) end def wait - @wait ||= Wait.new(timeout: RESPONSE_WAIT_TIMEOUT, interval: RESPONSE_WAIT_INTERVAL) + @wait ||= Wait.new(timeout: @response_timeout, interval: @response_interval) end def socket diff --git a/rb/lib/selenium/webdriver/remote/bidi_bridge.rb b/rb/lib/selenium/webdriver/remote/bidi_bridge.rb index c95ddec538f85..aa3a52ea2aa07 100644 --- a/rb/lib/selenium/webdriver/remote/bidi_bridge.rb +++ b/rb/lib/selenium/webdriver/remote/bidi_bridge.rb @@ -26,7 +26,13 @@ class BiDiBridge < Bridge def create_session(capabilities) super socket_url = @capabilities[:web_socket_url] - @bidi = Selenium::WebDriver::BiDi.new(url: socket_url) + + ws_options = { + response_timeout: capabilities['ws:responseTimeout'], + response_interval: capabilities['ws:responseInterval'] + }.compact + + @bidi = Selenium::WebDriver::BiDi.new(url: socket_url, options: ws_options) end def get(url) diff --git a/rb/sig/lib/selenium/webdriver/common/websocket_connection.rbs b/rb/sig/lib/selenium/webdriver/common/websocket_connection.rbs index 98ac289f081ed..a97bd98ea05b7 100644 --- a/rb/sig/lib/selenium/webdriver/common/websocket_connection.rbs +++ b/rb/sig/lib/selenium/webdriver/common/websocket_connection.rbs @@ -5,6 +5,8 @@ module Selenium @callback_threads: untyped + @response_interval: Float + @response_timeout: Integer @session_id: untyped @url: untyped diff --git a/rb/spec/integration/selenium/webdriver/bidi/browsing_context_spec.rb b/rb/spec/integration/selenium/webdriver/bidi/browsing_context_spec.rb index bcad86441d1bc..03a0155bb8ecf 100644 --- a/rb/spec/integration/selenium/webdriver/bidi/browsing_context_spec.rb +++ b/rb/spec/integration/selenium/webdriver/bidi/browsing_context_spec.rb @@ -132,6 +132,14 @@ class BiDi browsing_context.activate expect(driver.execute_script('return document.hasFocus();')).to be_truthy end + + it 'times out if a command takes too long' do + reset_driver!(web_socket_url: true, web_socket_timeout: 0.1, web_socket_interval: 1) do |driver| + expect { + driver.navigate.to url_for('sleep?time=0.2') + }.to raise_error(Selenium::WebDriver::Error::TimeoutError) + end + end end end # BiDi end # WebDriver