Skip to content

Commit

Permalink
Merge branch 'trunk' into dotnet_async_new
Browse files Browse the repository at this point in the history
  • Loading branch information
titusfortner committed Jun 6, 2024
2 parents 44f94bc + 3597ecd commit e037c9f
Show file tree
Hide file tree
Showing 79 changed files with 759 additions and 386 deletions.
7 changes: 0 additions & 7 deletions .github/workflows/ci-ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ jobs:
- chrome
- edge
- firefox
- safari
os:
- ubuntu
- windows
Expand All @@ -83,10 +82,6 @@ jobs:
os: ubuntu
- browser: edge
os: macos
- browser: safari
os: ubuntu
- browser: safari
os: windows
with:
name: Local Tests (${{ matrix.browser }}, ${{ matrix.os }})
browser: ${{ matrix.browser }}
Expand Down Expand Up @@ -115,8 +110,6 @@ jobs:
os: ubuntu
- browser: firefox
os: ubuntu
- browser: safari
os: macos
with:
name: Remote Tests (${{ matrix.browser }}, ${{ matrix.os }})
browser: ${{ matrix.browser }}
Expand Down
6 changes: 6 additions & 0 deletions .skipped-tests
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,9 @@
-//rb/spec/integration/selenium/webdriver/firefox:service-firefox-beta
-//rb/spec/integration/selenium/webdriver:element-chrome
-//rb/spec/integration/selenium/webdriver/firefox:driver-firefox-beta
-//rb/spec/integration/selenium/webdriver/chrome:service-chrome-bidi
-//rb/spec/integration/selenium/webdriver/edge:service-edge-bidi
-//rb/spec/integration/selenium/webdriver/firefox:service-firefox-bidi
-//rb/spec/integration/selenium/webdriver/firefox:service-firefox-beta-bidi
-//rb/spec/integration/selenium/webdriver:element-chrome-bidi
-//rb/spec/integration/selenium/webdriver/firefox:driver-firefox-beta-bidi
2 changes: 1 addition & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module(name = "selenium")

