Skip to content
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

[rb] manage bidi instance on the bridge not the driver #14071

Merged
merged 2 commits into from
Jun 4, 2024
Merged
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
9 changes: 2 additions & 7 deletions rb/lib/selenium/webdriver/common/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,9 @@ 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
add_extensions(@bridge.browser)
end

def inspect
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
Loading