Skip to content
Open
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
10 changes: 10 additions & 0 deletions .github/workflows/bazel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ on:
required: false
type: boolean
default: false
safari-preview:
description: Whether this job needs Safari Technology Preview installed (macos only)
required: false
type: boolean
default: false
node-version:
description: Custom Node version to install
required: false
Expand Down Expand Up @@ -190,6 +195,11 @@ jobs:
- name: Setup Safari
if: inputs.needs-display && inputs.os == 'macos'
run: sudo safaridriver --enable
- name: Setup Safari Technology Preview
if: inputs.safari-preview && inputs.os == 'macos'
run: |
brew install --cask safari-technology-preview
sudo "/Applications/Safari Technology Preview.app/Contents/MacOS/safaridriver" --enable
- name: Import GPG key
if: inputs.gpg-sign
uses: crazy-max/ghaction-import-gpg@v7
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/ci-ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,11 @@ jobs:
tag_filters: [chrome-beta, firefox-beta, edge-local]
include:
- os: macos
tag_filters: safari-local
tag_filters: safari-local,safari-preview-bidi
Comment thread
titusfortner marked this conversation as resolved.
with:
name: (${{ matrix.tag_filters }})
needs-display: true
safari-preview: ${{ contains(matrix.tag_filters, 'safari-preview') }}
os: ${{ matrix.os }}
rerun-with-debug: true
run: >
Expand Down
1 change: 0 additions & 1 deletion rb/lib/selenium/webdriver/chromium/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ module Chromium

class Driver < WebDriver::Driver
EXTENSIONS = [DriverExtensions::HasCDP,
DriverExtensions::HasBiDi,
DriverExtensions::HasCasting,
DriverExtensions::HasFedCmDialog,
DriverExtensions::HasNetworkConditions,
Expand Down
1 change: 0 additions & 1 deletion rb/lib/selenium/webdriver/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@
require 'selenium/webdriver/common/driver_extensions/uploads_files'
require 'selenium/webdriver/common/driver_extensions/full_page_screenshot'
require 'selenium/webdriver/common/driver_extensions/has_addons'
require 'selenium/webdriver/common/driver_extensions/has_bidi'
require 'selenium/webdriver/common/driver_extensions/has_devtools'
require 'selenium/webdriver/common/driver_extensions/has_file_downloads'
Comment thread
titusfortner marked this conversation as resolved.
Comment thread
titusfortner marked this conversation as resolved.
Comment thread
titusfortner marked this conversation as resolved.
require 'selenium/webdriver/common/driver_extensions/has_session_events'
Comment thread
titusfortner marked this conversation as resolved.
Expand Down
11 changes: 11 additions & 0 deletions rb/lib/selenium/webdriver/common/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,17 @@ def status
@bridge.status
end

#
# Returns the WebDriver BiDi connection for this session.
#
# @return [BiDi]
# @raise [Error::WebDriverError] if BiDi was not enabled for this session
#

def bidi
@bridge.bidi
end

#
# @return [Navigation]
# @see Navigation
Expand Down
36 changes: 0 additions & 36 deletions rb/lib/selenium/webdriver/common/driver_extensions/has_bidi.rb

This file was deleted.

8 changes: 8 additions & 0 deletions rb/lib/selenium/webdriver/common/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ def initialize(**opts)

@options = opts
@options[:browser_name] = self.class::BROWSER

enable_bidi! if @options[:web_socket_url]
end
Comment thread
titusfortner marked this conversation as resolved.

#
Expand All @@ -93,6 +95,12 @@ def add_option(name, value = nil)
@options[name] = value
end

#
# Enables WebDriver BiDi by requesting the W3C webSocketUrl capability.
#
# @return [Boolean]
#

def enable_bidi!
@options[:web_socket_url] = true
end
Expand Down
1 change: 0 additions & 1 deletion rb/lib/selenium/webdriver/firefox/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class Driver < WebDriver::Driver
EXTENSIONS = [DriverExtensions::HasAddons,
DriverExtensions::FullPageScreenshot,
DriverExtensions::HasContext,
DriverExtensions::HasBiDi,
DriverExtensions::HasLogEvents,
DriverExtensions::HasNetworkInterception,
DriverExtensions::PrintsPage].freeze
Expand Down
19 changes: 16 additions & 3 deletions rb/lib/selenium/webdriver/remote/bidi_bridge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,13 @@ class BiDiBridge < Bridge

def create_session(capabilities)
super
socket_url = @capabilities[:web_socket_url]
@bidi = Selenium::WebDriver::BiDi.new(url: socket_url)

begin
@bidi = Selenium::WebDriver::BiDi.new(url: validated_socket_url)
rescue StandardError
quit
raise
end
end
Comment thread
titusfortner marked this conversation as resolved.

def get(url)
Expand All @@ -46,7 +51,7 @@ def refresh
end

def quit
bidi.close
bidi&.close
rescue *QUIT_ERRORS
nil
ensure
Expand All @@ -59,6 +64,14 @@ def close

private

def validated_socket_url
url = @capabilities[:web_socket_url]
return url if url.is_a?(String) && url.start_with?('ws://', 'wss://')

raise Error::WebDriverError,
"BiDi was enabled, but the remote end did not return a valid webSocketUrl: #{url.inspect}."
end

def browsing_context
@browsing_context ||= WebDriver::BiDi::BrowsingContext.new(self)
end
Expand Down
17 changes: 16 additions & 1 deletion rb/lib/selenium/webdriver/safari/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ class Options < WebDriver::Options

# @see https://developer.apple.com/documentation/webkit/about_webdriver_for_safari
CAPABILITIES = {automatic_inspection: 'safari:automaticInspection',
automatic_profiling: 'safari:automaticProfiling'}.freeze
automatic_profiling: 'safari:automaticProfiling',
experimental_web_socket_url: 'safari:experimentalWebSocketUrl'}.freeze
Comment thread
titusfortner marked this conversation as resolved.
BROWSER = 'safari'
TECHNOLOGY_PREVIEW = 'Safari Technology Preview'

