diff --git a/rb/lib/selenium/webdriver/common/driver.rb b/rb/lib/selenium/webdriver/common/driver.rb index 41a079017d8adb..643d477ef381d8 100644 --- a/rb/lib/selenium/webdriver/common/driver.rb +++ b/rb/lib/selenium/webdriver/common/driver.rb @@ -318,7 +318,8 @@ def ref attr_reader :bridge def create_bridge(caps:, url:, http_client: nil) - Remote::Bridge.new(http_client: http_client, url: url).tap do |bridge| + klass = caps['webSocketUrl'] ? Remote::BiDiBridge : Remote::Bridge + klass.new(http_client: http_client, url: url).tap do |bridge| bridge.create_session(caps) end end diff --git a/rb/lib/selenium/webdriver/remote.rb b/rb/lib/selenium/webdriver/remote.rb index 44baebffb3816f..1f73c4b93270d3 100644 --- a/rb/lib/selenium/webdriver/remote.rb +++ b/rb/lib/selenium/webdriver/remote.rb @@ -25,6 +25,7 @@ module WebDriver module Remote autoload :Features, 'selenium/webdriver/remote/features' autoload :Bridge, 'selenium/webdriver/remote/bridge' + autoload :BiDiBridge, 'selenium/webdriver/remote/bidi_bridge' autoload :Driver, 'selenium/webdriver/remote/driver' autoload :Response, 'selenium/webdriver/remote/response' autoload :Capabilities, 'selenium/webdriver/remote/capabilities' diff --git a/rb/lib/selenium/webdriver/remote/bidi_bridge.rb b/rb/lib/selenium/webdriver/remote/bidi_bridge.rb new file mode 100644 index 00000000000000..4207577cf14dc8 --- /dev/null +++ b/rb/lib/selenium/webdriver/remote/bidi_bridge.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +# Licensed to the Software Freedom Conservancy (SFC) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The SFC licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +module Selenium + module WebDriver + module Remote + class BiDiBridge < Bridge + attr_reader :bidi + + def create_session(capabilities) + super(capabilities) + socket_url = @capabilities[:web_socket_url] + @bidi = Selenium::WebDriver::BiDi.new(url: socket_url) + end + + def quit + super + ensure + bidi.close + end + + def close + execute(:close_window).tap { |handles| bidi.close if handles.empty? } + end + end # BiDiBridge + end # Remote + end # WebDriver +end # Selenium diff --git a/rb/lib/selenium/webdriver/remote/bridge.rb b/rb/lib/selenium/webdriver/remote/bridge.rb index eb0b748b3702c4..3dd8a799c52496 100644 --- a/rb/lib/selenium/webdriver/remote/bridge.rb +++ b/rb/lib/selenium/webdriver/remote/bridge.rb @@ -213,12 +213,10 @@ def quit http.close rescue *QUIT_ERRORS nil - ensure - @bidi&.close end def close - execute(:close_window).tap { |handles| @bidi&.close if handles.empty? } + execute :close_window end def refresh @@ -605,10 +603,8 @@ def user_verified(verified, authenticator_id) 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]) + msg = 'BiDi must be enabled by setting #web_socket_url to true in options class' + raise(WebDriver::Error::WebDriverError, msg) end def command_list