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] implement toggle to use BiDi implementation #13126

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 2 additions & 12 deletions rb/lib/selenium/webdriver/bidi/browsing_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ class BrowsingContext

READINESS_STATE = {
none: 'none',
interactive: 'interactive',
complete: 'complete'
eager: 'interactive',
normal: 'complete'
}.freeze

def initialize(driver:, browsing_context_id: nil, type: nil, reference_context: nil)
Expand All @@ -38,21 +38,11 @@ def initialize(driver:, browsing_context_id: nil, type: nil, reference_context:
'WebDriver instance must support BiDi protocol'
end

unless type.nil? || %i[window tab].include?(type)
raise ArgumentError,
"Valid types are :window & :tab. Received: #{type.inspect}"
end

@bidi = driver.bidi
@id = browsing_context_id.nil? ? create(type, reference_context)['context'] : browsing_context_id
end

def navigate(url:, readiness_state: nil)
unless readiness_state.nil? || READINESS_STATE.key?(readiness_state)
raise ArgumentError,
"Valid readiness states are :none, :interactive & :complete. Received: #{readiness_state.inspect}"
end

navigate_result = @bidi.send_cmd('browsingContext.navigate', context: @id, url: url,
wait: READINESS_STATE[readiness_state])

Expand Down
9 changes: 7 additions & 2 deletions rb/lib/selenium/webdriver/common/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,14 @@ 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|
bridge.create_session(caps)
bridge = Remote::Bridge.new(http_client: http_client, url: url)
bridge.create_session(caps)
socket_url = bridge.capabilities[:web_socket_url]
if socket_url.kind_of?(String)
bridge.extend(Remote::BiDiBridge)
bridge.bidi = Selenium::WebDriver::BiDi.new(url: socket_url)
end
bridge
end

def service_url(service)
Expand Down
1 change: 1 addition & 0 deletions rb/lib/selenium/webdriver/remote.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ module Selenium
module WebDriver
module Remote
autoload :Features, 'selenium/webdriver/remote/features'
autoload :BiDiBridge, 'selenium/webdriver/remote/bi_di_bridge'
autoload :Bridge, 'selenium/webdriver/remote/bridge'
autoload :Driver, 'selenium/webdriver/remote/driver'
autoload :Response, 'selenium/webdriver/remote/response'
Expand Down
35 changes: 35 additions & 0 deletions rb/lib/selenium/webdriver/remote/bi_di_bridge.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# 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
module BiDiBridge
attr_accessor :bidi, :browsing_context

def get(url)
@browsing_context ||= WebDriver::BiDi::BrowsingContext.new(driver: self,
browsing_context_id: window_handle,
type: :tab)
@browsing_context.navigate(url: url, readiness_state: capabilities[:page_load_strategy])
end
end # BiDiBridge
end # Remote
end # WebDriver
end # Selenium
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class BiDi
browsing_context = described_class.new(driver: driver, type: :tab)

info = browsing_context.navigate url: url_for('/bidi/logEntryAdded.html'),
readiness_state: :complete
readiness_state: :normal

expect(browsing_context.id).not_to be_nil
expect(info.url).to include('/bidi/logEntryAdded.html')
Expand All @@ -76,7 +76,7 @@ class BiDi
browsing_context_id = driver.window_handle
parent_window = described_class.new(driver: driver, browsing_context_id: browsing_context_id)
parent_window.navigate(url: url_for('iframes.html'),
readiness_state: :complete)
readiness_state: :normal)

context_info = parent_window.get_tree
expect(context_info.children.size).to eq(1)
Expand All @@ -88,7 +88,7 @@ class BiDi
browsing_context_id = driver.window_handle
parent_window = described_class.new(driver: driver, browsing_context_id: browsing_context_id)
parent_window.navigate(url: url_for('iframes.html'),
readiness_state: :complete)
readiness_state: :normal)

context_info = parent_window.get_tree(max_depth: 0)
expect(context_info.children).to be_nil
Expand Down
5 changes: 2 additions & 3 deletions rb/spec/integration/selenium/webdriver/bidi_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,9 @@ module WebDriver
log_inspector = BiDi::LogInspector.new(driver)
log_inspector.on_javascript_exception { |log| log_entry = log }

browsing_context = BiDi::BrowsingContext.new(driver: driver, browsing_context_id: driver.window_handle)
info = browsing_context.navigate(url: url_for('/bidi/logEntryAdded.html'))
info = driver.navigate.to(url_for('/bidi/logEntryAdded.html'))

expect(browsing_context.id).not_to be_nil
expect(driver.send(:bridge).browsing_context.id).not_to be_nil
expect(info.navigation_id).not_to be_nil
expect(info.url).to include('/bidi/logEntryAdded.html')

Expand Down
2 changes: 1 addition & 1 deletion rb/spec/unit/selenium/webdriver/chrome/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ module Chrome
class: described_class)
end
let(:service_manager) { instance_double(ServiceManager, uri: 'http://example.com') }
let(:bridge) { instance_double(Remote::Bridge, quit: nil, create_session: {}) }
let(:bridge) { instance_double(Remote::Bridge, quit: nil, create_session: {}, capabilities: {}) }

before do
allow(Remote::Bridge).to receive(:new).and_return(bridge)
Expand Down
2 changes: 1 addition & 1 deletion rb/spec/unit/selenium/webdriver/edge/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ module Edge
class: described_class)
end
let(:service_manager) { instance_double(ServiceManager, uri: 'http://example.com') }
let(:bridge) { instance_double(Remote::Bridge, quit: nil, create_session: {}) }
let(:bridge) { instance_double(Remote::Bridge, quit: nil, create_session: {}, capabilities: {}) }

before do
allow(Remote::Bridge).to receive(:new).and_return(bridge)
Expand Down
2 changes: 1 addition & 1 deletion rb/spec/unit/selenium/webdriver/firefox/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ module Firefox
class: described_class)
end
let(:service_manager) { instance_double(ServiceManager, uri: 'http://example.com') }
let(:bridge) { instance_double(Remote::Bridge, quit: nil, create_session: {}) }
let(:bridge) { instance_double(Remote::Bridge, quit: nil, create_session: {}, capabilities: {}) }

before do
allow(Remote::Bridge).to receive(:new).and_return(bridge)
Expand Down
2 changes: 1 addition & 1 deletion rb/spec/unit/selenium/webdriver/ie/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ module IE
class: described_class)
end
let(:service_manager) { instance_double(ServiceManager, uri: 'http://example.com') }
let(:bridge) { instance_double(Remote::Bridge, quit: nil, create_session: {}) }
let(:bridge) { instance_double(Remote::Bridge, quit: nil, create_session: {}, capabilities: {}) }

before do
allow(Remote::Bridge).to receive(:new).and_return(bridge)
Expand Down
2 changes: 1 addition & 1 deletion rb/spec/unit/selenium/webdriver/safari/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ module Safari
class: described_class)
end
let(:service_manager) { instance_double(ServiceManager, uri: 'http://example.com') }
let(:bridge) { instance_double(Remote::Bridge, quit: nil, create_session: {}) }
let(:bridge) { instance_double(Remote::Bridge, quit: nil, create_session: {}, capabilities: {}) }

before do
allow(Remote::Bridge).to receive(:new).and_return(bridge)
Expand Down