Expand All @@ -43,6 +44,20 @@ def browser_name=(value)
def browser_name
@options[:browser_name] = Safari.technology_preview? ? TECHNOLOGY_PREVIEW : BROWSER
end

#
# Enables WebDriver BiDi for Safari, which also requires the experimental capability, and
# warns that Safari's BiDi support is experimental.
#
# @return [Boolean]
#

def enable_bidi!
super
WebDriver.logger.warn("Safari's WebDriver BiDi support is experimental and may be incomplete",
id: :safari_bidi)
Comment thread
titusfortner marked this conversation as resolved.
@options[:experimental_web_socket_url] = true
end
Comment thread
titusfortner marked this conversation as resolved.
Comment thread
titusfortner marked this conversation as resolved.
end # Options
end # Safari
end # WebDriver
Expand Down
2 changes: 2 additions & 0 deletions rb/sig/lib/selenium/webdriver/common/driver.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ module Selenium

def status: () -> Hash[untyped, untyped]

def bidi: () -> BiDi

def navigate: () -> Navigation

def switch_to: () -> TargetLocator
Expand Down

This file was deleted.

2 changes: 2 additions & 0 deletions rb/sig/lib/selenium/webdriver/remote/bidi_bridge.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ module Selenium

private

def validated_socket_url: () -> String

def browsing_context: () -> BiDi::BrowsingContext
end
end
Expand Down
10 changes: 5 additions & 5 deletions rb/spec/integration/selenium/webdriver/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("@rules_ruby//ruby:defs.bzl", "rb_library")
load("//rb/spec:tests.bzl", "DEFAULT_BROWSERS", "rb_integration_test")
load("//rb/spec:tests.bzl", "rb_integration_test")