bazel_dep(name = "apple_rules_lint", version = "0.3.2")
bazel_dep(name = "aspect_bazel_lib", version = "2.7.3")
bazel_dep(name = "aspect_bazel_lib", version = "2.7.6")
bazel_dep(name = "aspect_rules_esbuild", version = "0.20.0")
bazel_dep(name = "aspect_rules_js", version = "1.42.3")
bazel_dep(name = "aspect_rules_ts", version = "2.1.0")
Expand Down
6 changes: 3 additions & 3 deletions java/src/org/openqa/selenium/remote/RemoteWebDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,11 @@ private Capabilities init(Capabilities capabilities) {
converter = new JsonToWebElementConverter(this);
executeMethod = new RemoteExecuteMethod(this);

Set<String> logTypesToInclude = Set.of();
Set<String> logTypesToIgnore = Set.of();

LocalLogs performanceLogger = LocalLogs.getStoringLoggerInstance(logTypesToInclude);
LocalLogs performanceLogger = LocalLogs.getStoringLoggerInstance(logTypesToIgnore);
LocalLogs clientLogs =
LocalLogs.getHandlerBasedLoggerInstance(LoggingHandler.getInstance(), logTypesToInclude);
LocalLogs.getHandlerBasedLoggerInstance(LoggingHandler.getInstance(), logTypesToIgnore);
localLogs = LocalLogs.getCombinedLogsHolder(clientLogs, performanceLogger);
remoteLogs = new RemoteLogs(executeMethod, localLogs);

Expand Down
11 changes: 10 additions & 1 deletion java/src/org/openqa/selenium/remote/TracedCommandExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@
import java.io.IOException;
import java.util.Map;
import java.util.Objects;
import org.openqa.selenium.logging.LocalLogs;
import org.openqa.selenium.logging.NeedsLocalLogs;
import org.openqa.selenium.remote.tracing.Span;
import org.openqa.selenium.remote.tracing.Tracer;

public class TracedCommandExecutor implements CommandExecutor {
public class TracedCommandExecutor implements CommandExecutor, NeedsLocalLogs {

private final CommandExecutor delegate;
private final Tracer tracer;
Expand Down Expand Up @@ -51,4 +53,11 @@ public Response execute(Command command) throws IOException {
return delegate.execute(command);
}
}

@Override
public void setLocalLogs(LocalLogs logs) {
if (delegate instanceof NeedsLocalLogs) {
((NeedsLocalLogs) delegate).setLocalLogs(logs);
}
}
}
12 changes: 7 additions & 5 deletions py/selenium/webdriver/remote/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import copy
import os
import pkgutil
import tempfile
import types
import typing
import warnings
Expand Down Expand Up @@ -1147,12 +1148,13 @@ def download_file(self, file_name: str, target_directory: str) -> None:

contents = self.execute(Command.DOWNLOAD_FILE, {"name": file_name})["value"]["contents"]

target_file = os.path.join(target_directory, file_name)
with open(target_file, "wb") as file:
file.write(base64.b64decode(contents))
with tempfile.TemporaryDirectory() as tmp_dir:
zip_file = os.path.join(tmp_dir, file_name + ".zip")
with open(zip_file, "wb") as file:
file.write(base64.b64decode(contents))

with zipfile.ZipFile(target_file, "r") as zip_ref:
zip_ref.extractall(target_directory)
with zipfile.ZipFile(zip_file, "r") as zip_ref:
zip_ref.extractall(target_directory)

def delete_downloadable_files(self) -> None:
"""Deletes all downloadable files."""
Expand Down
1 change: 1 addition & 0 deletions rb/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ PATH
selenium-webdriver (~> 4.2)
selenium-webdriver (4.22.0.nightly)
base64 (~> 0.2)
logger (~> 1.4)
rexml (~> 3.2, >= 3.2.5)
rubyzip (>= 1.2.2, < 3.0)
websocket (~> 1.0)
Expand Down
10 changes: 10 additions & 0 deletions rb/lib/selenium/webdriver/bidi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ module WebDriver
class BiDi
autoload :Session, 'selenium/webdriver/bidi/session'
autoload :LogInspector, 'selenium/webdriver/bidi/log_inspector'
autoload :LogHandler, 'selenium/webdriver/bidi/log_handler'
autoload :BrowsingContext, 'selenium/webdriver/bidi/browsing_context'
autoload :Struct, 'selenium/webdriver/bidi/struct'

def initialize(url:)
@ws = WebSocketConnection.new(url: url)
Expand All @@ -36,6 +38,14 @@ def callbacks
@ws.callbacks
end

def add_callback(event, &block)
@ws.add_callback(event, &block)
end

def remove_callback(event, id)
@ws.remove_callback(event, id)
end

def session
@session ||= Session.new(self)
end
Expand Down
63 changes: 63 additions & 0 deletions rb/lib/selenium/webdriver/bidi/log_handler.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# 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
class BiDi
class LogHandler
ConsoleLogEntry = BiDi::Struct.new(:level, :text, :timestamp, :method, :args, :type)
JavaScriptLogEntry = BiDi::Struct.new(:level, :text, :timestamp, :stack_trace, :type)

def initialize(bidi)
@bidi = bidi
@log_entry_subscribed = false
end

# @return [int] id of the handler
def add_message_handler(type)
subscribe_log_entry unless @log_entry_subscribed
@bidi.add_callback('log.entryAdded') do |params|
if params['type'] == type
log_entry_klass = type == 'console' ? ConsoleLogEntry : JavaScriptLogEntry
yield(log_entry_klass.new(**params))
end
end
end

# @param [int] id of the handler previously added
def remove_message_handler(id)
@bidi.remove_callback('log.entryAdded', id)
unsubscribe_log_entry if @log_entry_subscribed && @bidi.callbacks['log.entryAdded'].empty?
end

private

def subscribe_log_entry
@bidi.session.subscribe('log.entryAdded')
@log_entry_subscribed = true
end

def unsubscribe_log_entry
@bidi.session.unsubscribe('log.entryAdded')
@log_entry_subscribed = false
end
end # LogHandler
end # Bidi
end # WebDriver
end # Selenium
6 changes: 5 additions & 1 deletion rb/lib/selenium/webdriver/bidi/log_inspector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ class LogInspector
}.freeze

