Skip to content
Draft
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:, http:)
@ws = WebSocketConnection.new(url: url, http: http)
end

def close
Expand Down
14 changes: 9 additions & 5 deletions rb/lib/selenium/webdriver/common/websocket_connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,23 @@

module Selenium
module WebDriver
#
# WebSocketConnection manages lifecycle of sockets for Devtools and BiDi implementations.
# @api private
#

class WebSocketConnection
CONNECTION_ERRORS = [
Errno::ECONNRESET, # connection is aborted (browser process was killed)
Errno::EPIPE # broken pipe (browser process was killed)
].freeze

RESPONSE_WAIT_TIMEOUT = 30
RESPONSE_WAIT_INTERVAL = 0.1

MAX_LOG_MESSAGE_SIZE = 9999

def initialize(url:)
def initialize(url:, http: nil)
@callback_threads = ThreadGroup.new
@socket_timeout = http&.socket_timeout || 30
@socket_interval = http&.socket_interval || 0.1

@session_id = nil
@url = url
Expand Down Expand Up @@ -147,7 +151,7 @@ def callback_thread(params)
end

def wait
@wait ||= Wait.new(timeout: RESPONSE_WAIT_TIMEOUT, interval: RESPONSE_WAIT_INTERVAL)
@wait ||= Wait.new(timeout: @socket_timeout, interval: @socket_interval)
end

def socket
Expand Down
2 changes: 1 addition & 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,7 @@ class BiDiBridge < Bridge
def create_session(capabilities)
super
socket_url = @capabilities[:web_socket_url]
@bidi = Selenium::WebDriver::BiDi.new(url: socket_url)
@bidi = Selenium::WebDriver::BiDi.new(url: socket_url, http: @http)
end

def get(url)
Expand Down
7 changes: 4 additions & 3 deletions rb/lib/selenium/webdriver/remote/http/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,21 @@ module Selenium
module WebDriver
module Remote
module Http
# @api private
class Default < Common
attr_writer :proxy

attr_accessor :open_timeout, :read_timeout
attr_accessor :open_timeout, :read_timeout, :socket_timeout, :socket_interval

# Initializes object.
# Warning: Setting {#open_timeout} to non-nil values will cause a separate thread to spawn.
# Debuggers that freeze the process will not be able to evaluate any operations if that happens.
# @param [Numeric] open_timeout - Open timeout to apply to HTTP client.
# @param [Numeric] read_timeout - Read timeout (seconds) to apply to HTTP client.
def initialize(open_timeout: nil, read_timeout: nil)
def initialize(open_timeout: nil, read_timeout: nil, socket_timeout: nil, socket_interval: nil)
@open_timeout = open_timeout
@read_timeout = read_timeout
@socket_timeout = socket_timeout || 30
@socket_interval = socket_interval || 0.1
super()
end

Expand Down
4 changes: 4 additions & 0 deletions rb/sig/lib/selenium/webdriver/common/websocket_connection.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ module Selenium

@session_id: untyped

@socket_interval: float

@socket_timeout: int

@url: untyped

@socket_thread: untyped
Expand Down
2 changes: 1 addition & 1 deletion rb/sig/lib/selenium/webdriver/remote/http/common.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module Selenium

def self.user_agent: -> String

attr_writer server_url: String
attr_writer server_url: URI::Generic

def quit_errors: () -> Array[untyped]

Expand Down
6 changes: 5 additions & 1 deletion rb/sig/lib/selenium/webdriver/remote/http/default.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ module Selenium

attr_accessor read_timeout: untyped

def initialize: (?open_timeout: untyped?, ?read_timeout: untyped?) -> void
attr_accessor socket_timeout: int

attr_accessor socket_interval: Numeric

def initialize: (?open_timeout: untyped?, ?read_timeout: untyped?, ?socket_timeout: int?, ?socket_interval: Numeric?) -> void

def close: () -> untyped

Expand Down
13 changes: 7 additions & 6 deletions rb/spec/unit/selenium/webdriver/remote/http/default_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,15 @@ module Http
end

describe '#initialize' do
let(:client) { described_class.new(read_timeout: 22, open_timeout: 23) }

it 'accepts read timeout options' do
it 'constructs values' do
client = described_class.new(read_timeout: 22,
open_timeout: 23,
socket_timeout: 4,
socket_interval: 0.5)
expect(client.open_timeout).to eq 23
end

it 'accepts open timeout options' do
expect(client.read_timeout).to eq 22
expect(client.socket_timeout).to eq 4
expect(client.socket_interval).to eq 0.5
end
end

Expand Down
Loading