rb_library(
name = "spec_helper",
Expand Down Expand Up @@ -66,8 +66,7 @@ _NO_GRID = ["driver_finder_spec.rb"]
rb_integration_test(
name = f[:-8],
srcs = [f],
browsers = DEFAULT_BROWSERS,
no_grid = True,
grid = False,
tags = ["se-manager"],
deps = [
"//rb/lib/selenium/webdriver:common",
Expand All @@ -92,7 +91,7 @@ _NO_GRID = ["driver_finder_spec.rb"]
rb_integration_test(
name = f[:-8],
srcs = [f],
tags = ["bidi"],
bidi = True,
deps = [
"//rb/lib/selenium/webdriver:bidi",
],
Expand All @@ -104,7 +103,8 @@ _NO_GRID = ["driver_finder_spec.rb"]
rb_integration_test(
name = f[:-8],
srcs = [f],
bidi_only = True,
bidi = True,
classic = False,
deps = [
"//rb/lib/selenium/webdriver:bidi",
],
Expand Down
3 changes: 2 additions & 1 deletion rb/spec/integration/selenium/webdriver/bidi/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ load("//rb/spec:tests.bzl", "rb_integration_test")
rb_integration_test(
name = file[:-8],
srcs = [file],
bidi_only = True,
bidi = True,
classic = False,
tags = ["exclusive-if-local"],
deps = [
"//rb/lib/selenium/webdriver:bidi",
Expand Down
20 changes: 15 additions & 5 deletions rb/spec/integration/selenium/webdriver/bidi/browser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,18 @@ class BiDi

let(:bidi) { driver.bidi }

it 'creates an user context' do
it 'creates a user context',
pending_if: {browser: %i[safari safari_preview],
reason: 'Safari does not support BiDi user contexts or getClientWindows'} do
browser = described_class.new(bidi)
user_context = browser.create_user_context
expect(user_context).not_to be_nil
expect(user_context['userContext']).to be_a String
end

it 'gets user contexts' do
it 'gets user contexts',
pending_if: {browser: %i[safari safari_preview],
reason: 'Safari does not support BiDi user contexts or getClientWindows'} do
browser = described_class.new(bidi)
created_context_id = browser.create_user_context['userContext']
all_context_ids = browser.user_contexts['userContexts'].map { |c| c['userContext'] }
Expand All @@ -51,21 +55,27 @@ class BiDi
expect(all_ids_after_removal).not_to include(context_id_to_remove)
end

it 'throws an error when removing the default user context' do
it 'throws an error when removing the default user context',
pending_if: {browser: %i[safari safari_preview],
reason: 'Safari does not support BiDi user contexts or getClientWindows'} do
browser = described_class.new(bidi)
expect {
browser.remove_user_context('default')
}.to raise_error(Error::WebDriverError, /user context cannot be removed/)
end

it 'throws an error when removing a non-existent user context' do
it 'throws an error when removing a non-existent user context',
pending_if: {browser: %i[safari safari_preview],
reason: 'Safari does not support BiDi user contexts or getClientWindows'} do
browser = described_class.new(bidi)
expect {
browser.remove_user_context('fake_context')
}.to raise_error(Error::WebDriverError)
end

it 'get windows' do
it 'gets windows',
pending_if: {browser: %i[safari safari_preview],
reason: 'Safari does not support BiDi user contexts or getClientWindows'} do
browser = described_class.new(bidi)
windows = browser.windows
active_window = windows.first
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ class BiDi
expect(driver.window_handles).to include(id)
end

it 'errors on unknown type', pending_if: {browser: :firefox, reason: "Doesn't return the expected error"} do
it 'errors on unknown type',
pending_if: {browser: %i[firefox safari safari_preview], reason: "Doesn't return the expected error"} do
msg = /invalid argument: Invalid enum value. Expected 'tab' | 'window', received 'unknown'/
expect {
described_class.new(bridge).create(type: :unknown)
Expand Down Expand Up @@ -123,7 +124,8 @@ class BiDi
expect(driver.title).to eq('Testing Alerts')
end

it 'activates a browser context' do
it 'activates a browser context',
pending_if: {browser: %i[safari safari_preview], reason: 'Safari does not focus the activated context'} do
browsing_context = described_class.new(bridge)
browsing_context.create

Expand Down
Loading
Loading