def initialize(driver, browsing_context_ids = nil)
WebDriver.logger.deprecate('LogInspector class',
'Script class with driver.script',
id: :log_inspector)

unless driver.capabilities.web_socket_url
raise Error::WebDriverError,
'WebDriver instance must support BiDi protocol'
Expand Down Expand Up @@ -92,7 +96,7 @@ def on_log(filter_by = nil, &block)

def on(event, &block)
event = EVENTS[event] if event.is_a?(Symbol)
@bidi.callbacks["log.#{event}"] << block
@bidi.add_callback("log.#{event}", &block)
end

def check_valid_filter(filter_by)
Expand Down
14 changes: 7 additions & 7 deletions rb/lib/selenium/webdriver/bidi/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,21 @@ def initialize(bidi)

def status
status = @bidi.send_cmd('session.status')
Status.new(status['ready'], status['message'])
Status.new(**status)
end

def subscribe(events, browsing_contexts = nil)
events_list = Array(events)
browsing_contexts_list = browsing_contexts.nil? ? nil : Array(browsing_contexts)
opts = {events: Array(events)}
opts[:browsing_contexts] = Array(browsing_contexts) if browsing_contexts

@bidi.send_cmd('session.subscribe', events: events_list, contexts: browsing_contexts_list)
@bidi.send_cmd('session.subscribe', **opts)
end

def unsubscribe(events, browsing_contexts = nil)
events_list = Array(events)
browsing_contexts_list = browsing_contexts.nil? ? nil : Array(browsing_contexts)
opts = {events: Array(events)}
opts[:browsing_contexts] = Array(browsing_contexts) if browsing_contexts

@bidi.send_cmd('session.unsubscribe', events: events_list, contexts: browsing_contexts_list)
@bidi.send_cmd('session.unsubscribe', **opts)
end
end # Session
end # BiDi
Expand Down
44 changes: 44 additions & 0 deletions rb/lib/selenium/webdriver/bidi/struct.rb
Original file line number Diff line number Diff line change
@@ -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
class BiDi
class Struct < ::Struct
class << self
def new(*args, &block)
super(*args) do
define_method(:initialize) do |**kwargs|
converted_kwargs = kwargs.transform_keys { |key| self.class.camel_to_snake(key.to_s).to_sym }
super(*converted_kwargs.values_at(*self.class.members))
end
class_eval(&block) if block
end
end

def camel_to_snake(camel_str)
camel_str.gsub(/([A-Z])/, '_\1').downcase
end
end
end
end

# BiDi
end # WebDriver
end # Selenium
1 change: 1 addition & 0 deletions rb/lib/selenium/webdriver/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,4 @@
require 'selenium/webdriver/common/shadow_root'
require 'selenium/webdriver/common/websocket_connection'
require 'selenium/webdriver/common/child_process'
require 'selenium/webdriver/common/script'
34 changes: 20 additions & 14 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 All @@ -100,6 +99,22 @@ def navigate
@navigate ||= WebDriver::Navigation.new(bridge)
end

#
# @return [Script]
# @see Script
#

def script(*args)
if args.any?
WebDriver.logger.deprecate('`Driver#script` as an alias for `#execute_script`',
'`Driver#execute_script`',
id: :driver_script)
execute_script(*args)
else
@script ||= WebDriver::Script.new(bridge)
end
end

#
# @return [TargetLocator]
# @see TargetLocator
Expand Down Expand Up @@ -174,18 +189,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 Expand Up @@ -267,12 +278,6 @@ def add_virtual_authenticator(options)

alias all find_elements

#
# driver.script('function() { ... };')
#

alias script execute_script

# Get the first element matching the given selector. If given a
# String or Symbol, it will be used as the id of the element.
#
Expand Down Expand Up @@ -313,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
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
Loading

0 comments on commit e037c9f

Please sign in to comment.