Skip to content

Commit

Permalink
[rb] manage bidi instance on the bridge not the driver
Browse files Browse the repository at this point in the history
  • Loading branch information
titusfortner committed Jun 3, 2024
1 parent 1b827c2 commit 4cbaa89
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 9 deletions.
7 changes: 1 addition & 6 deletions rb/lib/selenium/webdriver/common/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ def for(browser, opts = {})

def initialize(bridge: nil, listener: nil, **opts)
@devtools = nil
@bidi = nil
bridge ||= create_bridge(**opts)
add_extensions(bridge.browser)
@bridge = listener ? Support::EventFiringBridge.new(bridge, listener) : bridge
Expand Down Expand Up @@ -174,18 +173,14 @@ def quit
ensure
@service_manager&.stop
@devtools&.close
@bidi&.close
end

#
# Close the current window, or the browser if no windows are left.
#

def close
# If no top-level browsing contexts are open after calling close,
# it indicates that the WebDriver session is closed.
# If the WebDriver session is closed, the BiDi session also needs to be closed.
bridge.close.tap { |handles| @bidi&.close if handles&.empty? }
bridge.close
end

#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module HasBiDi
#

def bidi
@bidi ||= Selenium::WebDriver::BiDi.new(url: capabilities[:web_socket_url])
@bridge.bidi
end
end # HasBiDi
end # DriverExtensions
Expand Down
11 changes: 10 additions & 1 deletion rb/lib/selenium/webdriver/remote/bridge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,12 @@ def quit
http.close
rescue *QUIT_ERRORS
nil
ensure
@bidi.close
end

def close
execute :close_window
execute(:close_window).tap { |handles| @bidi.close if handles.empty? }
end

def refresh
Expand Down Expand Up @@ -602,6 +604,13 @@ def user_verified(verified, authenticator_id)
execute :set_user_verified, {authenticatorId: authenticator_id}, {isUserVerified: verified}
end

def bidi
msg = 'this operation requires enabling BiDi by setting #web_socket_url to true in options class'
raise(WebDriver::Error::WebDriverError, msg) unless capabilities.web_socket_url

@bidi ||= Selenium::WebDriver::BiDi.new(url: capabilities[:web_socket_url])
end

def command_list
COMMANDS
end
Expand Down
1 change: 0 additions & 1 deletion rb/sig/lib/selenium/webdriver/common/driver.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ module Selenium

include TakesScreenshot

@bidi: untyped
@devtools: untyped
@navigate: untyped

Expand Down
1 change: 1 addition & 0 deletions rb/sig/lib/selenium/webdriver/remote/bridge.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module Selenium
include _CommandList
include _Features

@bidi: WebDriver::BiDi
@http: untyped

@file_detector: untyped
Expand Down

0 comments on commit 4cbaa89

Please sign in to comment.