Skip to content

Rb make bidi timeout configurable #16053

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 16 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions rb/lib/selenium/webdriver/bidi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion rb/lib/selenium/webdriver/common/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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|
Expand Down
7 changes: 5 additions & 2 deletions rb/lib/selenium/webdriver/common/websocket_connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion rb/lib/selenium/webdriver/remote/bidi_bridge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions rb/sig/lib/selenium/webdriver/common/websocket_connection.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ module Selenium

@callback_threads: untyped

@response_interval: Float
@response_timeout: Integer
@session_id: untyped

@url: untyped
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading