diff --git a/.github/workflows/ci-ruby.yml b/.github/workflows/ci-ruby.yml index c6a3702fed30f..c8e3e0c6c41e4 100644 --- a/.github/workflows/ci-ruby.yml +++ b/.github/workflows/ci-ruby.yml @@ -48,7 +48,7 @@ jobs: bazel test --keep_going --test_size_filters small - //rb/spec/... + //rb/... smoke: name: ${{ matrix.os }}-smoke diff --git a/rb/.rubocop.yml b/rb/.rubocop.yml index 44009c1966ae6..e9ea634c827d0 100644 --- a/rb/.rubocop.yml +++ b/rb/.rubocop.yml @@ -44,6 +44,8 @@ Metrics/ClassLength: Exclude: - 'lib/selenium/webdriver/remote/bridge.rb' - 'lib/selenium/webdriver/remote/capabilities.rb' + - 'lib/selenium/webdriver/bidi/support/bidi_generate.rb' + - 'lib/selenium/webdriver/bidi/protocol/**/*' - 'spec/integration/selenium/webdriver/spec_support/test_environment.rb' Metrics/CyclomaticComplexity: @@ -64,6 +66,7 @@ Metrics/ModuleLength: Max: 110 Exclude: - 'lib/selenium/webdriver/common/platform.rb' + - 'lib/selenium/webdriver/bidi/support/bidi_generate.rb' - 'spec/**/*' Metrics/PerceivedComplexity: @@ -77,6 +80,10 @@ Metrics/ParameterLists: Naming/BlockForwarding: EnforcedStyle: explicit +Naming/AccessorMethodName: + Exclude: + - 'lib/selenium/webdriver/bidi/protocol/**/*' + Naming/FileName: Exclude: - 'lib/selenium-webdriver.rb' diff --git a/rb/Steepfile b/rb/Steepfile index 9114476f06176..f0f3b77bd2ec2 100644 --- a/rb/Steepfile +++ b/rb/Steepfile @@ -6,8 +6,16 @@ target :lib do # Total amount of errors ignore 64 in 29 files ignore( - # Ignore all files in the bidi directory until we decide the implementation - 'lib/selenium/webdriver/bidi/**/*.rb', + # Ignore all hand-written files in the bidi directory while we update the implementation + 'lib/selenium/webdriver/bidi/network/**/*.rb', + 'lib/selenium/webdriver/bidi/browser.rb', + 'lib/selenium/webdriver/bidi/browsing_context.rb', + 'lib/selenium/webdriver/bidi/log_handler.rb', + 'lib/selenium/webdriver/bidi/network.rb', + 'lib/selenium/webdriver/bidi/session.rb', + 'lib/selenium/webdriver/bidi/struct.rb', + # The generator + its up-to-date checker are build tooling, not typed runtime code + 'lib/selenium/webdriver/bidi/support/**/*.rb', # Ignore all spec files 'spec/**/*.rb', # Ignore line 166 due to UDP RBS issue diff --git a/rb/lib/selenium/webdriver/BUILD.bazel b/rb/lib/selenium/webdriver/BUILD.bazel index 44b1e16651595..d0342924f2a66 100644 --- a/rb/lib/selenium/webdriver/BUILD.bazel +++ b/rb/lib/selenium/webdriver/BUILD.bazel @@ -1,6 +1,8 @@ load( "@rules_ruby//ruby:defs.bzl", + "rb_binary", "rb_library", + "rb_test", ) package(default_visibility = ["//rb:__subpackages__"]) @@ -24,6 +26,40 @@ rb_library( deps = [":common"], ) +rb_binary( + name = "bidi-generate", + srcs = ["bidi/support/bidi_generate.rb"], + args = [ + "$(location //javascript/selenium-webdriver:create-bidi-src_schema)", + "rb/lib/selenium/webdriver/bidi/protocol", + ], + data = [ + "bidi/support/templates/module.rb.erb", + "bidi/support/templates/module.rbs.erb", + "//javascript/selenium-webdriver:create-bidi-src_schema", + ], + main = "bidi/support/bidi_generate.rb", +) + +# Fails if a checked-in protocol .rb was hand-edited or left stale after a generator/schema +# change. Re-renders each module in memory and compares (see check_generated.rb). Fix with +# `bazel run //rb/lib/selenium/webdriver:bidi-generate`. +rb_test( + name = "verify-bidi-generated", + size = "small", + srcs = ["bidi/support/check_generated.rb"], + args = ["$(rootpath //javascript/selenium-webdriver:create-bidi-src_schema)"], + data = [ + "bidi/support/bidi_generate.rb", + "bidi/support/templates/module.rb.erb", + "//javascript/selenium-webdriver:create-bidi-src_schema", + ] + glob( + ["bidi/protocol/*.rb"], + exclude = ["bidi/protocol/domain.rb"], + ), + main = "bidi/support/check_generated.rb", +) + rb_library( name = "devtools", srcs = glob([ diff --git a/rb/lib/selenium/webdriver/bidi.rb b/rb/lib/selenium/webdriver/bidi.rb index 80fc5b92fbe22..8cfe33f9a5d30 100644 --- a/rb/lib/selenium/webdriver/bidi.rb +++ b/rb/lib/selenium/webdriver/bidi.rb @@ -35,6 +35,9 @@ def initialize(url:) @ws = WebSocketConnection.new(url: url) end + # @api private + attr_reader :ws + def close @ws.close end diff --git a/rb/lib/selenium/webdriver/bidi/protocol.rb b/rb/lib/selenium/webdriver/bidi/protocol.rb new file mode 100644 index 0000000000000..425bccdd4a93e --- /dev/null +++ b/rb/lib/selenium/webdriver/bidi/protocol.rb @@ -0,0 +1,39 @@ +# 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. + +# serialization must load first (it defines the Serialization runtime the generated +# classes build on), then the Domain base the generated classes subclass. Add a require +# below when a new BiDi domain is generated. +require 'selenium/webdriver/bidi/serialization' +require 'selenium/webdriver/bidi/transport' +require 'selenium/webdriver/bidi/protocol/domain' +require 'selenium/webdriver/bidi/protocol/bluetooth' +require 'selenium/webdriver/bidi/protocol/browser' +require 'selenium/webdriver/bidi/protocol/browsing_context' +require 'selenium/webdriver/bidi/protocol/emulation' +require 'selenium/webdriver/bidi/protocol/input' +require 'selenium/webdriver/bidi/protocol/log' +require 'selenium/webdriver/bidi/protocol/network' +require 'selenium/webdriver/bidi/protocol/permissions' +require 'selenium/webdriver/bidi/protocol/script' +require 'selenium/webdriver/bidi/protocol/session' +require 'selenium/webdriver/bidi/protocol/speculation' +require 'selenium/webdriver/bidi/protocol/storage' +require 'selenium/webdriver/bidi/protocol/user_agent_client_hints' +require 'selenium/webdriver/bidi/protocol/web_extension' diff --git a/rb/lib/selenium/webdriver/bidi/protocol/bluetooth.rb b/rb/lib/selenium/webdriver/bidi/protocol/bluetooth.rb new file mode 100644 index 0000000000000..702fe248e248c --- /dev/null +++ b/rb/lib/selenium/webdriver/bidi/protocol/bluetooth.rb @@ -0,0 +1,442 @@ +# 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. + +# This file is automatically generated. DO NOT EDIT! +# Regenerate with: bazel run //rb/lib/selenium/webdriver:bidi-generate + +module Selenium + module WebDriver + class BiDi + module Protocol + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + class Bluetooth < Domain + EVENTS = { + request_device_prompt_updated: 'bluetooth.requestDevicePromptUpdated', + gatt_connection_attempted: 'bluetooth.gattConnectionAttempted' + }.freeze + + SIMULATE_ADAPTER_PARAMETERS_STATE = { + absent: 'absent', + powered_off: 'powered-off', + powered_on: 'powered-on' + }.freeze + + SIMULATE_SERVICE_PARAMETERS_TYPE = { + add: 'add', + remove: 'remove' + }.freeze + + SIMULATE_CHARACTERISTIC_PARAMETERS_TYPE = { + add: 'add', + remove: 'remove' + }.freeze + + SIMULATE_CHARACTERISTIC_RESPONSE_PARAMETERS_TYPE = { + read: 'read', + write: 'write', + subscribe_to_notifications: 'subscribe-to-notifications', + unsubscribe_from_notifications: 'unsubscribe-from-notifications' + }.freeze + + SIMULATE_DESCRIPTOR_PARAMETERS_TYPE = { + add: 'add', + remove: 'remove' + }.freeze + + SIMULATE_DESCRIPTOR_RESPONSE_PARAMETERS_TYPE = { + read: 'read', + write: 'write' + }.freeze + + CHARACTERISTIC_EVENT_GENERATED_PARAMETERS_TYPE = { + read: 'read', + write_with_response: 'write-with-response', + write_without_response: 'write-without-response', + subscribe_to_notifications: 'subscribe-to-notifications', + unsubscribe_from_notifications: 'unsubscribe-from-notifications' + }.freeze + + DESCRIPTOR_EVENT_GENERATED_PARAMETERS_TYPE = { + read: 'read', + write: 'write' + }.freeze + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + BluetoothManufacturerData = Serialization::Record.define(key: 'key', data: 'data') + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + CharacteristicProperties = Serialization::Record.define( + broadcast: 'broadcast', + read: 'read', + write_without_response: 'writeWithoutResponse', + write: 'write', + notify: 'notify', + indicate: 'indicate', + authenticated_signed_writes: 'authenticatedSignedWrites', + extended_properties: 'extendedProperties' + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + RequestDeviceInfo = Serialization::Record.define(id: 'id', name: {json_key: 'name', nullable: true}) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + ScanRecord = Serialization::Record.define( + name: 'name', + uuids: {json_key: 'uuids', list: true}, + appearance: 'appearance', + manufacturer_data: {json_key: 'manufacturerData', ref: 'Bluetooth::BluetoothManufacturerData', list: true} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + class HandleRequestDevicePromptParameters < Serialization::Union + discriminator 'accept' + variants( + true => 'Bluetooth::HandleRequestDevicePromptParameters::AcceptParameters', + false => 'Bluetooth::HandleRequestDevicePromptParameters::CancelParameters' + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + AcceptParameters = Serialization::Record.define( + accept: {fixed: true}, + context: 'context', + prompt: 'prompt', + device: 'device' + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + CancelParameters = Serialization::Record.define( + accept: {fixed: false}, + context: 'context', + prompt: 'prompt' + ) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + SimulateAdapterParameters = Serialization::Record.define( + context: 'context', + le_supported: 'leSupported', + state: {json_key: 'state', enum: 'Bluetooth::SIMULATE_ADAPTER_PARAMETERS_STATE'} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + DisableSimulationParameters = Serialization::Record.define(context: 'context') + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + SimulatePreconnectedPeripheralParameters = Serialization::Record.define( + context: 'context', + address: 'address', + name: 'name', + manufacturer_data: {json_key: 'manufacturerData', ref: 'Bluetooth::BluetoothManufacturerData', list: true}, + known_service_uuids: {json_key: 'knownServiceUuids', list: true} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + SimulateAdvertisementParameters = Serialization::Record.define( + context: 'context', + scan_entry: {json_key: 'scanEntry', ref: 'Bluetooth::SimulateAdvertisementScanEntryParameters'} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + SimulateAdvertisementScanEntryParameters = Serialization::Record.define( + device_address: 'deviceAddress', + rssi: 'rssi', + scan_record: {json_key: 'scanRecord', ref: 'Bluetooth::ScanRecord'} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + SimulateGattConnectionResponseParameters = Serialization::Record.define( + context: 'context', + address: 'address', + code: 'code' + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + SimulateGattDisconnectionParameters = Serialization::Record.define(context: 'context', address: 'address') + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + SimulateServiceParameters = Serialization::Record.define( + context: 'context', + address: 'address', + uuid: 'uuid', + type: {json_key: 'type', enum: 'Bluetooth::SIMULATE_SERVICE_PARAMETERS_TYPE'} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + SimulateCharacteristicParameters = Serialization::Record.define( + context: 'context', + address: 'address', + service_uuid: 'serviceUuid', + characteristic_uuid: 'characteristicUuid', + characteristic_properties: {json_key: 'characteristicProperties', ref: 'Bluetooth::CharacteristicProperties'}, + type: {json_key: 'type', enum: 'Bluetooth::SIMULATE_CHARACTERISTIC_PARAMETERS_TYPE'} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + SimulateCharacteristicResponseParameters = Serialization::Record.define( + context: 'context', + address: 'address', + service_uuid: 'serviceUuid', + characteristic_uuid: 'characteristicUuid', + type: {json_key: 'type', enum: 'Bluetooth::SIMULATE_CHARACTERISTIC_RESPONSE_PARAMETERS_TYPE'}, + code: 'code', + data: {json_key: 'data', list: true} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + SimulateDescriptorParameters = Serialization::Record.define( + context: 'context', + address: 'address', + service_uuid: 'serviceUuid', + characteristic_uuid: 'characteristicUuid', + descriptor_uuid: 'descriptorUuid', + type: {json_key: 'type', enum: 'Bluetooth::SIMULATE_DESCRIPTOR_PARAMETERS_TYPE'} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + SimulateDescriptorResponseParameters = Serialization::Record.define( + context: 'context', + address: 'address', + service_uuid: 'serviceUuid', + characteristic_uuid: 'characteristicUuid', + descriptor_uuid: 'descriptorUuid', + type: {json_key: 'type', enum: 'Bluetooth::SIMULATE_DESCRIPTOR_RESPONSE_PARAMETERS_TYPE'}, + code: 'code', + data: {json_key: 'data', list: true} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + RequestDevicePromptUpdatedParameters = Serialization::Record.define( + context: 'context', + prompt: 'prompt', + devices: {json_key: 'devices', ref: 'Bluetooth::RequestDeviceInfo', list: true} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + GattConnectionAttemptedParameters = Serialization::Record.define(context: 'context', address: 'address') + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + CharacteristicEventGeneratedParameters = Serialization::Record.define( + context: 'context', + address: 'address', + service_uuid: 'serviceUuid', + characteristic_uuid: 'characteristicUuid', + type: {json_key: 'type', enum: 'Bluetooth::CHARACTERISTIC_EVENT_GENERATED_PARAMETERS_TYPE'}, + data: {json_key: 'data', list: true} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + DescriptorEventGeneratedParameters = Serialization::Record.define( + context: 'context', + address: 'address', + service_uuid: 'serviceUuid', + characteristic_uuid: 'characteristicUuid', + descriptor_uuid: 'descriptorUuid', + type: {json_key: 'type', enum: 'Bluetooth::DESCRIPTOR_EVENT_GENERATED_PARAMETERS_TYPE'}, + data: {json_key: 'data', list: true} + ) + + EVENT_TYPES = { + 'bluetooth.requestDevicePromptUpdated' => Bluetooth::RequestDevicePromptUpdatedParameters, + 'bluetooth.gattConnectionAttempted' => Bluetooth::GattConnectionAttemptedParameters + }.freeze + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def handle_request_device_prompt(context:, prompt:, accept:, device: Serialization::UNSET) + params = HandleRequestDevicePromptParameters.build( + context: context, + prompt: prompt, + accept: accept, + device: device + ) + execute(cmd: 'bluetooth.handleRequestDevicePrompt', params: params) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def simulate_adapter(context:, state:, le_supported: Serialization::UNSET) + Serialization.validate!('state', state, Bluetooth::SIMULATE_ADAPTER_PARAMETERS_STATE) + params = SimulateAdapterParameters.new(context: context, le_supported: le_supported, state: state) + execute(cmd: 'bluetooth.simulateAdapter', params: params) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def disable_simulation(context:) + params = DisableSimulationParameters.new(context: context) + execute(cmd: 'bluetooth.disableSimulation', params: params) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def simulate_preconnected_peripheral(context:, address:, name:, manufacturer_data:, known_service_uuids:) + params = SimulatePreconnectedPeripheralParameters.new( + context: context, + address: address, + name: name, + manufacturer_data: manufacturer_data, + known_service_uuids: known_service_uuids + ) + execute(cmd: 'bluetooth.simulatePreconnectedPeripheral', params: params) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def simulate_advertisement(context:, scan_entry:) + params = SimulateAdvertisementParameters.new(context: context, scan_entry: scan_entry) + execute(cmd: 'bluetooth.simulateAdvertisement', params: params) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def simulate_gatt_connection_response(context:, address:, code:) + params = SimulateGattConnectionResponseParameters.new(context: context, address: address, code: code) + execute(cmd: 'bluetooth.simulateGattConnectionResponse', params: params) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def simulate_gatt_disconnection(context:, address:) + params = SimulateGattDisconnectionParameters.new(context: context, address: address) + execute(cmd: 'bluetooth.simulateGattDisconnection', params: params) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def simulate_service(context:, address:, uuid:, type:) + Serialization.validate!('type', type, Bluetooth::SIMULATE_SERVICE_PARAMETERS_TYPE) + params = SimulateServiceParameters.new(context: context, address: address, uuid: uuid, type: type) + execute(cmd: 'bluetooth.simulateService', params: params) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def simulate_characteristic( + context:, + address:, + service_uuid:, + characteristic_uuid:, + type:, + characteristic_properties: Serialization::UNSET + ) + Serialization.validate!('type', type, Bluetooth::SIMULATE_CHARACTERISTIC_PARAMETERS_TYPE) + params = SimulateCharacteristicParameters.new( + context: context, + address: address, + service_uuid: service_uuid, + characteristic_uuid: characteristic_uuid, + characteristic_properties: characteristic_properties, + type: type + ) + execute(cmd: 'bluetooth.simulateCharacteristic', params: params) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def simulate_characteristic_response( + context:, + address:, + service_uuid:, + characteristic_uuid:, + type:, + code:, + data: Serialization::UNSET + ) + Serialization.validate!('type', type, Bluetooth::SIMULATE_CHARACTERISTIC_RESPONSE_PARAMETERS_TYPE) + params = SimulateCharacteristicResponseParameters.new( + context: context, + address: address, + service_uuid: service_uuid, + characteristic_uuid: characteristic_uuid, + type: type, + code: code, + data: data + ) + execute(cmd: 'bluetooth.simulateCharacteristicResponse', params: params) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def simulate_descriptor(context:, address:, service_uuid:, characteristic_uuid:, descriptor_uuid:, type:) + Serialization.validate!('type', type, Bluetooth::SIMULATE_DESCRIPTOR_PARAMETERS_TYPE) + params = SimulateDescriptorParameters.new( + context: context, + address: address, + service_uuid: service_uuid, + characteristic_uuid: characteristic_uuid, + descriptor_uuid: descriptor_uuid, + type: type + ) + execute(cmd: 'bluetooth.simulateDescriptor', params: params) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def simulate_descriptor_response( + context:, + address:, + service_uuid:, + characteristic_uuid:, + descriptor_uuid:, + type:, + code:, + data: Serialization::UNSET + ) + Serialization.validate!('type', type, Bluetooth::SIMULATE_DESCRIPTOR_RESPONSE_PARAMETERS_TYPE) + params = SimulateDescriptorResponseParameters.new( + context: context, + address: address, + service_uuid: service_uuid, + characteristic_uuid: characteristic_uuid, + descriptor_uuid: descriptor_uuid, + type: type, + code: code, + data: data + ) + execute(cmd: 'bluetooth.simulateDescriptorResponse', params: params) + end + end # Bluetooth + end # Protocol + end # BiDi + end # WebDriver +end # Selenium diff --git a/rb/lib/selenium/webdriver/bidi/protocol/browser.rb b/rb/lib/selenium/webdriver/bidi/protocol/browser.rb new file mode 100644 index 0000000000000..b21ae8a5c69a2 --- /dev/null +++ b/rb/lib/selenium/webdriver/bidi/protocol/browser.rb @@ -0,0 +1,215 @@ +# 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. + +# This file is automatically generated. DO NOT EDIT! +# Regenerate with: bazel run //rb/lib/selenium/webdriver:bidi-generate + +module Selenium + module WebDriver + class BiDi + module Protocol + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + class Browser < Domain + CLIENT_WINDOW_INFO_STATE = { + fullscreen: 'fullscreen', + maximized: 'maximized', + minimized: 'minimized', + normal: 'normal' + }.freeze + + CLIENT_WINDOW_NAMED_STATE_STATE = { + fullscreen: 'fullscreen', + maximized: 'maximized', + minimized: 'minimized' + }.freeze + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + ClientWindowInfo = Serialization::Record.define( + active: 'active', + client_window: 'clientWindow', + height: 'height', + state: {json_key: 'state', enum: 'Browser::CLIENT_WINDOW_INFO_STATE'}, + width: 'width', + x: 'x', + y: 'y' + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + UserContextInfo = Serialization::Record.define(user_context: 'userContext') + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + CreateUserContextParameters = Serialization::Record.define( + accept_insecure_certs: 'acceptInsecureCerts', + proxy: {json_key: 'proxy', ref: 'Session::ProxyConfiguration'}, + unhandled_prompt_behavior: {json_key: 'unhandledPromptBehavior', ref: 'Session::UserPromptHandler'} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + GetClientWindowsResult = Serialization::Record.define( + client_windows: {json_key: 'clientWindows', ref: 'Browser::ClientWindowInfo', list: true} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + GetUserContextsResult = Serialization::Record.define( + user_contexts: {json_key: 'userContexts', ref: 'Browser::UserContextInfo', list: true} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + RemoveUserContextParameters = Serialization::Record.define(user_context: 'userContext') + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + class SetClientWindowStateParameters < Serialization::Union + discriminator 'state', {normal: 'normal'} + variants( + normal: 'Browser::SetClientWindowStateParameters::ClientWindowRectState' + ) + fallback 'Browser::SetClientWindowStateParameters::ClientWindowNamedState' + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + ClientWindowNamedState = Serialization::Record.define( + client_window: 'clientWindow', + state: {json_key: 'state', enum: 'Browser::CLIENT_WINDOW_NAMED_STATE_STATE'} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + ClientWindowRectState = Serialization::Record.define( + state: {fixed: 'normal'}, + client_window: 'clientWindow', + width: 'width', + height: 'height', + x: 'x', + y: 'y' + ) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + SetDownloadBehaviorParameters = Serialization::Record.define( + download_behavior: {json_key: 'downloadBehavior', nullable: true, ref: 'Browser::DownloadBehavior'}, + user_contexts: {json_key: 'userContexts', list: true} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + class DownloadBehavior < Serialization::Union + discriminator 'type', {allowed: 'allowed', denied: 'denied'} + variants( + allowed: 'Browser::DownloadBehavior::Allowed', + denied: 'Browser::DownloadBehavior::Denied' + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + Allowed = Serialization::Record.define(type: {fixed: 'allowed'}, destination_folder: 'destinationFolder') + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + Denied = Serialization::Record.define(type: {fixed: 'denied'}) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def close + execute(cmd: 'browser.close') + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def create_user_context( + accept_insecure_certs: Serialization::UNSET, + proxy: Serialization::UNSET, + unhandled_prompt_behavior: Serialization::UNSET + ) + params = CreateUserContextParameters.new( + accept_insecure_certs: accept_insecure_certs, + proxy: proxy, + unhandled_prompt_behavior: unhandled_prompt_behavior + ) + execute(cmd: 'browser.createUserContext', params: params, result: Browser::UserContextInfo) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def get_client_windows + execute(cmd: 'browser.getClientWindows', result: Browser::GetClientWindowsResult) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def get_user_contexts + execute(cmd: 'browser.getUserContexts', result: Browser::GetUserContextsResult) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def remove_user_context(user_context:) + params = RemoveUserContextParameters.new(user_context: user_context) + execute(cmd: 'browser.removeUserContext', params: params) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def set_client_window_state( + client_window:, + state:, + width: Serialization::UNSET, + height: Serialization::UNSET, + x: Serialization::UNSET, + y: Serialization::UNSET + ) + Serialization.validate!( + 'state', + state, + {normal: 'normal', fullscreen: 'fullscreen', maximized: 'maximized', minimized: 'minimized'} + ) + params = SetClientWindowStateParameters.build( + client_window: client_window, + state: state, + width: width, + height: height, + x: x, + y: y + ) + execute(cmd: 'browser.setClientWindowState', params: params, result: Browser::ClientWindowInfo) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def set_download_behavior(download_behavior:, user_contexts: Serialization::UNSET) + params = SetDownloadBehaviorParameters.new( + download_behavior: download_behavior, + user_contexts: user_contexts + ) + execute(cmd: 'browser.setDownloadBehavior', params: params) + end + end # Browser + end # Protocol + end # BiDi + end # WebDriver +end # Selenium diff --git a/rb/lib/selenium/webdriver/bidi/protocol/browsing_context.rb b/rb/lib/selenium/webdriver/bidi/protocol/browsing_context.rb new file mode 100644 index 0000000000000..bbecb1fe34129 --- /dev/null +++ b/rb/lib/selenium/webdriver/bidi/protocol/browsing_context.rb @@ -0,0 +1,597 @@ +# 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. + +# This file is automatically generated. DO NOT EDIT! +# Regenerate with: bazel run //rb/lib/selenium/webdriver:bidi-generate + +module Selenium + module WebDriver + class BiDi + module Protocol + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + class BrowsingContext < Domain + EVENTS = { + context_created: 'browsingContext.contextCreated', + context_destroyed: 'browsingContext.contextDestroyed', + dom_content_loaded: 'browsingContext.domContentLoaded', + download_end: 'browsingContext.downloadEnd', + download_will_begin: 'browsingContext.downloadWillBegin', + fragment_navigated: 'browsingContext.fragmentNavigated', + history_updated: 'browsingContext.historyUpdated', + load: 'browsingContext.load', + navigation_aborted: 'browsingContext.navigationAborted', + navigation_committed: 'browsingContext.navigationCommitted', + navigation_failed: 'browsingContext.navigationFailed', + navigation_started: 'browsingContext.navigationStarted', + user_prompt_closed: 'browsingContext.userPromptClosed', + user_prompt_opened: 'browsingContext.userPromptOpened' + }.freeze + + READINESS_STATE = { + none: 'none', + interactive: 'interactive', + complete: 'complete' + }.freeze + + USER_PROMPT_TYPE = { + alert: 'alert', + beforeunload: 'beforeunload', + confirm: 'confirm', + prompt: 'prompt' + }.freeze + + CREATE_TYPE = { + tab: 'tab', + window: 'window' + }.freeze + + INNER_TEXT_LOCATOR_MATCH_TYPE = { + full: 'full', + partial: 'partial' + }.freeze + + CAPTURE_SCREENSHOT_PARAMETERS_ORIGIN = { + viewport: 'viewport', + document: 'document' + }.freeze + + PRINT_PARAMETERS_ORIENTATION = { + portrait: 'portrait', + landscape: 'landscape' + }.freeze + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + Info = Serialization::Record.define( + children: {json_key: 'children', nullable: true, ref: 'BrowsingContext::Info', list: true}, + client_window: 'clientWindow', + context: 'context', + original_opener: {json_key: 'originalOpener', nullable: true}, + url: 'url', + user_context: 'userContext', + parent: {json_key: 'parent', nullable: true} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + class Locator < Serialization::Union + discriminator 'type', { + accessibility: 'accessibility', + css: 'css', + context: 'context', + inner_text: 'innerText', + xpath: 'xpath' + } + variants( + accessibility: 'BrowsingContext::AccessibilityLocator', + css: 'BrowsingContext::CssLocator', + context: 'BrowsingContext::ContextLocator', + inner_text: 'BrowsingContext::InnerTextLocator', + xpath: 'BrowsingContext::XPathLocator' + ) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + AccessibilityLocator = Serialization::Record.define( + type: {fixed: 'accessibility'}, + value: {json_key: 'value', ref: 'BrowsingContext::AccessibilityLocator::Value'} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + AccessibilityLocator::Value = Serialization::Record.define(name: 'name', role: 'role') + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + CssLocator = Serialization::Record.define(type: {fixed: 'css'}, value: 'value') + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + ContextLocator = Serialization::Record.define( + type: {fixed: 'context'}, + value: {json_key: 'value', ref: 'BrowsingContext::ContextLocator::Value'} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + ContextLocator::Value = Serialization::Record.define(context: 'context') + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + InnerTextLocator = Serialization::Record.define( + type: {fixed: 'innerText'}, + value: 'value', + ignore_case: 'ignoreCase', + match_type: {json_key: 'matchType', enum: 'BrowsingContext::INNER_TEXT_LOCATOR_MATCH_TYPE'}, + max_depth: 'maxDepth' + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + XPathLocator = Serialization::Record.define(type: {fixed: 'xpath'}, value: 'value') + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + BaseNavigationInfo = Serialization::Record.define( + context: 'context', + navigation: {json_key: 'navigation', nullable: true}, + timestamp: 'timestamp', + url: 'url', + user_context: 'userContext' + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + NavigationInfo = Serialization::Record.define( + context: 'context', + navigation: {json_key: 'navigation', nullable: true}, + timestamp: 'timestamp', + url: 'url', + user_context: 'userContext' + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + ActivateParameters = Serialization::Record.define(context: 'context') + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + CaptureScreenshotParameters = Serialization::Record.define( + context: 'context', + origin: {json_key: 'origin', enum: 'BrowsingContext::CAPTURE_SCREENSHOT_PARAMETERS_ORIGIN'}, + format: {json_key: 'format', ref: 'BrowsingContext::ImageFormat'}, + clip: {json_key: 'clip', ref: 'BrowsingContext::ClipRectangle'} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + ImageFormat = Serialization::Record.define(type: 'type', quality: 'quality') + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + class ClipRectangle < Serialization::Union + discriminator 'type', {box: 'box', element: 'element'} + variants( + box: 'BrowsingContext::BoxClipRectangle', + element: 'BrowsingContext::ElementClipRectangle' + ) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + ElementClipRectangle = Serialization::Record.define( + type: {fixed: 'element'}, + element: {json_key: 'element', ref: 'Script::SharedReference'} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + BoxClipRectangle = Serialization::Record.define( + type: {fixed: 'box'}, + x: 'x', + y: 'y', + width: 'width', + height: 'height' + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + CaptureScreenshotResult = Serialization::Record.define(data: 'data') + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + CloseParameters = Serialization::Record.define(context: 'context', prompt_unload: 'promptUnload') + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + CreateParameters = Serialization::Record.define( + type: {json_key: 'type', enum: 'BrowsingContext::CREATE_TYPE'}, + reference_context: 'referenceContext', + background: 'background', + user_context: 'userContext' + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + CreateResult = Serialization::Record.define(context: 'context', user_context: 'userContext') + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + GetTreeParameters = Serialization::Record.define(max_depth: 'maxDepth', root: 'root') + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + GetTreeResult = Serialization::Record.define( + contexts: {json_key: 'contexts', ref: 'BrowsingContext::Info', list: true} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + HandleUserPromptParameters = Serialization::Record.define( + context: 'context', + accept: 'accept', + user_text: 'userText' + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + LocateNodesParameters = Serialization::Record.define( + context: 'context', + locator: {json_key: 'locator', ref: 'BrowsingContext::Locator'}, + max_node_count: 'maxNodeCount', + serialization_options: {json_key: 'serializationOptions', ref: 'Script::SerializationOptions'}, + start_nodes: {json_key: 'startNodes', ref: 'Script::SharedReference', list: true} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + LocateNodesResult = Serialization::Record.define( + nodes: {json_key: 'nodes', ref: 'Script::NodeRemoteValue', list: true} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + NavigateParameters = Serialization::Record.define( + context: 'context', + url: 'url', + wait: {json_key: 'wait', enum: 'BrowsingContext::READINESS_STATE'} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + NavigateResult = Serialization::Record.define( + navigation: {json_key: 'navigation', nullable: true}, + url: 'url' + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + PrintParameters = Serialization::Record.define( + context: 'context', + background: 'background', + margin: {json_key: 'margin', ref: 'BrowsingContext::PrintMarginParameters'}, + orientation: {json_key: 'orientation', enum: 'BrowsingContext::PRINT_PARAMETERS_ORIENTATION'}, + page: {json_key: 'page', ref: 'BrowsingContext::PrintPageParameters'}, + page_ranges: {json_key: 'pageRanges', list: true}, + scale: 'scale', + shrink_to_fit: 'shrinkToFit' + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + PrintMarginParameters = Serialization::Record.define( + bottom: 'bottom', + left: 'left', + right: 'right', + top: 'top' + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + PrintPageParameters = Serialization::Record.define(height: 'height', width: 'width') + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + PrintResult = Serialization::Record.define(data: 'data') + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + ReloadParameters = Serialization::Record.define( + context: 'context', + ignore_cache: 'ignoreCache', + wait: {json_key: 'wait', enum: 'BrowsingContext::READINESS_STATE'} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + SetBypassCSPParameters = Serialization::Record.define( + bypass: {json_key: 'bypass', nullable: true}, + contexts: {json_key: 'contexts', list: true}, + user_contexts: {json_key: 'userContexts', list: true} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + SetViewportParameters = Serialization::Record.define( + context: 'context', + viewport: {json_key: 'viewport', nullable: true, ref: 'BrowsingContext::Viewport'}, + device_pixel_ratio: {json_key: 'devicePixelRatio', nullable: true}, + user_contexts: {json_key: 'userContexts', list: true} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + Viewport = Serialization::Record.define(width: 'width', height: 'height') + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + TraverseHistoryParameters = Serialization::Record.define(context: 'context', delta: 'delta') + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + HistoryUpdatedParameters = Serialization::Record.define( + context: 'context', + timestamp: 'timestamp', + url: 'url', + user_context: 'userContext' + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + DownloadWillBeginParams = Serialization::Record.define( + suggested_filename: 'suggestedFilename', + context: 'context', + navigation: {json_key: 'navigation', nullable: true}, + timestamp: 'timestamp', + url: 'url', + user_context: 'userContext' + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + class DownloadEndParams < Serialization::Union + discriminator 'status', {canceled: 'canceled', complete: 'complete'} + variants( + canceled: 'BrowsingContext::DownloadEndParams::CanceledParams', + complete: 'BrowsingContext::DownloadEndParams::CompleteParams' + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + CanceledParams = Serialization::Record.define( + status: {fixed: 'canceled'}, + context: 'context', + navigation: {json_key: 'navigation', nullable: true}, + timestamp: 'timestamp', + url: 'url', + user_context: 'userContext' + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + CompleteParams = Serialization::Record.define( + status: {fixed: 'complete'}, + filepath: {json_key: 'filepath', nullable: true}, + context: 'context', + navigation: {json_key: 'navigation', nullable: true}, + timestamp: 'timestamp', + url: 'url', + user_context: 'userContext' + ) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + UserPromptClosedParameters = Serialization::Record.define( + context: 'context', + accepted: 'accepted', + type: {json_key: 'type', enum: 'BrowsingContext::USER_PROMPT_TYPE'}, + user_context: 'userContext', + user_text: 'userText' + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + UserPromptOpenedParameters = Serialization::Record.define( + context: 'context', + handler: {json_key: 'handler', enum: 'Session::USER_PROMPT_HANDLER_TYPE'}, + message: 'message', + type: {json_key: 'type', enum: 'BrowsingContext::USER_PROMPT_TYPE'}, + user_context: 'userContext', + default_value: 'defaultValue' + ) + + EVENT_TYPES = { + 'browsingContext.contextCreated' => BrowsingContext::Info, + 'browsingContext.contextDestroyed' => BrowsingContext::Info, + 'browsingContext.domContentLoaded' => BrowsingContext::NavigationInfo, + 'browsingContext.downloadEnd' => BrowsingContext::DownloadEndParams, + 'browsingContext.downloadWillBegin' => BrowsingContext::DownloadWillBeginParams, + 'browsingContext.fragmentNavigated' => BrowsingContext::NavigationInfo, + 'browsingContext.historyUpdated' => BrowsingContext::HistoryUpdatedParameters, + 'browsingContext.load' => BrowsingContext::NavigationInfo, + 'browsingContext.navigationAborted' => BrowsingContext::NavigationInfo, + 'browsingContext.navigationCommitted' => BrowsingContext::NavigationInfo, + 'browsingContext.navigationFailed' => BrowsingContext::NavigationInfo, + 'browsingContext.navigationStarted' => BrowsingContext::NavigationInfo, + 'browsingContext.userPromptClosed' => BrowsingContext::UserPromptClosedParameters, + 'browsingContext.userPromptOpened' => BrowsingContext::UserPromptOpenedParameters + }.freeze + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def activate(context:) + params = ActivateParameters.new(context: context) + execute(cmd: 'browsingContext.activate', params: params) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def capture_screenshot( + context:, + origin: Serialization::UNSET, + format: Serialization::UNSET, + clip: Serialization::UNSET + ) + Serialization.validate!('origin', origin, BrowsingContext::CAPTURE_SCREENSHOT_PARAMETERS_ORIGIN) + params = CaptureScreenshotParameters.new(context: context, origin: origin, format: format, clip: clip) + execute( + cmd: 'browsingContext.captureScreenshot', + params: params, + result: BrowsingContext::CaptureScreenshotResult + ) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def close(context:, prompt_unload: Serialization::UNSET) + params = CloseParameters.new(context: context, prompt_unload: prompt_unload) + execute(cmd: 'browsingContext.close', params: params) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def create( + type:, + reference_context: Serialization::UNSET, + background: Serialization::UNSET, + user_context: Serialization::UNSET + ) + Serialization.validate!('type', type, BrowsingContext::CREATE_TYPE) + params = CreateParameters.new( + type: type, + reference_context: reference_context, + background: background, + user_context: user_context + ) + execute(cmd: 'browsingContext.create', params: params, result: BrowsingContext::CreateResult) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def get_tree(max_depth: Serialization::UNSET, root: Serialization::UNSET) + params = GetTreeParameters.new(max_depth: max_depth, root: root) + execute(cmd: 'browsingContext.getTree', params: params, result: BrowsingContext::GetTreeResult) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def handle_user_prompt(context:, accept: Serialization::UNSET, user_text: Serialization::UNSET) + params = HandleUserPromptParameters.new(context: context, accept: accept, user_text: user_text) + execute(cmd: 'browsingContext.handleUserPrompt', params: params) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def locate_nodes( + context:, + locator:, + max_node_count: Serialization::UNSET, + serialization_options: Serialization::UNSET, + start_nodes: Serialization::UNSET + ) + params = LocateNodesParameters.new( + context: context, + locator: locator, + max_node_count: max_node_count, + serialization_options: serialization_options, + start_nodes: start_nodes + ) + execute(cmd: 'browsingContext.locateNodes', params: params, result: BrowsingContext::LocateNodesResult) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def navigate(context:, url:, wait: Serialization::UNSET) + Serialization.validate!('wait', wait, BrowsingContext::READINESS_STATE) + params = NavigateParameters.new(context: context, url: url, wait: wait) + execute(cmd: 'browsingContext.navigate', params: params, result: BrowsingContext::NavigateResult) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def print( + context:, + background: Serialization::UNSET, + margin: Serialization::UNSET, + orientation: Serialization::UNSET, + page: Serialization::UNSET, + page_ranges: Serialization::UNSET, + scale: Serialization::UNSET, + shrink_to_fit: Serialization::UNSET + ) + Serialization.validate!('orientation', orientation, BrowsingContext::PRINT_PARAMETERS_ORIENTATION) + params = PrintParameters.new( + context: context, + background: background, + margin: margin, + orientation: orientation, + page: page, + page_ranges: page_ranges, + scale: scale, + shrink_to_fit: shrink_to_fit + ) + execute(cmd: 'browsingContext.print', params: params, result: BrowsingContext::PrintResult) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def reload(context:, ignore_cache: Serialization::UNSET, wait: Serialization::UNSET) + Serialization.validate!('wait', wait, BrowsingContext::READINESS_STATE) + params = ReloadParameters.new(context: context, ignore_cache: ignore_cache, wait: wait) + execute(cmd: 'browsingContext.reload', params: params, result: BrowsingContext::NavigateResult) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def set_bypass_csp(bypass:, contexts: Serialization::UNSET, user_contexts: Serialization::UNSET) + params = SetBypassCSPParameters.new(bypass: bypass, contexts: contexts, user_contexts: user_contexts) + execute(cmd: 'browsingContext.setBypassCSP', params: params) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def set_viewport( + context: Serialization::UNSET, + viewport: Serialization::UNSET, + device_pixel_ratio: Serialization::UNSET, + user_contexts: Serialization::UNSET + ) + params = SetViewportParameters.new( + context: context, + viewport: viewport, + device_pixel_ratio: device_pixel_ratio, + user_contexts: user_contexts + ) + execute(cmd: 'browsingContext.setViewport', params: params) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def traverse_history(context:, delta:) + params = TraverseHistoryParameters.new(context: context, delta: delta) + execute(cmd: 'browsingContext.traverseHistory', params: params) + end + end # BrowsingContext + end # Protocol + end # BiDi + end # WebDriver +end # Selenium diff --git a/rb/lib/selenium/webdriver/bidi/protocol/domain.rb b/rb/lib/selenium/webdriver/bidi/protocol/domain.rb new file mode 100644 index 0000000000000..15ebd344daeb2 --- /dev/null +++ b/rb/lib/selenium/webdriver/bidi/protocol/domain.rb @@ -0,0 +1,40 @@ +# 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 + module Protocol + # @api private + class Domain + def initialize(source) + @transport = source.is_a?(Driver) ? source.send(:bridge).transport : source + raise(Error::WebDriverError, 'a Driver or Transport is required') unless @transport.is_a?(Transport) + end + + private + + def execute(cmd:, params: nil, result: nil) + @transport.execute(cmd: cmd, params: params, result: result) + end + end + end + end + end +end diff --git a/rb/lib/selenium/webdriver/bidi/protocol/emulation.rb b/rb/lib/selenium/webdriver/bidi/protocol/emulation.rb new file mode 100644 index 0000000000000..c8a9e116a4490 --- /dev/null +++ b/rb/lib/selenium/webdriver/bidi/protocol/emulation.rb @@ -0,0 +1,330 @@ +# 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. + +# This file is automatically generated. DO NOT EDIT! +# Regenerate with: bazel run //rb/lib/selenium/webdriver:bidi-generate + +module Selenium + module WebDriver + class BiDi + module Protocol + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + class Emulation < Domain + FORCED_COLORS_MODE_THEME = { + light: 'light', + dark: 'dark' + }.freeze + + SCREEN_ORIENTATION_NATURAL = { + portrait: 'portrait', + landscape: 'landscape' + }.freeze + + SCREEN_ORIENTATION_TYPE = { + portrait_primary: 'portrait-primary', + portrait_secondary: 'portrait-secondary', + landscape_primary: 'landscape-primary', + landscape_secondary: 'landscape-secondary' + }.freeze + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + SetForcedColorsModeThemeOverrideParameters = Serialization::Record.define( + theme: {json_key: 'theme', nullable: true, enum: 'Emulation::FORCED_COLORS_MODE_THEME'}, + contexts: {json_key: 'contexts', list: true}, + user_contexts: {json_key: 'userContexts', list: true} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + class SetGeolocationOverrideParameters < Serialization::Union + presence( + 'Emulation::SetGeolocationOverrideParameters::Coordinates' => ['coordinates'], + 'Emulation::SetGeolocationOverrideParameters::Error' => ['error'] + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + Coordinates = Serialization::Record.define( + contexts: {json_key: 'contexts', list: true}, + user_contexts: {json_key: 'userContexts', list: true}, + coordinates: {json_key: 'coordinates', nullable: true, ref: 'Emulation::GeolocationCoordinates'} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + Error = Serialization::Record.define( + contexts: {json_key: 'contexts', list: true}, + user_contexts: {json_key: 'userContexts', list: true}, + error: {json_key: 'error', ref: 'Emulation::GeolocationPositionError'} + ) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + GeolocationCoordinates = Serialization::Record.define( + latitude: 'latitude', + longitude: 'longitude', + accuracy: 'accuracy', + altitude: {json_key: 'altitude', nullable: true}, + altitude_accuracy: {json_key: 'altitudeAccuracy', nullable: true}, + heading: {json_key: 'heading', nullable: true}, + speed: {json_key: 'speed', nullable: true} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + GeolocationPositionError = Serialization::Record.define(type: {fixed: 'positionUnavailable'}) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + SetLocaleOverrideParameters = Serialization::Record.define( + locale: {json_key: 'locale', nullable: true}, + contexts: {json_key: 'contexts', list: true}, + user_contexts: {json_key: 'userContexts', list: true} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + SetNetworkConditionsParameters = Serialization::Record.define( + network_conditions: {json_key: 'networkConditions', nullable: true, ref: 'Emulation::NetworkConditionsOffline'}, + contexts: {json_key: 'contexts', list: true}, + user_contexts: {json_key: 'userContexts', list: true} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + NetworkConditionsOffline = Serialization::Record.define(type: {fixed: 'offline'}) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + ScreenArea = Serialization::Record.define(width: 'width', height: 'height') + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + SetScreenSettingsOverrideParameters = Serialization::Record.define( + screen_area: {json_key: 'screenArea', nullable: true, ref: 'Emulation::ScreenArea'}, + contexts: {json_key: 'contexts', list: true}, + user_contexts: {json_key: 'userContexts', list: true} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + ScreenOrientation = Serialization::Record.define( + natural: {json_key: 'natural', enum: 'Emulation::SCREEN_ORIENTATION_NATURAL'}, + type: {json_key: 'type', enum: 'Emulation::SCREEN_ORIENTATION_TYPE'} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + SetScreenOrientationOverrideParameters = Serialization::Record.define( + screen_orientation: {json_key: 'screenOrientation', nullable: true, ref: 'Emulation::ScreenOrientation'}, + contexts: {json_key: 'contexts', list: true}, + user_contexts: {json_key: 'userContexts', list: true} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + SetUserAgentOverrideParameters = Serialization::Record.define( + user_agent: {json_key: 'userAgent', nullable: true}, + contexts: {json_key: 'contexts', list: true}, + user_contexts: {json_key: 'userContexts', list: true} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + SetScriptingEnabledParameters = Serialization::Record.define( + enabled: {json_key: 'enabled', nullable: true}, + contexts: {json_key: 'contexts', list: true}, + user_contexts: {json_key: 'userContexts', list: true} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + SetScrollbarTypeOverrideParameters = Serialization::Record.define( + scrollbar_type: {json_key: 'scrollbarType', nullable: true}, + contexts: {json_key: 'contexts', list: true}, + user_contexts: {json_key: 'userContexts', list: true} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + SetTimezoneOverrideParameters = Serialization::Record.define( + timezone: {json_key: 'timezone', nullable: true}, + contexts: {json_key: 'contexts', list: true}, + user_contexts: {json_key: 'userContexts', list: true} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + SetTouchOverrideParameters = Serialization::Record.define( + max_touch_points: {json_key: 'maxTouchPoints', nullable: true}, + contexts: {json_key: 'contexts', list: true}, + user_contexts: {json_key: 'userContexts', list: true} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def set_forced_colors_mode_theme_override( + theme:, + contexts: Serialization::UNSET, + user_contexts: Serialization::UNSET + ) + Serialization.validate!('theme', theme, Emulation::FORCED_COLORS_MODE_THEME) + params = SetForcedColorsModeThemeOverrideParameters.new( + theme: theme, + contexts: contexts, + user_contexts: user_contexts + ) + execute(cmd: 'emulation.setForcedColorsModeThemeOverride', params: params) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def set_geolocation_override( + contexts: Serialization::UNSET, + user_contexts: Serialization::UNSET, + coordinates: Serialization::UNSET, + error: Serialization::UNSET + ) + params = SetGeolocationOverrideParameters.build( + contexts: contexts, + user_contexts: user_contexts, + coordinates: coordinates, + error: error + ) + execute(cmd: 'emulation.setGeolocationOverride', params: params) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def set_locale_override(locale:, contexts: Serialization::UNSET, user_contexts: Serialization::UNSET) + params = SetLocaleOverrideParameters.new(locale: locale, contexts: contexts, user_contexts: user_contexts) + execute(cmd: 'emulation.setLocaleOverride', params: params) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def set_network_conditions( + network_conditions:, + contexts: Serialization::UNSET, + user_contexts: Serialization::UNSET + ) + params = SetNetworkConditionsParameters.new( + network_conditions: network_conditions, + contexts: contexts, + user_contexts: user_contexts + ) + execute(cmd: 'emulation.setNetworkConditions', params: params) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def set_screen_orientation_override( + screen_orientation:, + contexts: Serialization::UNSET, + user_contexts: Serialization::UNSET + ) + params = SetScreenOrientationOverrideParameters.new( + screen_orientation: screen_orientation, + contexts: contexts, + user_contexts: user_contexts + ) + execute(cmd: 'emulation.setScreenOrientationOverride', params: params) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def set_screen_settings_override( + screen_area:, + contexts: Serialization::UNSET, + user_contexts: Serialization::UNSET + ) + params = SetScreenSettingsOverrideParameters.new( + screen_area: screen_area, + contexts: contexts, + user_contexts: user_contexts + ) + execute(cmd: 'emulation.setScreenSettingsOverride', params: params) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def set_scripting_enabled(enabled:, contexts: Serialization::UNSET, user_contexts: Serialization::UNSET) + params = SetScriptingEnabledParameters.new( + enabled: enabled, + contexts: contexts, + user_contexts: user_contexts + ) + execute(cmd: 'emulation.setScriptingEnabled', params: params) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def set_scrollbar_type_override( + scrollbar_type:, + contexts: Serialization::UNSET, + user_contexts: Serialization::UNSET + ) + params = SetScrollbarTypeOverrideParameters.new( + scrollbar_type: scrollbar_type, + contexts: contexts, + user_contexts: user_contexts + ) + execute(cmd: 'emulation.setScrollbarTypeOverride', params: params) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def set_timezone_override(timezone:, contexts: Serialization::UNSET, user_contexts: Serialization::UNSET) + params = SetTimezoneOverrideParameters.new( + timezone: timezone, + contexts: contexts, + user_contexts: user_contexts + ) + execute(cmd: 'emulation.setTimezoneOverride', params: params) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def set_touch_override(max_touch_points:, contexts: Serialization::UNSET, user_contexts: Serialization::UNSET) + params = SetTouchOverrideParameters.new( + max_touch_points: max_touch_points, + contexts: contexts, + user_contexts: user_contexts + ) + execute(cmd: 'emulation.setTouchOverride', params: params) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def set_user_agent_override(user_agent:, contexts: Serialization::UNSET, user_contexts: Serialization::UNSET) + params = SetUserAgentOverrideParameters.new( + user_agent: user_agent, + contexts: contexts, + user_contexts: user_contexts + ) + execute(cmd: 'emulation.setUserAgentOverride', params: params) + end + end # Emulation + end # Protocol + end # BiDi + end # WebDriver +end # Selenium diff --git a/rb/lib/selenium/webdriver/bidi/protocol/input.rb b/rb/lib/selenium/webdriver/bidi/protocol/input.rb new file mode 100644 index 0000000000000..ce5aab7aeb9e1 --- /dev/null +++ b/rb/lib/selenium/webdriver/bidi/protocol/input.rb @@ -0,0 +1,272 @@ +# 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. + +# This file is automatically generated. DO NOT EDIT! +# Regenerate with: bazel run //rb/lib/selenium/webdriver:bidi-generate + +module Selenium + module WebDriver + class BiDi + module Protocol + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + class Input < Domain + EVENTS = { + file_dialog_opened: 'input.fileDialogOpened' + }.freeze + + POINTER_TYPE = { + mouse: 'mouse', + pen: 'pen', + touch: 'touch' + }.freeze + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + ElementOrigin = Serialization::Record.define( + type: {fixed: 'element'}, + element: {json_key: 'element', ref: 'Script::SharedReference'} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + PerformActionsParameters = Serialization::Record.define( + context: 'context', + actions: {json_key: 'actions', ref: 'Input::SourceActions', list: true} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + class SourceActions < Serialization::Union + discriminator 'type', {none: 'none', key: 'key', pointer: 'pointer', wheel: 'wheel'} + variants( + none: 'Input::NoneSourceActions', + key: 'Input::KeySourceActions', + pointer: 'Input::PointerSourceActions', + wheel: 'Input::WheelSourceActions' + ) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + NoneSourceActions = Serialization::Record.define( + type: {fixed: 'none'}, + id: 'id', + actions: {json_key: 'actions', ref: 'Input::PauseAction', list: true} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + KeySourceActions = Serialization::Record.define( + type: {fixed: 'key'}, + id: 'id', + actions: {json_key: 'actions', ref: 'Input::KeySourceAction', list: true} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + class KeySourceAction < Serialization::Union + discriminator 'type', {pause: 'pause', key_down: 'keyDown', key_up: 'keyUp'} + variants( + pause: 'Input::PauseAction', + key_down: 'Input::KeyDownAction', + key_up: 'Input::KeyUpAction' + ) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + PointerSourceActions = Serialization::Record.define( + type: {fixed: 'pointer'}, + id: 'id', + parameters: {json_key: 'parameters', ref: 'Input::PointerParameters'}, + actions: {json_key: 'actions', ref: 'Input::PointerSourceAction', list: true} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + PointerParameters = Serialization::Record.define( + pointer_type: {json_key: 'pointerType', enum: 'Input::POINTER_TYPE'} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + class PointerSourceAction < Serialization::Union + discriminator 'type', { + pause: 'pause', + pointer_down: 'pointerDown', + pointer_up: 'pointerUp', + pointer_move: 'pointerMove' + } + variants( + pause: 'Input::PauseAction', + pointer_down: 'Input::PointerDownAction', + pointer_up: 'Input::PointerUpAction', + pointer_move: 'Input::PointerMoveAction' + ) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + WheelSourceActions = Serialization::Record.define( + type: {fixed: 'wheel'}, + id: 'id', + actions: {json_key: 'actions', ref: 'Input::WheelSourceAction', list: true} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + class WheelSourceAction < Serialization::Union + discriminator 'type', {pause: 'pause', scroll: 'scroll'} + variants( + pause: 'Input::PauseAction', + scroll: 'Input::WheelScrollAction' + ) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + PauseAction = Serialization::Record.define(type: {fixed: 'pause'}, duration: 'duration') + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + KeyDownAction = Serialization::Record.define(type: {fixed: 'keyDown'}, value: 'value') + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + KeyUpAction = Serialization::Record.define(type: {fixed: 'keyUp'}, value: 'value') + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + PointerUpAction = Serialization::Record.define(type: {fixed: 'pointerUp'}, button: 'button') + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + PointerDownAction = Serialization::Record.define( + type: {fixed: 'pointerDown'}, + button: 'button', + width: 'width', + height: 'height', + pressure: 'pressure', + tangential_pressure: 'tangentialPressure', + twist: 'twist', + altitude_angle: 'altitudeAngle', + azimuth_angle: 'azimuthAngle' + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + PointerMoveAction = Serialization::Record.define( + type: {fixed: 'pointerMove'}, + x: 'x', + y: 'y', + duration: 'duration', + origin: {json_key: 'origin', ref: 'Input::Origin'}, + width: 'width', + height: 'height', + pressure: 'pressure', + tangential_pressure: 'tangentialPressure', + twist: 'twist', + altitude_angle: 'altitudeAngle', + azimuth_angle: 'azimuthAngle' + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + WheelScrollAction = Serialization::Record.define( + type: {fixed: 'scroll'}, + x: 'x', + y: 'y', + delta_x: 'deltaX', + delta_y: 'deltaY', + duration: 'duration', + origin: {json_key: 'origin', ref: 'Input::Origin'} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + PointerCommonProperties = Serialization::Record.define( + width: 'width', + height: 'height', + pressure: 'pressure', + tangential_pressure: 'tangentialPressure', + twist: 'twist', + altitude_angle: 'altitudeAngle', + azimuth_angle: 'azimuthAngle' + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + class Origin < Serialization::Union + discriminator 'type', {element: 'element'} + variants( + element: 'Input::ElementOrigin' + ) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + ReleaseActionsParameters = Serialization::Record.define(context: 'context') + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + SetFilesParameters = Serialization::Record.define( + context: 'context', + element: {json_key: 'element', ref: 'Script::SharedReference'}, + files: {json_key: 'files', list: true} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + FileDialogInfo = Serialization::Record.define( + context: 'context', + user_context: 'userContext', + element: {json_key: 'element', ref: 'Script::SharedReference'}, + multiple: 'multiple' + ) + + EVENT_TYPES = { + 'input.fileDialogOpened' => Input::FileDialogInfo + }.freeze + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def perform_actions(context:, actions:) + params = PerformActionsParameters.new(context: context, actions: actions) + execute(cmd: 'input.performActions', params: params) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def release_actions(context:) + params = ReleaseActionsParameters.new(context: context) + execute(cmd: 'input.releaseActions', params: params) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def set_files(context:, element:, files:) + params = SetFilesParameters.new(context: context, element: element, files: files) + execute(cmd: 'input.setFiles', params: params) + end + end # Input + end # Protocol + end # BiDi + end # WebDriver +end # Selenium diff --git a/rb/lib/selenium/webdriver/bidi/protocol/log.rb b/rb/lib/selenium/webdriver/bidi/protocol/log.rb new file mode 100644 index 0000000000000..3000e10a7af49 --- /dev/null +++ b/rb/lib/selenium/webdriver/bidi/protocol/log.rb @@ -0,0 +1,104 @@ +# 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. + +# This file is automatically generated. DO NOT EDIT! +# Regenerate with: bazel run //rb/lib/selenium/webdriver:bidi-generate + +module Selenium + module WebDriver + class BiDi + module Protocol + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + class Log < Domain + EVENTS = { + entry_added: 'log.entryAdded' + }.freeze + + LEVEL = { + debug: 'debug', + info: 'info', + warn: 'warn', + error: 'error' + }.freeze + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + class Entry < Serialization::Union + discriminator 'type', {console: 'console', javascript: 'javascript'} + variants( + console: 'Log::ConsoleLogEntry', + javascript: 'Log::JavascriptLogEntry' + ) + fallback 'Log::GenericLogEntry' + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + BaseLogEntry = Serialization::Record.define( + level: {json_key: 'level', enum: 'Log::LEVEL'}, + source: {json_key: 'source', ref: 'Script::Source'}, + text: {json_key: 'text', nullable: true}, + timestamp: 'timestamp', + stack_trace: {json_key: 'stackTrace', ref: 'Script::StackTrace'} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + GenericLogEntry = Serialization::Record.define( + level: {json_key: 'level', enum: 'Log::LEVEL'}, + source: {json_key: 'source', ref: 'Script::Source'}, + text: {json_key: 'text', nullable: true}, + timestamp: 'timestamp', + stack_trace: {json_key: 'stackTrace', ref: 'Script::StackTrace'}, + type: 'type' + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + ConsoleLogEntry = Serialization::Record.define( + type: {fixed: 'console'}, + level: {json_key: 'level', enum: 'Log::LEVEL'}, + source: {json_key: 'source', ref: 'Script::Source'}, + text: {json_key: 'text', nullable: true}, + timestamp: 'timestamp', + stack_trace: {json_key: 'stackTrace', ref: 'Script::StackTrace'}, + method_: 'method', + args: {json_key: 'args', ref: 'Script::RemoteValue', list: true} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + JavascriptLogEntry = Serialization::Record.define( + type: {fixed: 'javascript'}, + level: {json_key: 'level', enum: 'Log::LEVEL'}, + source: {json_key: 'source', ref: 'Script::Source'}, + text: {json_key: 'text', nullable: true}, + timestamp: 'timestamp', + stack_trace: {json_key: 'stackTrace', ref: 'Script::StackTrace'} + ) + + EVENT_TYPES = { + 'log.entryAdded' => Log::Entry + }.freeze + end # Log + end # Protocol + end # BiDi + end # WebDriver +end # Selenium diff --git a/rb/lib/selenium/webdriver/bidi/protocol/network.rb b/rb/lib/selenium/webdriver/bidi/protocol/network.rb new file mode 100644 index 0000000000000..2f5f75035e99e --- /dev/null +++ b/rb/lib/selenium/webdriver/bidi/protocol/network.rb @@ -0,0 +1,622 @@ +# 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. + +# This file is automatically generated. DO NOT EDIT! +# Regenerate with: bazel run //rb/lib/selenium/webdriver:bidi-generate + +module Selenium + module WebDriver + class BiDi + module Protocol + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + class Network < Domain + EVENTS = { + auth_required: 'network.authRequired', + before_request_sent: 'network.beforeRequestSent', + fetch_error: 'network.fetchError', + response_completed: 'network.responseCompleted', + response_started: 'network.responseStarted' + }.freeze + + COLLECTOR_TYPE = { + blob: 'blob' + }.freeze + + SAME_SITE = { + strict: 'strict', + lax: 'lax', + none: 'none', + default: 'default' + }.freeze + + DATA_TYPE = { + request: 'request', + response: 'response' + }.freeze + + INTERCEPT_PHASE = { + before_request_sent: 'beforeRequestSent', + response_started: 'responseStarted', + auth_required: 'authRequired' + }.freeze + + INITIATOR_TYPE = { + parser: 'parser', + script: 'script', + preflight: 'preflight', + other: 'other' + }.freeze + + CONTINUE_WITH_AUTH_NO_CREDENTIALS_ACTION = { + default: 'default', + cancel: 'cancel' + }.freeze + + SET_CACHE_BEHAVIOR_PARAMETERS_CACHE_BEHAVIOR = { + default: 'default', + bypass: 'bypass' + }.freeze + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + AuthChallenge = Serialization::Record.define(scheme: 'scheme', realm: 'realm') + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + AuthCredentials = Serialization::Record.define( + type: {fixed: 'password'}, + username: 'username', + password: 'password' + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + BaseParameters = Serialization::Record.define( + context: {json_key: 'context', nullable: true}, + is_blocked: 'isBlocked', + navigation: {json_key: 'navigation', nullable: true}, + redirect_count: 'redirectCount', + request: {json_key: 'request', ref: 'Network::RequestData'}, + timestamp: 'timestamp', + user_context: {json_key: 'userContext', nullable: true}, + intercepts: {json_key: 'intercepts', list: true} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + class BytesValue < Serialization::Union + discriminator 'type', {string: 'string', base64: 'base64'} + variants( + string: 'Network::StringValue', + base64: 'Network::Base64Value' + ) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + StringValue = Serialization::Record.define(type: {fixed: 'string'}, value: 'value') + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + Base64Value = Serialization::Record.define(type: {fixed: 'base64'}, value: 'value') + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + Cookie = Serialization::Record.define( + name: 'name', + value: {json_key: 'value', ref: 'Network::BytesValue'}, + domain: 'domain', + path: 'path', + size: 'size', + http_only: 'httpOnly', + secure: 'secure', + same_site: {json_key: 'sameSite', enum: 'Network::SAME_SITE'}, + expiry: 'expiry', + extensible: true + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + CookieHeader = Serialization::Record.define( + name: 'name', + value: {json_key: 'value', ref: 'Network::BytesValue'} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + FetchTimingInfo = Serialization::Record.define( + time_origin: 'timeOrigin', + request_time: 'requestTime', + redirect_start: 'redirectStart', + redirect_end: 'redirectEnd', + fetch_start: 'fetchStart', + dns_start: 'dnsStart', + dns_end: 'dnsEnd', + connect_start: 'connectStart', + connect_end: 'connectEnd', + tls_start: 'tlsStart', + request_start: 'requestStart', + response_start: 'responseStart', + response_end: 'responseEnd' + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + Header = Serialization::Record.define(name: 'name', value: {json_key: 'value', ref: 'Network::BytesValue'}) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + Initiator = Serialization::Record.define( + column_number: 'columnNumber', + line_number: 'lineNumber', + request: 'request', + stack_trace: {json_key: 'stackTrace', ref: 'Script::StackTrace'}, + type: {json_key: 'type', enum: 'Network::INITIATOR_TYPE'} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + RequestData = Serialization::Record.define( + request: 'request', + url: 'url', + method_: 'method', + headers: {json_key: 'headers', ref: 'Network::Header', list: true}, + cookies: {json_key: 'cookies', ref: 'Network::Cookie', list: true}, + headers_size: 'headersSize', + body_size: {json_key: 'bodySize', nullable: true}, + destination: 'destination', + initiator_type: {json_key: 'initiatorType', nullable: true}, + timings: {json_key: 'timings', ref: 'Network::FetchTimingInfo'} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + ResponseContent = Serialization::Record.define(size: 'size') + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + ResponseData = Serialization::Record.define( + url: 'url', + protocol: 'protocol', + status: 'status', + status_text: 'statusText', + from_cache: 'fromCache', + headers: {json_key: 'headers', ref: 'Network::Header', list: true}, + mime_type: 'mimeType', + bytes_received: 'bytesReceived', + headers_size: {json_key: 'headersSize', nullable: true}, + body_size: {json_key: 'bodySize', nullable: true}, + content: {json_key: 'content', ref: 'Network::ResponseContent'}, + auth_challenges: {json_key: 'authChallenges', ref: 'Network::AuthChallenge', list: true} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + SetCookieHeader = Serialization::Record.define( + name: 'name', + value: {json_key: 'value', ref: 'Network::BytesValue'}, + domain: 'domain', + http_only: 'httpOnly', + expiry: 'expiry', + max_age: 'maxAge', + path: 'path', + same_site: {json_key: 'sameSite', enum: 'Network::SAME_SITE'}, + secure: 'secure' + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + class UrlPattern < Serialization::Union + discriminator 'type', {pattern: 'pattern', string: 'string'} + variants( + pattern: 'Network::UrlPatternPattern', + string: 'Network::UrlPatternString' + ) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + UrlPatternPattern = Serialization::Record.define( + type: {fixed: 'pattern'}, + protocol: 'protocol', + hostname: 'hostname', + port: 'port', + pathname: 'pathname', + search: 'search' + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + UrlPatternString = Serialization::Record.define(type: {fixed: 'string'}, pattern: 'pattern') + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + AddDataCollectorParameters = Serialization::Record.define( + data_types: {json_key: 'dataTypes', list: true, enum: 'Network::DATA_TYPE'}, + max_encoded_data_size: 'maxEncodedDataSize', + collector_type: {json_key: 'collectorType', enum: 'Network::COLLECTOR_TYPE'}, + contexts: {json_key: 'contexts', list: true}, + user_contexts: {json_key: 'userContexts', list: true} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + AddDataCollectorResult = Serialization::Record.define(collector: 'collector') + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + AddInterceptParameters = Serialization::Record.define( + phases: {json_key: 'phases', list: true, enum: 'Network::INTERCEPT_PHASE'}, + contexts: {json_key: 'contexts', list: true}, + url_patterns: {json_key: 'urlPatterns', ref: 'Network::UrlPattern', list: true} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + AddInterceptResult = Serialization::Record.define(intercept: 'intercept') + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + ContinueRequestParameters = Serialization::Record.define( + request: 'request', + body: {json_key: 'body', ref: 'Network::BytesValue'}, + cookies: {json_key: 'cookies', ref: 'Network::CookieHeader', list: true}, + headers: {json_key: 'headers', ref: 'Network::Header', list: true}, + method_: 'method', + url: 'url' + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + ContinueResponseParameters = Serialization::Record.define( + request: 'request', + cookies: {json_key: 'cookies', ref: 'Network::SetCookieHeader', list: true}, + credentials: {json_key: 'credentials', ref: 'Network::AuthCredentials'}, + headers: {json_key: 'headers', ref: 'Network::Header', list: true}, + reason_phrase: 'reasonPhrase', + status_code: 'statusCode' + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + class ContinueWithAuthParameters < Serialization::Union + discriminator 'action', {provide_credentials: 'provideCredentials'} + variants( + provide_credentials: 'Network::ContinueWithAuthParameters::Credentials' + ) + fallback 'Network::ContinueWithAuthParameters::NoCredentials' + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + Credentials = Serialization::Record.define( + action: {fixed: 'provideCredentials'}, + request: 'request', + credentials: {json_key: 'credentials', ref: 'Network::AuthCredentials'} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + NoCredentials = Serialization::Record.define( + request: 'request', + action: {json_key: 'action', enum: 'Network::CONTINUE_WITH_AUTH_NO_CREDENTIALS_ACTION'} + ) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + DisownDataParameters = Serialization::Record.define( + data_type: {json_key: 'dataType', enum: 'Network::DATA_TYPE'}, + collector: 'collector', + request: 'request' + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + FailRequestParameters = Serialization::Record.define(request: 'request') + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + GetDataParameters = Serialization::Record.define( + data_type: {json_key: 'dataType', enum: 'Network::DATA_TYPE'}, + collector: 'collector', + disown: 'disown', + request: 'request' + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + GetDataResult = Serialization::Record.define(bytes: {json_key: 'bytes', ref: 'Network::BytesValue'}) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + ProvideResponseParameters = Serialization::Record.define( + request: 'request', + body: {json_key: 'body', ref: 'Network::BytesValue'}, + cookies: {json_key: 'cookies', ref: 'Network::SetCookieHeader', list: true}, + headers: {json_key: 'headers', ref: 'Network::Header', list: true}, + reason_phrase: 'reasonPhrase', + status_code: 'statusCode' + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + RemoveDataCollectorParameters = Serialization::Record.define(collector: 'collector') + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + RemoveInterceptParameters = Serialization::Record.define(intercept: 'intercept') + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + SetCacheBehaviorParameters = Serialization::Record.define( + cache_behavior: {json_key: 'cacheBehavior', enum: 'Network::SET_CACHE_BEHAVIOR_PARAMETERS_CACHE_BEHAVIOR'}, + contexts: {json_key: 'contexts', list: true} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + SetExtraHeadersParameters = Serialization::Record.define( + headers: {json_key: 'headers', ref: 'Network::Header', list: true}, + contexts: {json_key: 'contexts', list: true}, + user_contexts: {json_key: 'userContexts', list: true} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + AuthRequiredParameters = Serialization::Record.define( + context: {json_key: 'context', nullable: true}, + is_blocked: 'isBlocked', + navigation: {json_key: 'navigation', nullable: true}, + redirect_count: 'redirectCount', + request: {json_key: 'request', ref: 'Network::RequestData'}, + timestamp: 'timestamp', + user_context: {json_key: 'userContext', nullable: true}, + intercepts: {json_key: 'intercepts', list: true}, + response: {json_key: 'response', ref: 'Network::ResponseData'} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + BeforeRequestSentParameters = Serialization::Record.define( + context: {json_key: 'context', nullable: true}, + is_blocked: 'isBlocked', + navigation: {json_key: 'navigation', nullable: true}, + redirect_count: 'redirectCount', + request: {json_key: 'request', ref: 'Network::RequestData'}, + timestamp: 'timestamp', + user_context: {json_key: 'userContext', nullable: true}, + intercepts: {json_key: 'intercepts', list: true}, + initiator: {json_key: 'initiator', ref: 'Network::Initiator'} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + FetchErrorParameters = Serialization::Record.define( + context: {json_key: 'context', nullable: true}, + is_blocked: 'isBlocked', + navigation: {json_key: 'navigation', nullable: true}, + redirect_count: 'redirectCount', + request: {json_key: 'request', ref: 'Network::RequestData'}, + timestamp: 'timestamp', + user_context: {json_key: 'userContext', nullable: true}, + intercepts: {json_key: 'intercepts', list: true}, + error_text: 'errorText' + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + ResponseCompletedParameters = Serialization::Record.define( + context: {json_key: 'context', nullable: true}, + is_blocked: 'isBlocked', + navigation: {json_key: 'navigation', nullable: true}, + redirect_count: 'redirectCount', + request: {json_key: 'request', ref: 'Network::RequestData'}, + timestamp: 'timestamp', + user_context: {json_key: 'userContext', nullable: true}, + intercepts: {json_key: 'intercepts', list: true}, + response: {json_key: 'response', ref: 'Network::ResponseData'} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + ResponseStartedParameters = Serialization::Record.define( + context: {json_key: 'context', nullable: true}, + is_blocked: 'isBlocked', + navigation: {json_key: 'navigation', nullable: true}, + redirect_count: 'redirectCount', + request: {json_key: 'request', ref: 'Network::RequestData'}, + timestamp: 'timestamp', + user_context: {json_key: 'userContext', nullable: true}, + intercepts: {json_key: 'intercepts', list: true}, + response: {json_key: 'response', ref: 'Network::ResponseData'} + ) + + EVENT_TYPES = { + 'network.authRequired' => Network::AuthRequiredParameters, + 'network.beforeRequestSent' => Network::BeforeRequestSentParameters, + 'network.fetchError' => Network::FetchErrorParameters, + 'network.responseCompleted' => Network::ResponseCompletedParameters, + 'network.responseStarted' => Network::ResponseStartedParameters + }.freeze + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def add_data_collector( + data_types:, + max_encoded_data_size:, + collector_type: Serialization::UNSET, + contexts: Serialization::UNSET, + user_contexts: Serialization::UNSET + ) + Serialization.validate!('dataTypes', data_types, Network::DATA_TYPE) + Serialization.validate!('collectorType', collector_type, Network::COLLECTOR_TYPE) + params = AddDataCollectorParameters.new( + data_types: data_types, + max_encoded_data_size: max_encoded_data_size, + collector_type: collector_type, + contexts: contexts, + user_contexts: user_contexts + ) + execute(cmd: 'network.addDataCollector', params: params, result: Network::AddDataCollectorResult) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def add_intercept(phases:, contexts: Serialization::UNSET, url_patterns: Serialization::UNSET) + Serialization.validate!('phases', phases, Network::INTERCEPT_PHASE) + params = AddInterceptParameters.new(phases: phases, contexts: contexts, url_patterns: url_patterns) + execute(cmd: 'network.addIntercept', params: params, result: Network::AddInterceptResult) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def continue_request( + request:, + body: Serialization::UNSET, + cookies: Serialization::UNSET, + headers: Serialization::UNSET, + method_: Serialization::UNSET, + url: Serialization::UNSET + ) + params = ContinueRequestParameters.new( + request: request, + body: body, + cookies: cookies, + headers: headers, + method_: method_, + url: url + ) + execute(cmd: 'network.continueRequest', params: params) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def continue_response( + request:, + cookies: Serialization::UNSET, + credentials: Serialization::UNSET, + headers: Serialization::UNSET, + reason_phrase: Serialization::UNSET, + status_code: Serialization::UNSET + ) + params = ContinueResponseParameters.new( + request: request, + cookies: cookies, + credentials: credentials, + headers: headers, + reason_phrase: reason_phrase, + status_code: status_code + ) + execute(cmd: 'network.continueResponse', params: params) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def continue_with_auth(request:, action:, credentials: Serialization::UNSET) + Serialization.validate!( + 'action', + action, + {provide_credentials: 'provideCredentials', default: 'default', cancel: 'cancel'} + ) + params = ContinueWithAuthParameters.build(request: request, action: action, credentials: credentials) + execute(cmd: 'network.continueWithAuth', params: params) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def disown_data(data_type:, collector:, request:) + Serialization.validate!('dataType', data_type, Network::DATA_TYPE) + params = DisownDataParameters.new(data_type: data_type, collector: collector, request: request) + execute(cmd: 'network.disownData', params: params) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def fail_request(request:) + params = FailRequestParameters.new(request: request) + execute(cmd: 'network.failRequest', params: params) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def get_data(data_type:, request:, collector: Serialization::UNSET, disown: Serialization::UNSET) + Serialization.validate!('dataType', data_type, Network::DATA_TYPE) + params = GetDataParameters.new(data_type: data_type, collector: collector, disown: disown, request: request) + execute(cmd: 'network.getData', params: params, result: Network::GetDataResult) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def provide_response( + request:, + body: Serialization::UNSET, + cookies: Serialization::UNSET, + headers: Serialization::UNSET, + reason_phrase: Serialization::UNSET, + status_code: Serialization::UNSET + ) + params = ProvideResponseParameters.new( + request: request, + body: body, + cookies: cookies, + headers: headers, + reason_phrase: reason_phrase, + status_code: status_code + ) + execute(cmd: 'network.provideResponse', params: params) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def remove_data_collector(collector:) + params = RemoveDataCollectorParameters.new(collector: collector) + execute(cmd: 'network.removeDataCollector', params: params) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def remove_intercept(intercept:) + params = RemoveInterceptParameters.new(intercept: intercept) + execute(cmd: 'network.removeIntercept', params: params) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def set_cache_behavior(cache_behavior:, contexts: Serialization::UNSET) + Serialization.validate!( + 'cacheBehavior', + cache_behavior, + Network::SET_CACHE_BEHAVIOR_PARAMETERS_CACHE_BEHAVIOR + ) + params = SetCacheBehaviorParameters.new(cache_behavior: cache_behavior, contexts: contexts) + execute(cmd: 'network.setCacheBehavior', params: params) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def set_extra_headers(headers:, contexts: Serialization::UNSET, user_contexts: Serialization::UNSET) + params = SetExtraHeadersParameters.new(headers: headers, contexts: contexts, user_contexts: user_contexts) + execute(cmd: 'network.setExtraHeaders', params: params) + end + end # Network + end # Protocol + end # BiDi + end # WebDriver +end # Selenium diff --git a/rb/lib/selenium/webdriver/bidi/protocol/permissions.rb b/rb/lib/selenium/webdriver/bidi/protocol/permissions.rb new file mode 100644 index 0000000000000..ff00100fc2d74 --- /dev/null +++ b/rb/lib/selenium/webdriver/bidi/protocol/permissions.rb @@ -0,0 +1,73 @@ +# 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. + +# This file is automatically generated. DO NOT EDIT! +# Regenerate with: bazel run //rb/lib/selenium/webdriver:bidi-generate + +module Selenium + module WebDriver + class BiDi + module Protocol + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + class Permissions < Domain + PERMISSION_STATE = { + granted: 'granted', + denied: 'denied', + prompt: 'prompt' + }.freeze + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + PermissionDescriptor = Serialization::Record.define(name: 'name') + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + SetPermissionParameters = Serialization::Record.define( + descriptor: {json_key: 'descriptor', ref: 'Permissions::PermissionDescriptor'}, + state: {json_key: 'state', enum: 'Permissions::PERMISSION_STATE'}, + origin: 'origin', + embedded_origin: 'embeddedOrigin', + user_context: 'userContext' + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def set_permission( + descriptor:, + state:, + origin:, + embedded_origin: Serialization::UNSET, + user_context: Serialization::UNSET + ) + Serialization.validate!('state', state, Permissions::PERMISSION_STATE) + params = SetPermissionParameters.new( + descriptor: descriptor, + state: state, + origin: origin, + embedded_origin: embedded_origin, + user_context: user_context + ) + execute(cmd: 'permissions.setPermission', params: params) + end + end # Permissions + end # Protocol + end # BiDi + end # WebDriver +end # Selenium diff --git a/rb/lib/selenium/webdriver/bidi/protocol/script.rb b/rb/lib/selenium/webdriver/bidi/protocol/script.rb new file mode 100644 index 0000000000000..95ec4ce900d32 --- /dev/null +++ b/rb/lib/selenium/webdriver/bidi/protocol/script.rb @@ -0,0 +1,821 @@ +# 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. + +# This file is automatically generated. DO NOT EDIT! +# Regenerate with: bazel run //rb/lib/selenium/webdriver:bidi-generate + +module Selenium + module WebDriver + class BiDi + module Protocol + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + class Script < Domain + EVENTS = { + message: 'script.message', + realm_created: 'script.realmCreated', + realm_destroyed: 'script.realmDestroyed' + }.freeze + + SPECIAL_NUMBER = { + na_n: 'NaN', + neg0: '-0', + infinity: 'Infinity', + neg_infinity: '-Infinity' + }.freeze + + REALM_TYPE = { + window: 'window', + dedicated_worker: 'dedicated-worker', + shared_worker: 'shared-worker', + service_worker: 'service-worker', + worker: 'worker', + paint_worklet: 'paint-worklet', + audio_worklet: 'audio-worklet', + worklet: 'worklet' + }.freeze + + RESULT_OWNERSHIP = { + root: 'root', + none: 'none' + }.freeze + + NODE_PROPERTIES_MODE = { + open: 'open', + closed: 'closed' + }.freeze + + SERIALIZATION_OPTIONS_INCLUDE_SHADOW_TREE = { + none: 'none', + open: 'open', + all: 'all' + }.freeze + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + ChannelValue = Serialization::Record.define( + type: {fixed: 'channel'}, + value: {json_key: 'value', ref: 'Script::ChannelProperties'} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + ChannelProperties = Serialization::Record.define( + channel: 'channel', + serialization_options: {json_key: 'serializationOptions', ref: 'Script::SerializationOptions'}, + ownership: {json_key: 'ownership', enum: 'Script::RESULT_OWNERSHIP'} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + class EvaluateResult < Serialization::Union + discriminator 'type', {success: 'success', exception: 'exception'} + variants( + success: 'Script::EvaluateResultSuccess', + exception: 'Script::EvaluateResultException' + ) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + EvaluateResultSuccess = Serialization::Record.define( + type: {fixed: 'success'}, + result: {json_key: 'result', ref: 'Script::RemoteValue'}, + realm: 'realm' + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + EvaluateResultException = Serialization::Record.define( + type: {fixed: 'exception'}, + exception_details: {json_key: 'exceptionDetails', ref: 'Script::ExceptionDetails'}, + realm: 'realm' + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + ExceptionDetails = Serialization::Record.define( + column_number: 'columnNumber', + exception: {json_key: 'exception', ref: 'Script::RemoteValue'}, + line_number: 'lineNumber', + stack_trace: {json_key: 'stackTrace', ref: 'Script::StackTrace'}, + text: 'text' + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + class LocalValue < Serialization::Union + discriminator 'type', { + undefined: 'undefined', + null: 'null', + string: 'string', + number: 'number', + boolean: 'boolean', + bigint: 'bigint', + channel: 'channel', + array: 'array', + date: 'date', + map: 'map', + object: 'object', + regexp: 'regexp', + set: 'set' + } + variants( + undefined: 'Script::UndefinedValue', + null: 'Script::NullValue', + string: 'Script::StringValue', + number: 'Script::NumberValue', + boolean: 'Script::BooleanValue', + bigint: 'Script::BigIntValue', + channel: 'Script::ChannelValue', + array: 'Script::ArrayLocalValue', + date: 'Script::DateLocalValue', + map: 'Script::MapLocalValue', + object: 'Script::ObjectLocalValue', + regexp: 'Script::RegExpLocalValue', + set: 'Script::SetLocalValue' + ) + fallback 'Script::RemoteReference' + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + ArrayLocalValue = Serialization::Record.define( + type: {fixed: 'array'}, + value: {json_key: 'value', ref: 'Script::LocalValue', list: true} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + DateLocalValue = Serialization::Record.define(type: {fixed: 'date'}, value: 'value') + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + MapLocalValue = Serialization::Record.define( + type: {fixed: 'map'}, + value: {json_key: 'value', ref: 'Script::LocalValue', list: true} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + ObjectLocalValue = Serialization::Record.define( + type: {fixed: 'object'}, + value: {json_key: 'value', ref: 'Script::LocalValue', list: true} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + RegExpValue = Serialization::Record.define(pattern: 'pattern', flags: 'flags') + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + RegExpLocalValue = Serialization::Record.define( + type: {fixed: 'regexp'}, + value: {json_key: 'value', ref: 'Script::RegExpValue'} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + SetLocalValue = Serialization::Record.define( + type: {fixed: 'set'}, + value: {json_key: 'value', ref: 'Script::LocalValue', list: true} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + class PrimitiveProtocolValue < Serialization::Union + discriminator 'type', { + undefined: 'undefined', + null: 'null', + string: 'string', + number: 'number', + boolean: 'boolean', + bigint: 'bigint' + } + variants( + undefined: 'Script::UndefinedValue', + null: 'Script::NullValue', + string: 'Script::StringValue', + number: 'Script::NumberValue', + boolean: 'Script::BooleanValue', + bigint: 'Script::BigIntValue' + ) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + UndefinedValue = Serialization::Record.define(type: {fixed: 'undefined'}) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + NullValue = Serialization::Record.define(type: {fixed: 'null'}) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + StringValue = Serialization::Record.define(type: {fixed: 'string'}, value: 'value') + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + NumberValue = Serialization::Record.define(type: {fixed: 'number'}, value: 'value') + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + BooleanValue = Serialization::Record.define(type: {fixed: 'boolean'}, value: 'value') + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + BigIntValue = Serialization::Record.define(type: {fixed: 'bigint'}, value: 'value') + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + class RealmInfo < Serialization::Union + discriminator 'type', { + window: 'window', + dedicated_worker: 'dedicated-worker', + shared_worker: 'shared-worker', + service_worker: 'service-worker', + worker: 'worker', + paint_worklet: 'paint-worklet', + audio_worklet: 'audio-worklet', + worklet: 'worklet' + } + variants( + window: 'Script::WindowRealmInfo', + dedicated_worker: 'Script::DedicatedWorkerRealmInfo', + shared_worker: 'Script::SharedWorkerRealmInfo', + service_worker: 'Script::ServiceWorkerRealmInfo', + worker: 'Script::WorkerRealmInfo', + paint_worklet: 'Script::PaintWorkletRealmInfo', + audio_worklet: 'Script::AudioWorkletRealmInfo', + worklet: 'Script::WorkletRealmInfo' + ) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + BaseRealmInfo = Serialization::Record.define(realm: 'realm', origin: 'origin') + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + WindowRealmInfo = Serialization::Record.define( + type: {fixed: 'window'}, + realm: 'realm', + origin: 'origin', + context: 'context', + user_context: 'userContext', + sandbox: 'sandbox' + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + DedicatedWorkerRealmInfo = Serialization::Record.define( + type: {fixed: 'dedicated-worker'}, + realm: 'realm', + origin: 'origin', + owners: {json_key: 'owners', list: true} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + SharedWorkerRealmInfo = Serialization::Record.define( + type: {fixed: 'shared-worker'}, + realm: 'realm', + origin: 'origin' + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + ServiceWorkerRealmInfo = Serialization::Record.define( + type: {fixed: 'service-worker'}, + realm: 'realm', + origin: 'origin' + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + WorkerRealmInfo = Serialization::Record.define(type: {fixed: 'worker'}, realm: 'realm', origin: 'origin') + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + PaintWorkletRealmInfo = Serialization::Record.define( + type: {fixed: 'paint-worklet'}, + realm: 'realm', + origin: 'origin' + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + AudioWorkletRealmInfo = Serialization::Record.define( + type: {fixed: 'audio-worklet'}, + realm: 'realm', + origin: 'origin' + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + WorkletRealmInfo = Serialization::Record.define(type: {fixed: 'worklet'}, realm: 'realm', origin: 'origin') + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + class RemoteReference < Serialization::Union + presence( + 'Script::SharedReference' => ['sharedId'], + 'Script::RemoteObjectReference' => ['handle'] + ) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + SharedReference = Serialization::Record.define(shared_id: 'sharedId', handle: 'handle', extensible: true) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + RemoteObjectReference = Serialization::Record.define( + handle: 'handle', + shared_id: 'sharedId', + extensible: true + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + class RemoteValue < Serialization::Union + discriminator 'type', { + undefined: 'undefined', + null: 'null', + string: 'string', + number: 'number', + boolean: 'boolean', + bigint: 'bigint', + symbol: 'symbol', + array: 'array', + object: 'object', + function: 'function', + regexp: 'regexp', + date: 'date', + map: 'map', + set: 'set', + weakmap: 'weakmap', + weakset: 'weakset', + generator: 'generator', + error: 'error', + proxy: 'proxy', + promise: 'promise', + typedarray: 'typedarray', + arraybuffer: 'arraybuffer', + nodelist: 'nodelist', + htmlcollection: 'htmlcollection', + node: 'node', + window: 'window' + } + variants( + undefined: 'Script::UndefinedValue', + null: 'Script::NullValue', + string: 'Script::StringValue', + number: 'Script::NumberValue', + boolean: 'Script::BooleanValue', + bigint: 'Script::BigIntValue', + symbol: 'Script::SymbolRemoteValue', + array: 'Script::ArrayRemoteValue', + object: 'Script::ObjectRemoteValue', + function: 'Script::FunctionRemoteValue', + regexp: 'Script::RegExpRemoteValue', + date: 'Script::DateRemoteValue', + map: 'Script::MapRemoteValue', + set: 'Script::SetRemoteValue', + weakmap: 'Script::WeakMapRemoteValue', + weakset: 'Script::WeakSetRemoteValue', + generator: 'Script::GeneratorRemoteValue', + error: 'Script::ErrorRemoteValue', + proxy: 'Script::ProxyRemoteValue', + promise: 'Script::PromiseRemoteValue', + typedarray: 'Script::TypedArrayRemoteValue', + arraybuffer: 'Script::ArrayBufferRemoteValue', + nodelist: 'Script::NodeListRemoteValue', + htmlcollection: 'Script::HTMLCollectionRemoteValue', + node: 'Script::NodeRemoteValue', + window: 'Script::WindowProxyRemoteValue' + ) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + SymbolRemoteValue = Serialization::Record.define( + type: {fixed: 'symbol'}, + handle: 'handle', + internal_id: 'internalId' + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + ArrayRemoteValue = Serialization::Record.define( + type: {fixed: 'array'}, + handle: 'handle', + internal_id: 'internalId', + value: {json_key: 'value', ref: 'Script::RemoteValue', list: true} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + ObjectRemoteValue = Serialization::Record.define( + type: {fixed: 'object'}, + handle: 'handle', + internal_id: 'internalId', + value: {json_key: 'value', ref: 'Script::RemoteValue', list: true} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + FunctionRemoteValue = Serialization::Record.define( + type: {fixed: 'function'}, + handle: 'handle', + internal_id: 'internalId' + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + RegExpRemoteValue = Serialization::Record.define( + type: {fixed: 'regexp'}, + value: {json_key: 'value', ref: 'Script::RegExpValue'}, + handle: 'handle', + internal_id: 'internalId' + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + DateRemoteValue = Serialization::Record.define( + type: {fixed: 'date'}, + value: 'value', + handle: 'handle', + internal_id: 'internalId' + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + MapRemoteValue = Serialization::Record.define( + type: {fixed: 'map'}, + handle: 'handle', + internal_id: 'internalId', + value: {json_key: 'value', ref: 'Script::RemoteValue', list: true} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + SetRemoteValue = Serialization::Record.define( + type: {fixed: 'set'}, + handle: 'handle', + internal_id: 'internalId', + value: {json_key: 'value', ref: 'Script::RemoteValue', list: true} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + WeakMapRemoteValue = Serialization::Record.define( + type: {fixed: 'weakmap'}, + handle: 'handle', + internal_id: 'internalId' + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + WeakSetRemoteValue = Serialization::Record.define( + type: {fixed: 'weakset'}, + handle: 'handle', + internal_id: 'internalId' + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + GeneratorRemoteValue = Serialization::Record.define( + type: {fixed: 'generator'}, + handle: 'handle', + internal_id: 'internalId' + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + ErrorRemoteValue = Serialization::Record.define( + type: {fixed: 'error'}, + handle: 'handle', + internal_id: 'internalId' + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + ProxyRemoteValue = Serialization::Record.define( + type: {fixed: 'proxy'}, + handle: 'handle', + internal_id: 'internalId' + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + PromiseRemoteValue = Serialization::Record.define( + type: {fixed: 'promise'}, + handle: 'handle', + internal_id: 'internalId' + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + TypedArrayRemoteValue = Serialization::Record.define( + type: {fixed: 'typedarray'}, + handle: 'handle', + internal_id: 'internalId' + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + ArrayBufferRemoteValue = Serialization::Record.define( + type: {fixed: 'arraybuffer'}, + handle: 'handle', + internal_id: 'internalId' + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + NodeListRemoteValue = Serialization::Record.define( + type: {fixed: 'nodelist'}, + handle: 'handle', + internal_id: 'internalId', + value: {json_key: 'value', ref: 'Script::RemoteValue', list: true} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + HTMLCollectionRemoteValue = Serialization::Record.define( + type: {fixed: 'htmlcollection'}, + handle: 'handle', + internal_id: 'internalId', + value: {json_key: 'value', ref: 'Script::RemoteValue', list: true} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + NodeRemoteValue = Serialization::Record.define( + type: {fixed: 'node'}, + shared_id: 'sharedId', + handle: 'handle', + internal_id: 'internalId', + value: {json_key: 'value', ref: 'Script::NodeProperties'} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + NodeProperties = Serialization::Record.define( + node_type: 'nodeType', + child_node_count: 'childNodeCount', + attributes: 'attributes', + children: {json_key: 'children', ref: 'Script::NodeRemoteValue', list: true}, + local_name: 'localName', + mode: {json_key: 'mode', enum: 'Script::NODE_PROPERTIES_MODE'}, + namespace_uri: 'namespaceURI', + node_value: 'nodeValue', + shadow_root: {json_key: 'shadowRoot', nullable: true, ref: 'Script::NodeRemoteValue'} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + WindowProxyRemoteValue = Serialization::Record.define( + type: {fixed: 'window'}, + value: {json_key: 'value', ref: 'Script::WindowProxyProperties'}, + handle: 'handle', + internal_id: 'internalId' + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + WindowProxyProperties = Serialization::Record.define(context: 'context') + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + SerializationOptions = Serialization::Record.define( + max_dom_depth: {json_key: 'maxDomDepth', nullable: true}, + max_object_depth: {json_key: 'maxObjectDepth', nullable: true}, + include_shadow_tree: {json_key: 'includeShadowTree', enum: 'Script::SERIALIZATION_OPTIONS_INCLUDE_SHADOW_TREE'} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + StackFrame = Serialization::Record.define( + column_number: 'columnNumber', + function_name: 'functionName', + line_number: 'lineNumber', + url: 'url' + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + StackTrace = Serialization::Record.define( + call_frames: {json_key: 'callFrames', ref: 'Script::StackFrame', list: true} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + Source = Serialization::Record.define(realm: 'realm', context: 'context', user_context: 'userContext') + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + RealmTarget = Serialization::Record.define(realm: 'realm') + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + ContextTarget = Serialization::Record.define(context: 'context', sandbox: 'sandbox') + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + class Target < Serialization::Union + presence( + 'Script::ContextTarget' => ['context'], + 'Script::RealmTarget' => ['realm'] + ) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + AddPreloadScriptParameters = Serialization::Record.define( + function_declaration: 'functionDeclaration', + arguments: {json_key: 'arguments', ref: 'Script::ChannelValue', list: true}, + contexts: {json_key: 'contexts', list: true}, + user_contexts: {json_key: 'userContexts', list: true}, + sandbox: 'sandbox' + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + AddPreloadScriptResult = Serialization::Record.define(script: 'script') + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + DisownParameters = Serialization::Record.define( + handles: {json_key: 'handles', list: true}, + target: {json_key: 'target', ref: 'Script::Target'} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + CallFunctionParameters = Serialization::Record.define( + function_declaration: 'functionDeclaration', + await_promise: 'awaitPromise', + target: {json_key: 'target', ref: 'Script::Target'}, + arguments: {json_key: 'arguments', ref: 'Script::LocalValue', list: true}, + result_ownership: {json_key: 'resultOwnership', enum: 'Script::RESULT_OWNERSHIP'}, + serialization_options: {json_key: 'serializationOptions', ref: 'Script::SerializationOptions'}, + this: {json_key: 'this', ref: 'Script::LocalValue'}, + user_activation: 'userActivation' + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + EvaluateParameters = Serialization::Record.define( + expression: 'expression', + target: {json_key: 'target', ref: 'Script::Target'}, + await_promise: 'awaitPromise', + result_ownership: {json_key: 'resultOwnership', enum: 'Script::RESULT_OWNERSHIP'}, + serialization_options: {json_key: 'serializationOptions', ref: 'Script::SerializationOptions'}, + user_activation: 'userActivation' + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + GetRealmsParameters = Serialization::Record.define( + context: 'context', + type: {json_key: 'type', enum: 'Script::REALM_TYPE'} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + GetRealmsResult = Serialization::Record.define( + realms: {json_key: 'realms', ref: 'Script::RealmInfo', list: true} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + RemovePreloadScriptParameters = Serialization::Record.define(script: 'script') + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + MessageParameters = Serialization::Record.define( + channel: 'channel', + data: {json_key: 'data', ref: 'Script::RemoteValue'}, + source: {json_key: 'source', ref: 'Script::Source'} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + RealmDestroyedParameters = Serialization::Record.define(realm: 'realm') + + EVENT_TYPES = { + 'script.message' => Script::MessageParameters, + 'script.realmCreated' => Script::RealmInfo, + 'script.realmDestroyed' => Script::RealmDestroyedParameters + }.freeze + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def add_preload_script( + function_declaration:, + arguments: Serialization::UNSET, + contexts: Serialization::UNSET, + user_contexts: Serialization::UNSET, + sandbox: Serialization::UNSET + ) + params = AddPreloadScriptParameters.new( + function_declaration: function_declaration, + arguments: arguments, + contexts: contexts, + user_contexts: user_contexts, + sandbox: sandbox + ) + execute(cmd: 'script.addPreloadScript', params: params, result: Script::AddPreloadScriptResult) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def call_function( + function_declaration:, + await_promise:, + target:, + arguments: Serialization::UNSET, + result_ownership: Serialization::UNSET, + serialization_options: Serialization::UNSET, + this: Serialization::UNSET, + user_activation: Serialization::UNSET + ) + Serialization.validate!('resultOwnership', result_ownership, Script::RESULT_OWNERSHIP) + params = CallFunctionParameters.new( + function_declaration: function_declaration, + await_promise: await_promise, + target: target, + arguments: arguments, + result_ownership: result_ownership, + serialization_options: serialization_options, + this: this, + user_activation: user_activation + ) + execute(cmd: 'script.callFunction', params: params, result: Script::EvaluateResult) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def disown(handles:, target:) + params = DisownParameters.new(handles: handles, target: target) + execute(cmd: 'script.disown', params: params) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def evaluate( + expression:, + target:, + await_promise:, + result_ownership: Serialization::UNSET, + serialization_options: Serialization::UNSET, + user_activation: Serialization::UNSET + ) + Serialization.validate!('resultOwnership', result_ownership, Script::RESULT_OWNERSHIP) + params = EvaluateParameters.new( + expression: expression, + target: target, + await_promise: await_promise, + result_ownership: result_ownership, + serialization_options: serialization_options, + user_activation: user_activation + ) + execute(cmd: 'script.evaluate', params: params, result: Script::EvaluateResult) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def get_realms(context: Serialization::UNSET, type: Serialization::UNSET) + Serialization.validate!('type', type, Script::REALM_TYPE) + params = GetRealmsParameters.new(context: context, type: type) + execute(cmd: 'script.getRealms', params: params, result: Script::GetRealmsResult) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def remove_preload_script(script:) + params = RemovePreloadScriptParameters.new(script: script) + execute(cmd: 'script.removePreloadScript', params: params) + end + end # Script + end # Protocol + end # BiDi + end # WebDriver +end # Selenium diff --git a/rb/lib/selenium/webdriver/bidi/protocol/session.rb b/rb/lib/selenium/webdriver/bidi/protocol/session.rb new file mode 100644 index 0000000000000..2175ee0fab470 --- /dev/null +++ b/rb/lib/selenium/webdriver/bidi/protocol/session.rb @@ -0,0 +1,230 @@ +# 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. + +# This file is automatically generated. DO NOT EDIT! +# Regenerate with: bazel run //rb/lib/selenium/webdriver:bidi-generate + +module Selenium + module WebDriver + class BiDi + module Protocol + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + class Session < Domain + USER_PROMPT_HANDLER_TYPE = { + accept: 'accept', + dismiss: 'dismiss', + ignore: 'ignore' + }.freeze + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + CapabilitiesRequest = Serialization::Record.define( + always_match: {json_key: 'alwaysMatch', ref: 'Session::CapabilityRequest'}, + first_match: {json_key: 'firstMatch', ref: 'Session::CapabilityRequest', list: true} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + CapabilityRequest = Serialization::Record.define( + accept_insecure_certs: 'acceptInsecureCerts', + browser_name: 'browserName', + browser_version: 'browserVersion', + platform_name: 'platformName', + proxy: {json_key: 'proxy', ref: 'Session::ProxyConfiguration'}, + unhandled_prompt_behavior: {json_key: 'unhandledPromptBehavior', ref: 'Session::UserPromptHandler'}, + extensible: true + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + class ProxyConfiguration < Serialization::Union + discriminator 'proxyType', { + autodetect: 'autodetect', + direct: 'direct', + manual: 'manual', + pac: 'pac', + system: 'system' + } + variants( + autodetect: 'Session::AutodetectProxyConfiguration', + direct: 'Session::DirectProxyConfiguration', + manual: 'Session::ManualProxyConfiguration', + pac: 'Session::PacProxyConfiguration', + system: 'Session::SystemProxyConfiguration' + ) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + AutodetectProxyConfiguration = Serialization::Record.define( + proxy_type: {json_key: 'proxyType', fixed: 'autodetect'}, + extensible: true + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + DirectProxyConfiguration = Serialization::Record.define( + proxy_type: {json_key: 'proxyType', fixed: 'direct'}, + extensible: true + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + ManualProxyConfiguration = Serialization::Record.define( + proxy_type: {json_key: 'proxyType', fixed: 'manual'}, + http_proxy: 'httpProxy', + ssl_proxy: 'sslProxy', + socks_proxy: 'socksProxy', + socks_version: 'socksVersion', + no_proxy: {json_key: 'noProxy', list: true}, + extensible: true + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + SocksProxyConfiguration = Serialization::Record.define( + socks_proxy: 'socksProxy', + socks_version: 'socksVersion' + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + PacProxyConfiguration = Serialization::Record.define( + proxy_type: {json_key: 'proxyType', fixed: 'pac'}, + proxy_autoconfig_url: 'proxyAutoconfigUrl', + extensible: true + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + SystemProxyConfiguration = Serialization::Record.define( + proxy_type: {json_key: 'proxyType', fixed: 'system'}, + extensible: true + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + UserPromptHandler = Serialization::Record.define( + alert: {json_key: 'alert', enum: 'Session::USER_PROMPT_HANDLER_TYPE'}, + before_unload: {json_key: 'beforeUnload', enum: 'Session::USER_PROMPT_HANDLER_TYPE'}, + confirm: {json_key: 'confirm', enum: 'Session::USER_PROMPT_HANDLER_TYPE'}, + default: {json_key: 'default', enum: 'Session::USER_PROMPT_HANDLER_TYPE'}, + file: {json_key: 'file', enum: 'Session::USER_PROMPT_HANDLER_TYPE'}, + prompt: {json_key: 'prompt', enum: 'Session::USER_PROMPT_HANDLER_TYPE'} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + SubscribeParameters = Serialization::Record.define( + events: {json_key: 'events', list: true}, + contexts: {json_key: 'contexts', list: true}, + user_contexts: {json_key: 'userContexts', list: true} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + UnsubscribeByIDRequest = Serialization::Record.define(subscriptions: {json_key: 'subscriptions', list: true}) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + UnsubscribeByAttributesRequest = Serialization::Record.define(events: {json_key: 'events', list: true}) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + StatusResult = Serialization::Record.define(ready: 'ready', message: 'message') + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + NewParameters = Serialization::Record.define( + capabilities: {json_key: 'capabilities', ref: 'Session::CapabilitiesRequest'} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + NewResult = Serialization::Record.define( + session_id: 'sessionId', + capabilities: {json_key: 'capabilities', ref: 'Session::NewResult::Capabilities'} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + NewResult::Capabilities = Serialization::Record.define( + accept_insecure_certs: 'acceptInsecureCerts', + browser_name: 'browserName', + browser_version: 'browserVersion', + platform_name: 'platformName', + set_window_rect: 'setWindowRect', + user_agent: 'userAgent', + proxy: {json_key: 'proxy', ref: 'Session::ProxyConfiguration'}, + unhandled_prompt_behavior: {json_key: 'unhandledPromptBehavior', ref: 'Session::UserPromptHandler'}, + web_socket_url: 'webSocketUrl', + extensible: true + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + SubscribeResult = Serialization::Record.define(subscription: 'subscription') + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + class UnsubscribeParameters < Serialization::Union + presence( + 'Session::UnsubscribeByAttributesRequest' => ['events'], + 'Session::UnsubscribeByIDRequest' => ['subscriptions'] + ) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def end_ + execute(cmd: 'session.end') + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def new(capabilities:) + params = NewParameters.new(capabilities: capabilities) + execute(cmd: 'session.new', params: params, result: Session::NewResult) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def status + execute(cmd: 'session.status', result: Session::StatusResult) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def subscribe(events:, contexts: Serialization::UNSET, user_contexts: Serialization::UNSET) + params = SubscribeParameters.new(events: events, contexts: contexts, user_contexts: user_contexts) + execute(cmd: 'session.subscribe', params: params, result: Session::SubscribeResult) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def unsubscribe(events: Serialization::UNSET, subscriptions: Serialization::UNSET) + params = UnsubscribeParameters.build(events: events, subscriptions: subscriptions) + execute(cmd: 'session.unsubscribe', params: params) + end + end # Session + end # Protocol + end # BiDi + end # WebDriver +end # Selenium diff --git a/rb/lib/selenium/webdriver/bidi/protocol/speculation.rb b/rb/lib/selenium/webdriver/bidi/protocol/speculation.rb new file mode 100644 index 0000000000000..ef65a15495a49 --- /dev/null +++ b/rb/lib/selenium/webdriver/bidi/protocol/speculation.rb @@ -0,0 +1,56 @@ +# 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. + +# This file is automatically generated. DO NOT EDIT! +# Regenerate with: bazel run //rb/lib/selenium/webdriver:bidi-generate + +module Selenium + module WebDriver + class BiDi + module Protocol + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + class Speculation < Domain + EVENTS = { + prefetch_status_updated: 'speculation.prefetchStatusUpdated' + }.freeze + + PRELOADING_STATUS = { + pending: 'pending', + ready: 'ready', + success: 'success', + failure: 'failure' + }.freeze + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + PrefetchStatusUpdatedParameters = Serialization::Record.define( + context: 'context', + url: 'url', + status: {json_key: 'status', enum: 'Speculation::PRELOADING_STATUS'} + ) + + EVENT_TYPES = { + 'speculation.prefetchStatusUpdated' => Speculation::PrefetchStatusUpdatedParameters + }.freeze + end # Speculation + end # Protocol + end # BiDi + end # WebDriver +end # Selenium diff --git a/rb/lib/selenium/webdriver/bidi/protocol/storage.rb b/rb/lib/selenium/webdriver/bidi/protocol/storage.rb new file mode 100644 index 0000000000000..ca0f0f1bdf74a --- /dev/null +++ b/rb/lib/selenium/webdriver/bidi/protocol/storage.rb @@ -0,0 +1,157 @@ +# 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. + +# This file is automatically generated. DO NOT EDIT! +# Regenerate with: bazel run //rb/lib/selenium/webdriver:bidi-generate + +module Selenium + module WebDriver + class BiDi + module Protocol + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + class Storage < Domain + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + PartitionKey = Serialization::Record.define( + user_context: 'userContext', + source_origin: 'sourceOrigin', + extensible: true + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + CookieFilter = Serialization::Record.define( + name: 'name', + value: {json_key: 'value', ref: 'Network::BytesValue'}, + domain: 'domain', + path: 'path', + size: 'size', + http_only: 'httpOnly', + secure: 'secure', + same_site: {json_key: 'sameSite', enum: 'Network::SAME_SITE'}, + expiry: 'expiry', + extensible: true + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + BrowsingContextPartitionDescriptor = Serialization::Record.define( + type: {fixed: 'context'}, + context: 'context' + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + StorageKeyPartitionDescriptor = Serialization::Record.define( + type: {fixed: 'storageKey'}, + user_context: 'userContext', + source_origin: 'sourceOrigin', + extensible: true + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + class PartitionDescriptor < Serialization::Union + discriminator 'type', {context: 'context', storage_key: 'storageKey'} + variants( + context: 'Storage::BrowsingContextPartitionDescriptor', + storage_key: 'Storage::StorageKeyPartitionDescriptor' + ) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + GetCookiesParameters = Serialization::Record.define( + filter: {json_key: 'filter', ref: 'Storage::CookieFilter'}, + partition: {json_key: 'partition', ref: 'Storage::PartitionDescriptor'} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + GetCookiesResult = Serialization::Record.define( + cookies: {json_key: 'cookies', ref: 'Network::Cookie', list: true}, + partition_key: {json_key: 'partitionKey', ref: 'Storage::PartitionKey'} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + PartialCookie = Serialization::Record.define( + name: 'name', + value: {json_key: 'value', ref: 'Network::BytesValue'}, + domain: 'domain', + path: 'path', + http_only: 'httpOnly', + secure: 'secure', + same_site: {json_key: 'sameSite', enum: 'Network::SAME_SITE'}, + expiry: 'expiry', + extensible: true + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + SetCookieParameters = Serialization::Record.define( + cookie: {json_key: 'cookie', ref: 'Storage::PartialCookie'}, + partition: {json_key: 'partition', ref: 'Storage::PartitionDescriptor'} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + SetCookieResult = Serialization::Record.define( + partition_key: {json_key: 'partitionKey', ref: 'Storage::PartitionKey'} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + DeleteCookiesParameters = Serialization::Record.define( + filter: {json_key: 'filter', ref: 'Storage::CookieFilter'}, + partition: {json_key: 'partition', ref: 'Storage::PartitionDescriptor'} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + DeleteCookiesResult = Serialization::Record.define( + partition_key: {json_key: 'partitionKey', ref: 'Storage::PartitionKey'} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def delete_cookies(filter: Serialization::UNSET, partition: Serialization::UNSET) + params = DeleteCookiesParameters.new(filter: filter, partition: partition) + execute(cmd: 'storage.deleteCookies', params: params, result: Storage::DeleteCookiesResult) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def get_cookies(filter: Serialization::UNSET, partition: Serialization::UNSET) + params = GetCookiesParameters.new(filter: filter, partition: partition) + execute(cmd: 'storage.getCookies', params: params, result: Storage::GetCookiesResult) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def set_cookie(cookie:, partition: Serialization::UNSET) + params = SetCookieParameters.new(cookie: cookie, partition: partition) + execute(cmd: 'storage.setCookie', params: params, result: Storage::SetCookieResult) + end + end # Storage + end # Protocol + end # BiDi + end # WebDriver +end # Selenium diff --git a/rb/lib/selenium/webdriver/bidi/protocol/user_agent_client_hints.rb b/rb/lib/selenium/webdriver/bidi/protocol/user_agent_client_hints.rb new file mode 100644 index 0000000000000..0e6fea421ebd1 --- /dev/null +++ b/rb/lib/selenium/webdriver/bidi/protocol/user_agent_client_hints.rb @@ -0,0 +1,75 @@ +# 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. + +# This file is automatically generated. DO NOT EDIT! +# Regenerate with: bazel run //rb/lib/selenium/webdriver:bidi-generate + +module Selenium + module WebDriver + class BiDi + module Protocol + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + class UserAgentClientHints < Domain + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + ClientHintsMetadata = Serialization::Record.define( + brands: {json_key: 'brands', ref: 'UserAgentClientHints::BrandVersion', list: true}, + full_version_list: {json_key: 'fullVersionList', ref: 'UserAgentClientHints::BrandVersion', list: true}, + platform: 'platform', + platform_version: 'platformVersion', + architecture: 'architecture', + model: 'model', + mobile: 'mobile', + bitness: 'bitness', + wow64: 'wow64', + form_factors: {json_key: 'formFactors', list: true} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + BrandVersion = Serialization::Record.define(brand: 'brand', version: 'version') + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + SetClientHintsOverrideCommandParams = Serialization::Record.define( + client_hints: {json_key: 'clientHints', nullable: true, ref: 'UserAgentClientHints::ClientHintsMetadata'}, + contexts: {json_key: 'contexts', list: true}, + user_contexts: {json_key: 'userContexts', list: true} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def set_client_hints_override( + client_hints:, + contexts: Serialization::UNSET, + user_contexts: Serialization::UNSET + ) + params = SetClientHintsOverrideCommandParams.new( + client_hints: client_hints, + contexts: contexts, + user_contexts: user_contexts + ) + execute(cmd: 'userAgentClientHints.setClientHintsOverride', params: params) + end + end # UserAgentClientHints + end # Protocol + end # BiDi + end # WebDriver +end # Selenium diff --git a/rb/lib/selenium/webdriver/bidi/protocol/web_extension.rb b/rb/lib/selenium/webdriver/bidi/protocol/web_extension.rb new file mode 100644 index 0000000000000..bd0742fda840e --- /dev/null +++ b/rb/lib/selenium/webdriver/bidi/protocol/web_extension.rb @@ -0,0 +1,84 @@ +# 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. + +# This file is automatically generated. DO NOT EDIT! +# Regenerate with: bazel run //rb/lib/selenium/webdriver:bidi-generate + +module Selenium + module WebDriver + class BiDi + module Protocol + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + class WebExtension < Domain + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + InstallParameters = Serialization::Record.define( + extension_data: {json_key: 'extensionData', ref: 'WebExtension::ExtensionData'} + ) + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + class ExtensionData < Serialization::Union + discriminator 'type', {archive_path: 'archivePath', base64: 'base64', path: 'path'} + variants( + archive_path: 'WebExtension::ExtensionArchivePath', + base64: 'WebExtension::ExtensionBase64Encoded', + path: 'WebExtension::ExtensionPath' + ) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + ExtensionPath = Serialization::Record.define(type: {fixed: 'path'}, path: 'path') + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + ExtensionArchivePath = Serialization::Record.define(type: {fixed: 'archivePath'}, path: 'path') + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + ExtensionBase64Encoded = Serialization::Record.define(type: {fixed: 'base64'}, value: 'value') + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + InstallResult = Serialization::Record.define(extension: 'extension') + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + UninstallParameters = Serialization::Record.define(extension: 'extension') + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def install(extension_data:) + params = InstallParameters.new(extension_data: extension_data) + execute(cmd: 'webExtension.install', params: params, result: WebExtension::InstallResult) + end + + # @api private + # @see https://www.selenium.dev/documentation/warnings/bidi-implementation/ + def uninstall(extension:) + params = UninstallParameters.new(extension: extension) + execute(cmd: 'webExtension.uninstall', params: params) + end + end # WebExtension + end # Protocol + end # BiDi + end # WebDriver +end # Selenium diff --git a/rb/lib/selenium/webdriver/bidi/serialization.rb b/rb/lib/selenium/webdriver/bidi/serialization.rb new file mode 100644 index 0000000000000..3009f5a1b9f6e --- /dev/null +++ b/rb/lib/selenium/webdriver/bidi/serialization.rb @@ -0,0 +1,78 @@ +# 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 + # Wire round-trip runtime for the generated protocol layer: the value-type bases + # (Record, Union), the omit sentinel (UNSET), and outbound enum validation. + # + # @api private + module Serialization + # Sentinel for an omitted optional: dropped from the payload entirely, vs nil which + # a nullable field serializes as wire null. + # + # @api private + UNSET = ::Object.new + def UNSET.inspect = 'UNSET' + UNSET.freeze + + # Validates an outbound enum argument: +value+ is a symbol (or list of symbols) that + # must be a key of the enum hash (+{symbol => wire_token}+), so a bad value fails + # locally with a clear error instead of a round-trip. Inbound payloads are trusted + # and not checked. + # + # @api private + def self.validate!(name, value, enum) + return if UNSET.equal?(value) || value.nil? + + elements = value.is_a?(::Array) ? value : [value] + invalid = elements.reject { |element| enum.key?(element) } + return if invalid.empty? + + raise ::ArgumentError, "#{name} must be one of #{enum.keys.inspect}, got #{invalid.inspect}" + end + + # Outbound: map a validated enum symbol (or list) to the wire token(s) to serialize. + # + # @api private + def self.to_wire(value, enum) + return value if UNSET.equal?(value) || value.nil? + + value.is_a?(::Array) ? value.map { |element| enum.fetch(element) } : enum.fetch(value) + end + + # Inbound: map a wire token (or list) back to its enum symbol, raising on a token + # outside our schema so a non-compliant (or newer-than-schema) browser value fails + # loud instead of silently passing through untyped. + # + # @api private + def self.to_symbol(name, value, enum) + return value if value.nil? + return value.map { |element| to_symbol(name, element, enum) } if value.is_a?(::Array) + + enum.key(value) || raise(Error::WebDriverError, "#{name} received an unknown value: #{value.inspect}") + end + end + end # BiDi + end # WebDriver +end # Selenium + +require 'selenium/webdriver/bidi/serialization/record' +require 'selenium/webdriver/bidi/serialization/union' diff --git a/rb/lib/selenium/webdriver/bidi/serialization/record.rb b/rb/lib/selenium/webdriver/bidi/serialization/record.rb new file mode 100644 index 0000000000000..229e2ab96ec5a --- /dev/null +++ b/rb/lib/selenium/webdriver/bidi/serialization/record.rb @@ -0,0 +1,199 @@ +# 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 + module Serialization + # Immutable value type for the generated protocol classes. +Record.define(spec)+ + # bakes each field's wire facts and returns a +::Data+ subclass with serialization. + # + # Cookie = Record.define(name: 'name', value: {json_key: 'value', ref: 'Network::BytesValue'}) + # + # @api private + class Record < ::Data + # Named Field, not Member, to avoid colliding with +::Data#members+. + Field = ::Data.define(:name, :json_key, :nullable, :ref, :list, :fixed, :enum) + + def self.define(**spec) + extensible = spec.delete(:extensible) || false + fields = spec.map { |name, meta| field(name, meta) } + names = fields.map(&:name) + names << :extensions if extensible + + klass = super(*names) + fields.freeze + # Singleton methods are inherited by `X = Record.define(…)`; ivars would not. + klass.define_singleton_method(:fields) { fields } + klass.define_singleton_method(:extensible?) { extensible } + klass.include(Serializable) + # Capture ::Data's generated +new+, then prepend (not include) Deserializer so + # its +new+ overrides it — outbound +new+ adds validation, while inbound + # +from_json+ builds directly via the captured constructor. Bound to +self+ so a + # subclass builds itself, not the base. + data_new = klass.singleton_class.instance_method(:new) + klass.singleton_class.prepend(Deserializer) + klass.define_singleton_method(:construct) { |**attributes| data_new.bind_call(self, **attributes) } + klass.singleton_class.send(:private, :construct) + klass + end + + def self.field(name, meta) + meta = {json_key: meta} if meta.is_a?(::String) + Field.new(name: name.to_sym, json_key: meta.fetch(:json_key, name.to_s), + nullable: meta[:nullable] || false, ref: meta[:ref], + list: meta[:list] || false, fixed: meta.fetch(:fixed, UNSET), enum: meta[:enum]) + end + private_class_method :field + + # Inbound construction: the keyword +new+ (validated) and the wire +from_json+. + # + # @api private + module Deserializer + def new(**kwargs) + # Start from what was passed so ::Data's constructor rejects an unknown key, then fill + # each field with its value or UNSET (omitted), forcing fixed discriminators. + attributes = kwargs.dup + fields.each { |f| attributes[f.name] = fixed?(f) ? f.fixed : attributes.fetch(f.name, UNSET) } + attributes[:extensions] = kwargs.fetch(:extensions, {}) if extensible? + validate_values(attributes) + construct(**attributes) + end + + # Inbound: builds from the wire. Enum tokens are mapped back to symbols and an + # unrecognized one raises (in +read+); required-presence isn't checked and extra keys + # are captured (extensible) or ignored (closed) — strict on values, lenient on keys. + def from_json(json_payload) + attributes = fields.to_h do |f| + [f.name, wire_value(f, json_payload)] + end + attributes[:extensions] = extra(json_payload) if extensible? + construct(**attributes) + end + + private + + # Checks each field's value: a non-nullable field cannot be nil (nil is neither a + # value nor the UNSET omit-sentinel, so it would be silently dropped on the wire), and + # an enum field must be in its allowed set. The enum constant is resolved lazily so a + # cross-domain enum need not be loaded first. Outbound only (from +new+); inbound enum + # tokens are mapped-and-checked separately in +read+. + def validate_values(attributes) + fields.each do |f| + value = attributes[f.name] + raise ::ArgumentError, "#{name}##{f.name} cannot be nil" if value.nil? && !f.nullable + next if value.nil? || UNSET.equal?(value) + + check_outbound_shape(f, value) + Serialization.validate!("#{name}##{f.name}", value, Protocol.const_get(f.enum)) if f.enum + end + end + + # Outbound mirror of check_shape: a list-typed arg must be an array, a scalar-shaped one + # (enum or ref, not a list) must not — a local ArgumentError, not a wire round-trip. + def check_outbound_shape(field, value) + return if field.list == value.is_a?(::Array) + return unless field.list || field.enum || field.ref + + kind = field.list ? 'a list' : 'a single value' + raise ::ArgumentError, "#{name}##{field.name} expected #{kind}, got #{value.inspect}" + end + + def fixed?(field) + !UNSET.equal?(field.fixed) + end + + def wire_value(field, json_payload) + return field.fixed if fixed?(field) + return UNSET unless json_payload.key?(field.json_key) + + read(field, json_payload[field.json_key]) + end + + def read(field, raw) + if raw.nil? + return raw if field.nullable + + raise Error::WebDriverError, "#{name}##{field.name} received null but is not nullable" + end + check_shape(field, raw) + return Serialization.to_symbol("#{name}##{field.name}", raw, enum_hash(field)) if field.enum + return raw if field.ref.nil? + + klass = (@refs ||= {})[field.name] ||= Protocol.const_get(field.ref) + field.list ? read_list(raw, klass) : klass.from_json(raw) + end + + # A declared list must arrive as an array; a scalar-shaped field (enum or ref, not a + # list) must not. An opaque field carries no shape descriptor, so it passes through. + def check_shape(field, raw) + return if field.list == raw.is_a?(::Array) + return unless field.list || field.enum || field.ref + + raise Error::WebDriverError, + "#{name}##{field.name} expected #{field.list ? 'a list' : 'a single value'}, got #{raw.inspect}" + end + + def enum_hash(field) + (@enums ||= {})[field.name] ||= Protocol.const_get(field.enum) + end + + # Parses each element, recursing into nested lists (e.g. a map's [key, value] pairs) + # so their entries become typed too. + def read_list(raw, klass) + raw.map { |element| element.is_a?(::Array) ? read_list(element, klass) : klass.from_json(element) } + end + + def extra(json_payload) + known = (@json_keys ||= fields.map(&:json_key)) + json_payload.except(*known) + end + end + + # @api private + module Serializable + def self.as_json(value) + case value + when Serializable then value.as_json + when ::Array then value.map { |element| as_json(element) } + when ::Hash then value.transform_values { |element| as_json(element) } + else value + end + end + + # Omit UNSET fields; emit null only for nullable ones. + def as_json(*) + payload = {} + self.class.fields.each do |f| + value = public_send(f.name) + next if UNSET.equal?(value) + next if value.nil? && !f.nullable + + value = Serialization.to_wire(value, Protocol.const_get(f.enum)) if f.enum + payload[f.json_key] = Serializable.as_json(value) + end + payload.merge!(extensions) if self.class.extensible? && !extensions.empty? + payload + end + end + end + end + end # BiDi + end # WebDriver +end # Selenium diff --git a/rb/lib/selenium/webdriver/bidi/serialization/union.rb b/rb/lib/selenium/webdriver/bidi/serialization/union.rb new file mode 100644 index 0000000000000..ccfc3908a76ce --- /dev/null +++ b/rb/lib/selenium/webdriver/bidi/serialization/union.rb @@ -0,0 +1,114 @@ +# 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 + module Serialization + # Resolves a wire payload to the right Data variant: a shared discriminator gives + # table dispatch; presence rules and a no-tag fallback cover unions without one. + # Subclassed (never instantiated) — each union holds its own dispatch table. + # + # class Locator < Serialization::Union + # discriminator 'type' + # variants('css' => 'BrowsingContext::CssLocator') + # end + # + # @api private + class Union + class << self + # values maps each variant's discriminator symbol to its wire token, so an + # inbound payload tag (a wire string) can be matched to the symbol-keyed table. + def discriminator(json_key, values = {}) + @discriminator = json_key + @discriminator_values = values + end + + def variants(table) = @variants = table + def presence(rules) = @presence = rules + def fallback(path) = @fallback = path + + # A non-Hash payload is a bare scalar arm (e.g. input.Origin's "viewport") with + # no object to dispatch on, so it is returned unchanged. + def from_json(json_payload) + return json_payload unless json_payload.is_a?(::Hash) + + variant = select(json_payload) + unless variant + raise Error::WebDriverError, + "#{name} received a variant not in this Selenium's BiDi schema: #{json_payload.inspect}" + end + Protocol.const_get(variant).from_json(json_payload) + end + + # Outbound mirror of from_json: build the variant the command's kwargs describe + # so its typed as_json drives null-vs-absent per field (a flat hash through + # Transport cannot). Dispatch keys are wire names equal to their ruby kwarg + # (asserted at generation), so they match the kwargs by symbol. A mismatch here + # is a caller error (unlike an unknown inbound value), so it fails loudly. + def build(**kwargs) + variant = outbound_variant(kwargs) || + raise(::ArgumentError, "no #{name} variant matches #{kwargs.inspect}") + klass = Protocol.const_get(variant) + # An omitted optional arrives as UNSET; forward only what was provided. A provided + # key that isn't a field of the chosen variant is an invalid combination for this union. + provided = kwargs.reject { |_, value| UNSET.equal?(value) } + invalid = provided.keys - klass.fields.map(&:name) + return klass.new(**provided) if invalid.empty? + + raise ::ArgumentError, "invalid combination for #{name}: #{invalid.join(', ')}" + end + + private + + # The discriminator value may legitimately be null (e.g. script.NullValue's + # "null" tag), so it is matched by key presence. + def select(json_payload) + variant_for(payload_tag(json_payload)) { |k| json_payload.key?(k) } + end + + # An explicit nil kwarg still counts as supplied; a non-nullable field set to nil is + # rejected at construction (Data.new), not here. + def outbound_variant(kwargs) + tag = @discriminator ? kwargs.fetch(@discriminator.to_sym, UNSET) : UNSET + variant_for(tag) { |k| kwargs.key?(k.to_sym) && !UNSET.equal?(kwargs[k.to_sym]) } + end + + # The matching variant's ref, or nil when none matches (the fallback if declared). + def variant_for(tag, &supplied) + return @variants[tag] if !UNSET.equal?(tag) && @variants&.key?(tag) + + @presence&.each { |path, keys| return path if keys.all?(&supplied) } + @fallback + end + + # The wire tag mapped back to its variant symbol (the table's key); an + # unrecognized tag falls through as-is so select misses and from_json raises. + def payload_tag(json_payload) + return UNSET unless @discriminator && json_payload.key?(@discriminator) + + wire = json_payload[@discriminator] + @discriminator_values.key(wire) || wire + end + end + end + end + end # BiDi + end # WebDriver +end # Selenium diff --git a/rb/lib/selenium/webdriver/bidi/support/bidi_generate.rb b/rb/lib/selenium/webdriver/bidi/support/bidi_generate.rb new file mode 100644 index 0000000000000..8b6f7f2f78120 --- /dev/null +++ b/rb/lib/selenium/webdriver/bidi/support/bidi_generate.rb @@ -0,0 +1,916 @@ +# 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. + +require 'json' +require 'erb' +require 'fileutils' + +# Generates Ruby WebDriver BiDi protocol modules from the shared, binding-neutral +# BiDi schema produced by the JavaScript generator (see PR #17700): +# //javascript/selenium-webdriver:create-bidi-src_schema -> bidi-schema.json +# +# The schema is already normalized (inline enums hoisted, unions canonicalized, +# group composition flattened, wire names and nullability preserved verbatim), so +# this generator is a straight projection into Ruby with no CDDL interpretation. +# +# Invoked via `bazel run //rb/lib/selenium/webdriver:bidi-generate`. Bazel passes +# the schema path (resolved through runfiles) plus the workspace-relative output +# directory as ARGV. Can also be run directly: +# ruby bidi_generate.rb schema.json output/dir +# +# @api private +module BiDiGenerate + # Companion to the generated `@api private` tags: the page explaining why the BiDi + # implementation layer is internal and what higher-level API to use instead (see #17628). + BIDI_DOC_URL = 'https://www.selenium.dev/documentation/warnings/bidi-implementation/' + + # RuboCop's Layout/LineLength max; emitted Serialization::Record.define calls wrap to stay within it. + LINE_LIMIT = 120 + + # Ruby keywords that cannot be used as method names unquoted. + RUBY_RESERVED = %w[begin end rescue ensure raise return yield if unless while until for do + case when then class module def].freeze + + def self.camel_to_snake(str) + str + .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2') + .gsub(/([a-z\d])([A-Z])/, '\1_\2') + .downcase + end + + def self.snake_to_class_name(snake) + snake.split('_').map(&:capitalize).join + end + + # Local constant for a domain-scoped type: "script.LocalValue" -> "LocalValue". + # The first letter is capitalized so a lower-cased spec name (e.g. + # "permissions.setPermission") still yields a valid Ruby constant. + def self.type_class_name(type_name) + type_name.split('.', 2).last.sub(/\A[a-z]/, &:upcase) + end + + # Protocol-relative class path: "script.LocalValue" -> "Script::LocalValue". + def self.type_ruby_path(type_name) + domain = type_name.split('.', 2).first + "#{snake_to_class_name(camel_to_snake(domain))}::#{type_class_name(type_name)}" + end + + # Source literal for a discriminator/const value (string, boolean, or number). + def self.ruby_literal(value) + return 'nil' if value.nil? + + value.is_a?(String) ? "'#{value}'" : value.to_s + end + + # Renders `prefix(args)` on one line, or one argument per line when it would exceed + # LINE_LIMIT at the given indent. open/close default to parentheses (pass {} for a + # hash literal) so emitted calls and literals stay within RuboCop's length limit. + def self.wrap_call(prefix, args, indent, open: '(', close: ')') + one_line = "#{prefix}#{open}#{args.join(', ')}#{close}" + return one_line if args.empty? || indent + one_line.length <= LINE_LIMIT + + pad = ' ' * (indent + 2) + "#{prefix}#{open}\n#{pad}#{args.join(",\n#{pad}")}\n#{' ' * indent}#{close}" + end + + # Append underscore to avoid clashing with Ruby reserved keywords. + def self.safe_method_name(name) + RUBY_RESERVED.include?(name) ? "#{name}_" : name + end + + # Object/Data methods a Data member name would shadow (breaking value semantics + # or reflection), e.g. a "method" field overriding Object#method. + RESERVED_FIELD_NAMES = (RUBY_RESERVED + %w[method hash class send dup clone freeze inspect + to_h to_s members with deconstruct deconstruct_keys + object_id tap itself then display + extensible extensions]).freeze + + # Append underscore to a field name that would shadow a core method; the wire + # name is unaffected, only the Ruby reader is renamed. + def self.safe_field_name(name) + RESERVED_FIELD_NAMES.include?(name) ? "#{name}_" : name + end + + # SCREAMING_SNAKE constant name for an enum, matching the EVENTS map style + # (ReadinessState → READINESS_STATE). + def self.screaming_snake(camel) + camel_to_snake(camel).upcase + end + + # Makes an RBS type admit nil, idempotently (an already-nilable or opaque type is + # left as-is). Used both for nullable fields and for optional params, where passing + # nil is the runtime equivalent of omitting the argument. + def self.rbs_nilable(type) + return type if type == 'untyped' || type == 'nil' || type.end_with?('?') + + "#{type}?" + end + + # Domain-qualified path to an enum's frozen hash constant + # ("browsingContext.ReadinessState" → "BrowsingContext::READINESS_STATE"), so a + # generated command method can reference it for an outbound membership check. + def self.enum_const_path(type_name) + domain, local = type_name.split('.', 2) + "#{snake_to_class_name(camel_to_snake(domain))}::#{screaming_snake(local)}" + end + + # snake_case hash key for an enum value (only a label for the wire value it maps to). + # Preserves camelCase word boundaries (beforeRequestSent → before_request_sent), maps a + # leading minus to "neg" (-0 → neg0, -Infinity → neg_infinity; no underscore before a + # digit, so the key stays normalcase), and collapses other punctuation + # (dedicated-worker → dedicated_worker). + def self.enum_key(value) + camel_to_snake(value.to_s) + .sub(/\A-(?=\d)/, 'neg') + .sub(/\A-/, 'neg_') + .gsub(/[^a-z0-9]+/, '_') + .gsub(/\A_+|_+\z/, '') + end + + # ruby_name is the snake_case keyword argument; wire_name is the exact key the + # protocol expects (baked verbatim from the schema, no runtime conversion). enum is + # the allowed-values constant path for an enum-typed param (nil otherwise). + Param = Struct.new(:ruby_name, :wire_name, :required, :enum, :rbs, keyword_init: true) do + # Optionals default to UNSET (omitted), so an explicit nil can still reach a + # nullable field as wire null. + def sig_part + required ? "#{ruby_name}:" : "#{ruby_name}: Serialization::UNSET" + end + + def enum_check(indent) + return unless enum + + BiDiGenerate.wrap_call('Serialization.validate!', ["'#{wire_name}'", ruby_name, enum], indent) + end + + # An RBS keyword parameter carrying the param's value type. A required param is its + # bare type; an optional one is prefixed `?` and admits nil, since passing nil is the + # runtime equivalent of omitting it (a non-nullable field's nil is dropped on the wire). + def rbs_part + type = rbs || 'untyped' + required ? "#{ruby_name}: #{type}" : "?#{ruby_name}: #{BiDiGenerate.rbs_nilable(type)}" + end + end + + # params_class is the Parameters class the named args construct (nil for a no-arg + # command); union_params picks its variant via `.build` rather than `.new`. result_ref + # is the Protocol-relative result class path, or nil to return the raw hash. + Command = Struct.new(:wire_name, :method_name, :params, :result_ref, :params_class, + :union_params, keyword_init: true) do + def required_params = params.select(&:required) + def optional_params = params.reject(&:required) + def enum_checks(indent) = params.filter_map { |p| p.enum_check(indent) } + + # `def name` or `def name(...)` — wrapped one argument per line when the signature + # would exceed the line limit. + def def_header(indent) + return "def #{method_name}" if params.empty? + + BiDiGenerate.wrap_call("def #{method_name}", required_params.map(&:sig_part) + optional_params.map(&:sig_part), + indent) + end + + # The RBS method signature `(params) -> return` — the return is the typed result class + # when the command parses one, else `untyped`. + def rbs_signature + "(#{rbs_params}) -> #{rbs_return}" + end + + def rbs_params + (required_params.map(&:rbs_part) + optional_params.map(&:rbs_part)).join(', ') + end + + def rbs_return + result_ref ? "::Selenium::WebDriver::BiDi::Protocol::#{result_ref}" : 'untyped' + end + + # The `params = …` line built before the execute call, or nil for a no-arg command. A + # record builds its Parameters object and a union dispatches via `.build` (whose typed + # as_json emits explicit null where a flat hash through Transport could not). Wrapped + # one entry per line when long, so it (and the short execute call) stay within the limit. + def params_assignment(indent) + return nil if params.empty? + + kwargs = params.map { |p| "#{p.ruby_name}: #{p.ruby_name}" } + BiDiGenerate.wrap_call("params = #{params_class}.#{union_params ? 'build' : 'new'}", kwargs, indent) + end + + # `@transport.execute(cmd:[, params: params][, result:])`. The result type is + # referenced directly (resolved lazily in the method body, and unambiguous within + # Protocol). Params, when present, are the `params` local built above. + def execute_call(indent) + args = ["cmd: '#{wire_name}'"] + args << 'params: params' unless params.empty? + args << "result: #{result_ref}" if result_ref + BiDiGenerate.wrap_call('execute', args, indent) + end + end + + # payload_ref is the Protocol-relative class the event's params parse into (nil when + # non-structured, dispatched raw) — the inbound counterpart to a command's result_ref. + Event = Struct.new(:wire_name, :event_name, :payload_ref, keyword_init: true) do + # An EVENT_TYPES entry mapping the wire method to the type its params parse into. + def type_entry = "'#{wire_name}' => #{payload_ref || 'nil'}" + end + + # constant_name is the SCREAMING_SNAKE hash name; pairs are [symbol_key, wire_value] tuples. + Enum = Struct.new(:constant_name, :pairs, keyword_init: true) + + # ref is the Protocol-relative class path for a nested structured field (nil + # for a scalar/opaque field); list wraps it in an array. json_key is the exact + # JSON payload key (the schema's `wire` name, baked verbatim). + FieldIR = Struct.new(:ruby_name, :json_key, :required, :nullable, :ref, :list, :enum, :rbs, keyword_init: true) do + # A `Serialization::Record.define` spec entry: `name: 'jsonKey'` shorthand, or + # `name: {json_key:, …}` when the field carries JSON facts beyond its name. + # enum carries the allowed-values constant path, validated at construction. + def spec_entry + meta = [] + meta << 'nullable: true' if nullable + meta << "ref: '#{ref}'" if ref + meta << 'list: true' if list + meta << "enum: '#{enum}'" if enum + return "#{ruby_name}: '#{json_key}'" if meta.empty? + + "#{ruby_name}: {json_key: '#{json_key}', #{meta.join(', ')}}" + end + + # The `self.new` keyword for this field — a user-supplied input carrying the field's + # value type. An optional field is prefixed `?` and admits nil (nil omits it, same as + # the command-param path); a required field is its bare type. + def rbs_arg + required ? "#{ruby_name}: #{rbs}" : "?#{ruby_name}: #{BiDiGenerate.rbs_nilable(rbs)}" + end + + # The `attr_reader` type. A present value is `rbs`; an omitted optional reads back + # the UNSET sentinel, which a value type can't capture, so optionals stay `untyped`. + def rbs_reader + "#{ruby_name}: #{required ? rbs : 'untyped'}" + end + end + + # A generated immutable value type (a Serialization::Record.define(...) class). discriminator is the + # baked variant tag {ruby_name:, wire:, value:} or nil; schema_name/synthetic/owner/ + # nested drive owner-nesting (see nest_synthetic). + TypeClass = Struct.new(:ruby_name, :fields, :discriminator, :extensible, + :schema_name, :synthetic, :owner, :label, :nested, keyword_init: true) do + def union? = false + def nested_types = nested || [] + + # Keyword arguments for `Serialization::Record.define(...)`: the fixed discriminator member + # first, then the fields, then the extensible flag. + def define_entries + entries = [] + entries << discriminator_entry if discriminator + entries.concat(fields.map(&:spec_entry)) + entries << 'extensible: true' if extensible + entries + end + + # `Name = Serialization::Record.define(...)` as one line when it fits within the line limit at the + # given indent, else wrapped one entry per line — so the emitted source stays inside + # RuboCop's length limit without a per-file exception. + def define_assignment(name, indent) + BiDiGenerate.wrap_call("#{name} = Serialization::Record.define", define_entries, indent) + end + + def discriminator_entry + literal = BiDiGenerate.ruby_literal(discriminator[:value]) + if discriminator[:wire] == discriminator[:ruby_name].to_s + "#{discriminator[:ruby_name]}: {fixed: #{literal}}" + else + "#{discriminator[:ruby_name]}: {json_key: '#{discriminator[:wire]}', fixed: #{literal}}" + end + end + + # Every Data member gets a typed `attr_reader`: the baked discriminator (untyped), + # each field (typed when required; UNSET-bearing optionals stay untyped), then the + # extensible passthrough. + def rbs_readers + readers = [] + readers << "#{discriminator[:ruby_name]}: untyped" if discriminator + readers.concat(fields.map(&:rbs_reader)) + readers << 'extensions: Hash[String, untyped]' if extensible + readers + end + + # The keyword arguments `self.new` accepts: each constructable field with its value + # type, plus the optional extensions bag. The fixed discriminator is baked, so its + # value is ignored — but the lenient `**kwargs` constructor still accepts it (and a + # command method passes it through), so it is advertised as an optional keyword. + def rbs_new_args + parts = [] + parts << "?#{discriminator[:ruby_name]}: untyped" if discriminator + parts.concat(fields.map(&:rbs_arg)) + parts << '?extensions: untyped' if extensible + parts.join(', ') + end + end + + # mode is :value (matched by discriminator), :fallback (the no-tag variant), or + # :presence (selected when its required wire keys are all present). + VariantIR = Struct.new(:mode, :value, :ref, :requires, keyword_init: true) do + # A string tag becomes an idiomatic symbol key; a bool/number tag stays a literal. + def symbolic? = value.is_a?(::String) + + # The variant table entry: `sym: 'Ref'` for a string tag, else `true => 'Ref'`. + def variant_entry + key = symbolic? ? "#{BiDiGenerate.enum_key(value)}:" : "#{BiDiGenerate.ruby_literal(value)} =>" + "#{key} '#{ref}'" + end + + # `sym: 'wireToken'` feeding the union's inbound wire->symbol map (string tags only). + def discriminator_pair + "#{BiDiGenerate.enum_key(value)}: '#{value}'" if symbolic? + end + end + + # A generated discriminated union (< Serialization::Union, resolved by lexical scope). + # nested holds its synthetic variant records (see nest_synthetic). + UnionClass = Struct.new(:ruby_name, :discriminator_wire, :variants, :schema_name, :nested, keyword_init: true) do + def union? = true + def value_variants = variants.select { |v| v.mode == :value } + def presence_variants = variants.select { |v| v.mode == :presence } + def fallback_variant = variants.find { |v| v.mode == :fallback } + def nested_types = nested || [] + + # `discriminator 'wire'`, or `discriminator 'wire', {sym: 'token', …}` (wrapped when + # long) carrying the inbound wire->symbol map for string-tagged variants. + def discriminator_decl(indent) + pairs = value_variants.filter_map(&:discriminator_pair) + head = "discriminator '#{discriminator_wire}'" + return head if pairs.empty? + + BiDiGenerate.wrap_call("#{head}, ", pairs, indent, open: '{', close: '}') + end + end + + Module = Struct.new(:name, :ruby_class, :filename, :commands, :events, :enums, :types, keyword_init: true) + + class Schema + def initialize(schema) + @types = schema['types'] + @commands = schema['commands'] + @events = schema['events'] + promote_command_params_records! + end + + # A command written in CDDL map form carries its params as an *inline* object (rather + # than the usual group form referencing a named params type). The projector links the + # command to those params, but hoists them into a synthetic record owned by the + # command's message envelope. That envelope is suppressed (Transport forms it), so the + # synthetic params record would never be emitted even though the command's params ref + # points straight at it. Promote it to a top-level domain record so the generator emits + # and references it like any other params type. Today this is exactly + # `userAgentClientHints.setClientHintsOverride`. + def promote_command_params_records! + @commands.each do |cmd| + ref = cmd.dig('params', 'ref') + next unless ref + + type = @types[ref] + promote_to_domain_type!(ref) if type && envelope_synthetic?(type) + end + end + + # Strip the synthetic/owner/label tags so a lifted-out type emits as a top-level + # domain record instead of nesting under its (suppressed) envelope. + def promote_to_domain_type!(name) + type = @types[name] + type&.delete('synthetic') + type&.delete('owner') + type&.delete('label') + end + + # Domains that carry a command or event each become one generated module. + def domains + (@commands + @events).map { |entry| entry['domain'] }.uniq + end + + def commands_for(domain) + @commands.select { |c| c['domain'] == domain } + end + + def type_kind(ref) + @types[ref]&.fetch('kind', nil) + end + + def events_for(domain) + @events.select { |e| e['domain'] == domain } + end + + # Flat params for a command: the record's fields, or — for a union of + # records — the merged superset of variant fields. Returns [] for commands + # with no params, or nil when params can't be flattened (alias, or a union + # whose variants aren't all records) so the caller forwards verbatim. + def params_for(params_ref) + return [] unless params_ref + + type = @types[params_ref['ref']] + return nil unless type + + case type['kind'] + when 'record' then record_params(type['fields']) + when 'union' then union_params(type, params_ref['ref']) + end + end + + # Enum types declared under "." become nested constant modules. + def enums_for(domain) + @types.filter_map do |name, type| + next unless type['kind'] == 'enum' + next unless name.start_with?("#{domain}.") + + pairs = type['values'].map { |v| [BiDiGenerate.enum_key(v), v.to_s] } + Enum.new(constant_name: BiDiGenerate.screaming_snake(name.sub("#{domain}.", '')), pairs: pairs) + end + end + + # Structured value classes (records + discriminated unions) declared under + # "." Empty records are projector artifacts with nothing to carry, so + # they stay opaque hashes; only non-empty records and unions become classes. + # Command/event message envelopes (the `{method, params}` wire wrapper) are + # skipped — Transport forms that envelope, so nothing references them. + def types_for(domain) + prefix = "#{domain}." + @types.filter_map do |name, type| + next unless name.start_with?(prefix) + + case type['kind'] + when 'record' then record_class(name, type) unless type['fields'].empty? || suppressed_record?(type) + when 'union' then union_class(name) + when 'alias' then union_class(name) if type['type'].key?('union') + end + end + end + + # Records the generator deliberately does not emit: a message envelope, or a + # synthetic params record lifted out of one. Both are reachable only through the + # envelope, which Transport replaces — so nothing else references them. + def suppressed_record?(type) + message_envelope?(type) || envelope_synthetic?(type) + end + + # A protocol message envelope is a record with a baked `method` discriminator + # (`{method: , params: …}`) — the wire shape of a command/event message. + # No value type carries a const `method` field, so this is unambiguous. + def message_envelope?(type) + type['fields'].any? { |f| f['wire'] == 'method' && f['type'].key?('const') } + end + + # A synthetic record lifted out as an envelope's params (its owner is an envelope). + def envelope_synthetic?(type) + return false unless type['synthetic'] + + owner = @types[type['owner']] + owner && owner['kind'] == 'record' && message_envelope?(owner) + end + + # The Protocol-relative class path a command result parses into, or nil when + # it is non-structured (or a bare list, returned raw). + def structured_ref(name) + resolved = resolve_named(name) + resolved[:list] ? nil : resolved[:ref] + end + + private + + def domain_path(name) + name.include?('.') ? ruby_path(name) : nil + end + + # Class path, nesting a synthetic type under its owner as `Owner::Label` so a ref + # resolves to the same nested constant the type is emitted as. + def ruby_path(name) + type = @types[name] + return BiDiGenerate.type_ruby_path(name) unless type && type['synthetic'] + + "#{ruby_path(type['owner'])}::#{type['label']}" + end + + # Resolution for anything not modeled as a value type (scalar, enum, empty record). + # Frozen because it is shared across callers. + OPAQUE = {ref: nil, list: false, rbs: 'untyped'}.freeze + + # Projects a schema type node to {ref:, list:, nullable:, rbs:}. Deriving the + # serialization facts and the RBS signature from one walk keeps them from drifting + # apart when the schema shape changes. + def resolve(node) + nullable = node['nullable'] ? true : false + if node.key?('list') + element = resolve(node['list']) + return {ref: element[:ref], list: true, nullable: nullable, rbs: nilable("Array[#{element[:rbs]}]", nullable)} + end + if node.key?('ref') + named = resolve_named(node['ref']) + return {ref: named[:ref], list: named[:list], nullable: nullable, rbs: nilable(named[:rbs], nullable)} + end + return resolve_union(node, nullable) if node.key?('union') + + {ref: nil, list: false, nullable: nullable, rbs: nilable(scalar_rbs(node), nullable)} + end + + # An inline union of one union-typed arm plus scalars (e.g. a MappingRemoteValue entry, + # RemoteValue / string) parses through that arm — its from_json returns a non-Hash value + # unchanged, so the scalar siblings pass through. Carry its ref so nested entries are typed; + # any other shape (a record arm, multiple structured arms, all scalars) stays opaque. + def resolve_union(node, nullable) + refs = node['union'].select { |arm| arm.key?('ref') } + opaque = {ref: nil, list: false, nullable: nullable, rbs: nilable('untyped', nullable)} + return opaque unless refs.one? && union_ref?(refs.first['ref']) + + named = resolve_named(refs.first['ref']) + {ref: named[:ref], list: named[:list], nullable: nullable, rbs: nilable('untyped', nullable)} + end + + # True when a ref (following aliases) is a union — the only arm whose from_json tolerates a + # scalar sibling. A record arm would raise on one, so it is not carried. + def union_ref?(name) + type = @types[name] + return false unless type + return union_ref?(type['type']['ref']) if type['kind'] == 'alias' && type['type'].key?('ref') + + type['kind'] == 'union' + end + + # Resolves a named ref to the same {ref:, list:, rbs:} facts, transparently + # following aliases — including alias-to-list — so an element type behind an alias + # (e.g. script.ListLocalValue -> [script.LocalValue]) is preserved. Nullability is a + # property of the referencing node (applied by +resolve+), so it is not threaded + # here. seen guards against cyclic ref-aliases. + def resolve_named(name, seen = {}) + return OPAQUE if name.nil? || seen[name] + + seen[name] = true + type = @types[name] + return OPAQUE unless type + + case type['kind'] + when 'record' then type['fields'].empty? ? OPAQUE : named_type(name) + when 'union' then named_type(name) + when 'enum' then {ref: nil, list: false, rbs: 'Symbol'} + when 'alias' then resolve_named_alias(name, type['type'], seen) + else OPAQUE + end + end + + # A named structured type's serialization ref (nil for a dotless/global type, never + # emitted as a class) and its absolute RBS class path, derived independently so each + # output keeps its own treatment of dotless names. + def named_type(name) + {ref: domain_path(name), list: false, rbs: rbs_abs(ruby_path(name))} + end + + def resolve_named_alias(name, inner, seen) + return named_type(name) if inner.key?('union') + return resolve_named(inner['ref'], seen) if inner.key?('ref') + + if inner.key?('list') + element = resolve(inner['list']) + return {ref: element[:ref], list: true, rbs: "Array[#{element[:rbs]}]"} + end + + {ref: nil, list: false, rbs: scalar_rbs(inner)} + end + + def nilable(type, flag) + flag ? BiDiGenerate.rbs_nilable(type) : type + end + + def record_class(name, type) + const = type['fields'].find { |f| baked_discriminator?(f) } + discriminator = const && {ruby_name: BiDiGenerate.safe_field_name(BiDiGenerate.camel_to_snake(const['name'])), + wire: const['wire'], value: const['type']['const']} + fields = type['fields'].reject { |f| baked_discriminator?(f) }.map { |f| field_ir(f) } + TypeClass.new(ruby_name: BiDiGenerate.type_class_name(name), fields: fields, + discriminator: discriminator, extensible: type['extensible'] ? true : false, + schema_name: name, synthetic: type['synthetic'] ? true : false, + owner: type['owner'], label: type['label']) + end + + # A const field is a baked discriminator tag, unless it is also nullable: the spec's + # `literal | null` (browsingContext.setBypassCSP, emulation.setScriptingEnabled) is a + # settable value (the literal to set, null to clear), so it stays a normal field that + # can serialize null rather than a fixed tag that can only ever emit the literal. + def baked_discriminator?(field) + field['type'].key?('const') && !field['type']['nullable'] + end + + def field_ir(field) + resolved = resolve(field['type']) + ruby_name = BiDiGenerate.safe_field_name(BiDiGenerate.camel_to_snake(field['name'])) + FieldIR.new(ruby_name: ruby_name, json_key: field['wire'], + required: field['required'], nullable: resolved[:nullable], + ref: resolved[:ref], list: resolved[:list], enum: enum_const(field['type']), + rbs: resolved[:rbs]) + end + + def union_class(name) + type = @types[name] + # A first-class union carries the schema's authoritative dispatch `selector` + # (derived spec-faithfully, including null discriminators and the spec's choice + # order); consume it rather than re-deriving and silently depending on emit + # order. An alias-to-union (only input.Origin) has no selector — its const-string + # arms aren't first-class types — so it keeps the structural re-derivation. + type['kind'] == 'union' ? union_from_selector(name, type['selector']) : union_from_alias(name) + end + + # Map a union `selector` to dispatch variants the template renders: + # { by, variants, default? } -> a discriminator table (value => ref), `default` + # as the fallback (it may itself be a union, which finishes the dispatch). + # { ordered: [{ ref, requires }] } -> presence rules in the spec's choice order. + # { correlated: true } -> resolved by request id, not the payload, so no payload + # dispatch. Unreachable here: every correlated union is a top-level result + # grouping, never domain-scoped, so it is never emitted as a class. + def union_from_selector(name, selector) + # A correlated union is resolved by request id, never the payload, so it carries + # no dispatch — it must never be emitted (every one is a top-level result + # grouping). Fail loudly if a future schema makes one domain-scoped rather than + # emit a Union whose every parse would raise. + if selector['correlated'] + raise "correlated union #{name} must not be emitted (resolved by request id, not payload)" + end + + variants = selector['by'] ? discriminated_variants(selector) : ordered_variants(selector) + raise "union #{name} selector yielded no dispatch variants" if variants.empty? + + UnionClass.new(ruby_name: BiDiGenerate.type_class_name(name), + discriminator_wire: selector['by'], variants: variants, schema_name: name) + end + + def discriminated_variants(selector) + variants = selector['variants'].map do |variant| + VariantIR.new(mode: :value, value: variant['value'], ref: ruby_path(variant['ref']), requires: nil) + end + return variants unless selector['default'] + + variants << VariantIR.new(mode: :fallback, value: nil, ref: ruby_path(selector['default']), requires: nil) + end + + def ordered_variants(selector) + (selector['ordered'] || []).map do |arm| + VariantIR.new(mode: :presence, value: nil, ref: ruby_path(arm['ref']), requires: arm['requires']) + end + end + + # The sole alias-union is input.Origin ("viewport" | "pointer" | ElementOrigin): a + # scalar-or-object union the object-payload selector model doesn't cover, so the + # projector leaves it an alias with no selector. Its object arm(s) carry a const + # discriminator; the bare-string arms need no dispatch (Union.from_json returns a + # non-Hash payload unchanged). So dispatch the ref arms by their const tag. + def union_from_alias(name) + consts = @types[name]['type']['union'].filter_map { |arm| arm['ref'] }.to_h do |ref| + const = @types[ref]['fields'].find { |f| f['type'].key?('const') } + const || raise("alias-union #{name} arm #{ref} has no const discriminator to dispatch on") + [ref, const] + end + variants = consts.map do |ref, const| + VariantIR.new(mode: :value, value: const['type']['const'], ref: ruby_path(ref), requires: nil) + end + UnionClass.new(ruby_name: BiDiGenerate.type_class_name(name), + discriminator_wire: consts.values.first['wire'], variants: variants, schema_name: name) + end + + def record_params(fields) + fields.map do |field| + Param.new( + ruby_name: BiDiGenerate.safe_field_name(BiDiGenerate.camel_to_snake(field['name'])), + wire_name: field['wire'], + required: field['required'], + enum: enum_const(field['type']), + rbs: rbs_type(field['type']) + ) + end + end + + def rbs_type(node) + resolve(node)[:rbs] + end + + PRIMITIVE_RBS = { + 'string' => 'String', 'number' => 'Numeric', 'integer' => 'Integer', + 'boolean' => 'bool', 'null' => 'nil', 'unknown' => 'untyped' + }.freeze + + # The leaf of +resolve+: the bare scalar type, before any nullable wrap. An alias's + # own nullable is intentionally left off — only the referencing node's is applied. + def scalar_rbs(node) + return PRIMITIVE_RBS.fetch(node['primitive'], 'untyped') if node.key?('primitive') + return rbs_const(node['const']) if node.key?('const') + + 'untyped' + end + + def rbs_const(value) + case value + when true, false then 'bool' + when ::String then 'String' + when ::Numeric then 'Numeric' + else 'untyped' + end + end + + def rbs_abs(path) + "::Selenium::WebDriver::BiDi::Protocol::#{path}" + end + + # The allowed-values constant path when a field (or a list's element) is an enum + # type, else nil. Union command-params skip this (their merged superset can blur a + # discriminator's const vs enum); only flat record params get the outbound check. + def enum_const(field_type) + ref = field_type['ref'] || field_type.dig('list', 'ref') + return unless ref && @types[ref] && @types[ref]['kind'] == 'enum' + + BiDiGenerate.enum_const_path(ref) + end + + # Merge a union's record variants into one flat param list for the command + # signature. A field is only required when every variant declares it required; + # variant-specific fields become optional. The command body dispatches these + # kwargs to the matching variant via `Union.build`, whose typed `as_json` handles + # null-vs-absent — so no nullable allowlist is needed. + def union_params(type, ref = nil) + variants = type['variants'].map { |variant_ref| @types[variant_ref] } + return nil unless variants.all? { |v| v && v['kind'] == 'record' } + + selector = type['selector'] + guard_union_dispatch_keys_simple!(selector, ref) + params = merged_params(variants.map { |v| v['fields'] }) + annotate_discriminator_enum!(params, selector) + params + end + + # A discriminated union's `by` field is validated against the whole allowed set: + # the const values that tag each variant plus the default variant's own enum + # values (e.g. continueWithAuth.action = {provideCredentials} + {default, cancel}). + # That spans variants, so no single enum constant fits — emit an inline symbol=>wire + # hash so the check accepts the idiomatic symbol like every other enum. + # Boolean discriminators (handleRequestDevicePrompt.accept) need no membership check. + def annotate_discriminator_enum!(params, selector) + by = selector['by'] + tagged = by ? selector['variants'].map { |v| v['value'] } : [] + return unless !tagged.empty? && tagged.all?(String) + + allowed = (tagged + default_variant_enum_values(selector, by)).uniq + pairs = allowed.map { |v| "#{BiDiGenerate.enum_key(v)}: '#{v}'" } + param = params.find { |p| p.wire_name == by } + return unless param + + param.enum = "{#{pairs.join(', ')}}" + param.rbs = 'Symbol' + end + + def default_variant_enum_values(selector, by) + default = selector['default'] + field = default && @types[default]['fields'].find { |f| f['wire'] == by } + ref = field && field['type']['ref'] + ref && @types[ref] && @types[ref]['kind'] == 'enum' ? @types[ref]['values'] : [] + end + + # Merge variant field lists into one flat param superset. A field is required only + # when every variant declares it required; variant-specific fields become optional. + def merged_params(variant_fields) + all_fields = variant_fields.flatten + all_fields.map { |f| f['wire'] }.uniq.map do |wire| + field = all_fields.find { |f| f['wire'] == wire } + required = variant_fields.all? { |fields| fields.any? { |f| f['wire'] == wire && f['required'] } } + Param.new(ruby_name: BiDiGenerate.safe_field_name(BiDiGenerate.camel_to_snake(field['name'])), + wire_name: wire, required: required, rbs: rbs_type(field['type'])) + end + end + + # `Union.build` matches the command's kwargs to the selector's dispatch keys by + # symbol, which holds only while each dispatch wire key equals its ruby kwarg. + # Every current key is a single lowercase word; fail generation if a new one is + # camelCase so the outbound dispatch gets an explicit wire<->ruby mapping then. + def guard_union_dispatch_keys_simple!(selector, ref) + keys = selector['by'] ? [selector['by']] : (selector['ordered'] || []).flat_map { |arm| arm['requires'] } + camel = keys.reject { |k| BiDiGenerate.camel_to_snake(k) == k } + return if camel.empty? + + raise "union command param #{ref} dispatches on non-snake wire key(s) #{camel.inspect}; " \ + 'Union.build matches kwargs to dispatch keys by symbol, so give the outbound ' \ + 'dispatch an explicit wire<->ruby mapping before shipping this.' + end + end + + # Param kinds the named args can construct a Parameters object for (record fields, + # or a union dispatched to one of its variants); anything else forwards a raw hash. + PARAMS_CLASS_KINDS = %w[record union].freeze + + def self.build_ir(schema) + schema.domains.map do |domain| + Module.new( + name: domain, + ruby_class: snake_to_class_name(camel_to_snake(domain)), + filename: camel_to_snake(domain), + commands: schema.commands_for(domain).map { |cmd| build_command(schema, cmd) }, + events: schema.events_for(domain).map { |ev| build_event(schema, ev) }, + enums: schema.enums_for(domain), + types: nest_synthetic(schema.types_for(domain)) + ) + end + end + + def self.build_command(schema, cmd) + params = schema.params_for(cmd['params']) + # A param that can't flatten to a typed object (alias or non-record union) would be + # silently dropped, so fail generation and handle that shape deliberately if it appears. + if cmd['params'] && params.nil? + raise "command #{cmd['method']} has params that cannot be expressed as a typed object" + end + + params_ref = cmd['params'] && cmd['params']['ref'] + params_kind = schema.type_kind(params_ref) + params_class = type_class_name(params_ref) if !params.empty? && PARAMS_CLASS_KINDS.include?(params_kind) + Command.new( + wire_name: cmd['method'], + method_name: safe_method_name(camel_to_snake(cmd['name'])), + params: params, + result_ref: cmd['result'] && schema.structured_ref(cmd['result']['ref']), + params_class: params_class, + union_params: params_kind == 'union' + ) + end + + def self.build_event(schema, event) + params = event['params'] + payload_ref = params && params['ref'] && schema.structured_ref(params['ref']) + Event.new(wire_name: event['method'], event_name: camel_to_snake(event['name']), payload_ref: payload_ref) + end + + # The projector tags lifted-out types with {synthetic, owner, label}. Emit each + # synthetic record inside its owner's class body under its bare label, so + # `Owner_Label` becomes the nested `Owner::Label` (refs resolve there via + # ruby_path). Synthetic enums stay domain-level. Raises on a missing owner. + def self.nest_synthetic(types) + index = types.to_h { |t| [t.schema_name, t] } + children = types.select { |t| !t.union? && t.synthetic } + children.each do |child| + owner = index[child.owner] || + raise("synthetic type #{child.schema_name} has no emitted owner #{child.owner}") + owner.nested = (owner.nested || []) << child + child.ruby_name = child.label + end + types - children + end + + def self.render(mod, template_path) + ERB.new(File.read(template_path), trim_mode: '-').result(binding) + end + + def self.call(schema_path, output_dir) + raw = load_json(schema_path) + schema = Schema.new(raw) + modules = build_ir(schema) + + emit(modules, output_dir, 'module.rb.erb', 'rb') + emit(modules, sig_dir(output_dir), 'module.rbs.erb', 'rbs') + end + + # Renders every module through one template and writes the result into target, + # one file per module. Used for both the Ruby source and its RBS signatures. + def self.emit(modules, output_dir, template, extension) + target = File.join(workspace_root, output_dir) + FileUtils.mkdir_p(target) + + tmpl = File.join(File.dirname(__FILE__), 'templates', template) + modules.each do |mod| + path = File.join(target, "#{mod.filename}.#{extension}") + File.write(path, render(mod, tmpl)) + warn "bidi-generate: wrote #{path}" + end + end + + # The RBS signatures mirror the source tree under sig/ (the repo's convention), + # e.g. rb/lib/.../protocol -> rb/sig/lib/.../protocol. + def self.sig_dir(output_dir) + output_dir.sub(%r{(\A|/)lib/}, '\1sig/lib/') + end + + private_class_method def self.load_json(path) + resolved = File.exist?(path) ? path : File.join(Dir.pwd, path) + JSON.parse(File.read(resolved)) + end + + private_class_method def self.workspace_root + ENV['BUILD_WORKSPACE_DIRECTORY'] || Dir.pwd + end +end + +BiDiGenerate.call(*ARGV) if $PROGRAM_NAME == __FILE__ diff --git a/rb/lib/selenium/webdriver/bidi/support/check_generated.rb b/rb/lib/selenium/webdriver/bidi/support/check_generated.rb new file mode 100644 index 0000000000000..3f4d1e7bbbce6 --- /dev/null +++ b/rb/lib/selenium/webdriver/bidi/support/check_generated.rb @@ -0,0 +1,52 @@ +# 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. + +require 'json' +require_relative 'bidi_generate' + +module BiDiGenerate + # Verifies the checked-in protocol .rb match what the generator would produce from the + # current schema — catching a hand-edit or a forgotten regeneration. Re-renders each module + # in memory (no file writes) and compares. The .rbs are covered by Steep. + def self.check!(schema_rootpath) + modules = build_ir(Schema.new(JSON.parse(File.read(schema_path(schema_rootpath))))) + protocol_dir = File.expand_path('../protocol', __dir__) + template = File.join(__dir__, 'templates', 'module.rb.erb') + + stale = modules.reject do |mod| + path = File.join(protocol_dir, "#{mod.filename}.rb") + File.exist?(path) && File.read(path) == render(mod, template) + end + return if stale.empty? + + warn "Generated BiDi protocol code is stale or hand-edited: #{stale.map { |m| "#{m.filename}.rb" }.sort.join(', ')}" + warn 'Regenerate with: bazel run //rb/lib/selenium/webdriver:bidi-generate' + exit 1 + end + + # $(rootpath) is relative to the runfiles root; __dir__ anchors us there, so it resolves the + # same way locally and on RBE (an execpath would not). + def self.schema_path(rootpath) + root = __dir__.delete_suffix('/rb/lib/selenium/webdriver/bidi/support') + [File.join(root, rootpath), rootpath].find { |p| File.exist?(p) } || + raise("BiDi schema not found (looked for #{rootpath})") + end +end + +BiDiGenerate.check!(ARGV.fetch(0)) if $PROGRAM_NAME == __FILE__ diff --git a/rb/lib/selenium/webdriver/bidi/support/templates/module.rb.erb b/rb/lib/selenium/webdriver/bidi/support/templates/module.rb.erb new file mode 100644 index 0000000000000..3cb30e0dfbad6 --- /dev/null +++ b/rb/lib/selenium/webdriver/bidi/support/templates/module.rb.erb @@ -0,0 +1,110 @@ +# 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. + +# This file is automatically generated. DO NOT EDIT! +# Regenerate with: bazel run //rb/lib/selenium/webdriver:bidi-generate + +module Selenium + module WebDriver + class BiDi + module Protocol + # @api private + # @see <%= BiDiGenerate::BIDI_DOC_URL %> + class <%= mod.ruby_class %> < Domain +<%- unless mod.events.empty? -%> + EVENTS = { + <%= mod.events.map { |event| "#{event.event_name}: '#{event.wire_name}'" }.join(",\n ") %> + }.freeze + +<%- end -%> +<%- mod.enums.each do |enum| -%> + <%= enum.constant_name %> = { + <%= enum.pairs.map { |key, wire_val| "#{key}: '#{wire_val}'" }.join(",\n ") %> + }.freeze + +<%- end -%> +<%- mod.types.each do |type| -%> +<%- if type.union? -%> + # @api private + # @see <%= BiDiGenerate::BIDI_DOC_URL %> + class <%= type.ruby_name %> < Serialization::Union +<%- if type.discriminator_wire && !type.value_variants.empty? -%> + <%= type.discriminator_decl(12) %> + variants( + <%= type.value_variants.map(&:variant_entry).join(",\n ") %> + ) +<%- end -%> +<%- unless type.presence_variants.empty? -%> + presence( + <%= type.presence_variants.map { |v| "'#{v.ref}' => [#{v.requires.map { |w| "'#{w}'" }.join(', ')}]" }.join(",\n ") %> + ) +<%- end -%> +<%- if type.fallback_variant -%> + fallback '<%= type.fallback_variant.ref %>' +<%- end -%> +<%- type.nested_types.each do |nested| -%> + + # @api private + # @see <%= BiDiGenerate::BIDI_DOC_URL %> + <%= nested.define_assignment(nested.ruby_name, 12) %> +<%- end -%> + end + +<%- else -%> + # @api private + # @see <%= BiDiGenerate::BIDI_DOC_URL %> + <%= type.define_assignment(type.ruby_name, 10) %> +<%- type.nested_types.each do |nested| -%> + + # @api private + # @see <%= BiDiGenerate::BIDI_DOC_URL %> + <%= nested.define_assignment("#{type.ruby_name}::#{nested.ruby_name}", 10) %> +<%- end -%> + +<%- end -%> +<%- end -%> +<%- unless mod.events.empty? -%> + EVENT_TYPES = { + <%= mod.events.map(&:type_entry).join(",\n ") %> + }.freeze +<%- unless mod.commands.empty? -%> + +<%- end -%> +<%- end -%> +<%- mod.commands.each_with_index do |cmd, index| -%> +<%- unless index.zero? -%> + +<%- end -%> + # @api private + # @see <%= BiDiGenerate::BIDI_DOC_URL %> + <%= cmd.def_header(10) %> +<%- cmd.enum_checks(12).each do |check| -%> + <%= check %> +<%- end -%> +<%- if cmd.params_assignment(12) -%> + <%= cmd.params_assignment(12) %> +<%- end -%> + <%= cmd.execute_call(12) %> + end +<%- end -%> + end # <%= mod.ruby_class %> + end # Protocol + end # BiDi + end # WebDriver +end # Selenium diff --git a/rb/lib/selenium/webdriver/bidi/support/templates/module.rbs.erb b/rb/lib/selenium/webdriver/bidi/support/templates/module.rbs.erb new file mode 100644 index 0000000000000..f3e4e2ee1277b --- /dev/null +++ b/rb/lib/selenium/webdriver/bidi/support/templates/module.rbs.erb @@ -0,0 +1,77 @@ +# 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. + +# This file is automatically generated. DO NOT EDIT! +# Regenerate with: bazel run //rb/lib/selenium/webdriver:bidi-generate + +module Selenium + module WebDriver + class BiDi + module Protocol + class <%= mod.ruby_class %> < ::Selenium::WebDriver::BiDi::Protocol::Domain +<%- unless mod.events.empty? -%> + EVENTS: Hash[Symbol, String] + +<%- end -%> +<%- mod.enums.each do |enum| -%> + <%= enum.constant_name %>: Hash[Symbol, String] + +<%- end -%> +<%- mod.types.each do |type| -%> +<%- if type.union? -%> + class <%= type.ruby_name %> < ::Selenium::WebDriver::BiDi::Serialization::Union +<%- type.nested_types.each do |nested| -%> + class <%= nested.ruby_name %> < ::Selenium::WebDriver::BiDi::Serialization::Record +<%- nested.rbs_readers.each do |reader| -%> + attr_reader <%= reader %> +<%- end -%> + def self.new: (<%= nested.rbs_new_args %>) -> instance + end +<%- end -%> + end + +<%- else -%> + class <%= type.ruby_name %> < ::Selenium::WebDriver::BiDi::Serialization::Record +<%- type.rbs_readers.each do |reader| -%> + attr_reader <%= reader %> +<%- end -%> + def self.new: (<%= type.rbs_new_args %>) -> instance +<%- type.nested_types.each do |nested| -%> + + class <%= nested.ruby_name %> < ::Selenium::WebDriver::BiDi::Serialization::Record +<%- nested.rbs_readers.each do |reader| -%> + attr_reader <%= reader %> +<%- end -%> + def self.new: (<%= nested.rbs_new_args %>) -> instance + end +<%- end -%> + end + +<%- end -%> +<%- end -%> +<%- unless mod.events.empty? -%> + EVENT_TYPES: Hash[String, untyped] + +<%- end -%> +<%- mod.commands.each do |cmd| -%> + def <%= cmd.method_name %>: <%= cmd.rbs_signature %> +<%- end -%> + end + end + end + end +end diff --git a/rb/lib/selenium/webdriver/bidi/transport.rb b/rb/lib/selenium/webdriver/bidi/transport.rb new file mode 100644 index 0000000000000..c22ad147032df --- /dev/null +++ b/rb/lib/selenium/webdriver/bidi/transport.rb @@ -0,0 +1,52 @@ +# 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 + # The seam between the generated Protocol layer and the websocket: serializes a + # command's params, sends it, and parses the reply into its declared type. + # + # @api private + class Transport + def initialize(connection) + @connection = connection + end + + def execute(cmd:, params: nil, result: nil) + reply = @connection.send_cmd(method: cmd, params: serialize(params)) + raise Error::WebDriverError, error_message(reply) if reply['error'] + + value = reply['result'] + result ? result.from_json(value) : value + end + + private + + def serialize(params) + params&.as_json || {} + end + + def error_message(reply) + "#{reply['error']}: #{reply['message']}\n#{reply['stacktrace']}" + end + end # Transport + end # BiDi + end # WebDriver +end # Selenium diff --git a/rb/lib/selenium/webdriver/remote/bidi_bridge.rb b/rb/lib/selenium/webdriver/remote/bidi_bridge.rb index fe5d3e8cc6677..38e3dcf1d7981 100644 --- a/rb/lib/selenium/webdriver/remote/bidi_bridge.rb +++ b/rb/lib/selenium/webdriver/remote/bidi_bridge.rb @@ -17,16 +17,21 @@ # specific language governing permissions and limitations # under the License. +require 'selenium/webdriver/bidi' +require 'selenium/webdriver/bidi/transport' + module Selenium module WebDriver module Remote class BiDiBridge < Bridge - attr_reader :bidi + attr_reader :bidi, :transport def create_session(capabilities) super socket_url = @capabilities[:web_socket_url] @bidi = Selenium::WebDriver::BiDi.new(url: socket_url) + # Share the BiDi object's socket until the bridge owns the connection directly. + @transport = BiDi::Transport.new(@bidi.ws) end def get(url) diff --git a/rb/lib/selenium/webdriver/remote/bridge.rb b/rb/lib/selenium/webdriver/remote/bridge.rb index 7db5d3b759386..951890ef9eaa7 100644 --- a/rb/lib/selenium/webdriver/remote/bridge.rb +++ b/rb/lib/selenium/webdriver/remote/bridge.rb @@ -598,6 +598,11 @@ def bidi raise(WebDriver::Error::WebDriverError, msg) end + def transport + msg = 'BiDi must be enabled by setting #web_socket_url to true in options class' + raise(WebDriver::Error::WebDriverError, msg) + end + def command_list COMMANDS end diff --git a/rb/sig/lib/selenium/webdriver/bidi.rbs b/rb/sig/lib/selenium/webdriver/bidi.rbs index 617d086aac432..2e878c5d80a43 100644 --- a/rb/sig/lib/selenium/webdriver/bidi.rbs +++ b/rb/sig/lib/selenium/webdriver/bidi.rbs @@ -23,6 +23,8 @@ module Selenium @session: Session + attr_reader ws: WebSocketConnection + def initialize: (url: String) -> void def add_callback: (String | Symbol event) { () -> void } -> Integer diff --git a/rb/sig/lib/selenium/webdriver/bidi/protocol/bluetooth.rbs b/rb/sig/lib/selenium/webdriver/bidi/protocol/bluetooth.rbs new file mode 100644 index 0000000000000..54d387853836f --- /dev/null +++ b/rb/sig/lib/selenium/webdriver/bidi/protocol/bluetooth.rbs @@ -0,0 +1,242 @@ +# 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. + +# This file is automatically generated. DO NOT EDIT! +# Regenerate with: bazel run //rb/lib/selenium/webdriver:bidi-generate + +module Selenium + module WebDriver + class BiDi + module Protocol + class Bluetooth < ::Selenium::WebDriver::BiDi::Protocol::Domain + EVENTS: Hash[Symbol, String] + + SIMULATE_ADAPTER_PARAMETERS_STATE: Hash[Symbol, String] + + SIMULATE_SERVICE_PARAMETERS_TYPE: Hash[Symbol, String] + + SIMULATE_CHARACTERISTIC_PARAMETERS_TYPE: Hash[Symbol, String] + + SIMULATE_CHARACTERISTIC_RESPONSE_PARAMETERS_TYPE: Hash[Symbol, String] + + SIMULATE_DESCRIPTOR_PARAMETERS_TYPE: Hash[Symbol, String] + + SIMULATE_DESCRIPTOR_RESPONSE_PARAMETERS_TYPE: Hash[Symbol, String] + + CHARACTERISTIC_EVENT_GENERATED_PARAMETERS_TYPE: Hash[Symbol, String] + + DESCRIPTOR_EVENT_GENERATED_PARAMETERS_TYPE: Hash[Symbol, String] + + class BluetoothManufacturerData < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader key: Integer + attr_reader data: String + def self.new: (key: Integer, data: String) -> instance + end + + class CharacteristicProperties < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader broadcast: untyped + attr_reader read: untyped + attr_reader write_without_response: untyped + attr_reader write: untyped + attr_reader notify: untyped + attr_reader indicate: untyped + attr_reader authenticated_signed_writes: untyped + attr_reader extended_properties: untyped + def self.new: (?broadcast: bool?, ?read: bool?, ?write_without_response: bool?, ?write: bool?, ?notify: bool?, ?indicate: bool?, ?authenticated_signed_writes: bool?, ?extended_properties: bool?) -> instance + end + + class RequestDeviceInfo < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader id: String + attr_reader name: String? + def self.new: (id: String, name: String?) -> instance + end + + class ScanRecord < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader name: untyped + attr_reader uuids: untyped + attr_reader appearance: untyped + attr_reader manufacturer_data: untyped + def self.new: (?name: String?, ?uuids: Array[String]?, ?appearance: Numeric?, ?manufacturer_data: Array[::Selenium::WebDriver::BiDi::Protocol::Bluetooth::BluetoothManufacturerData]?) -> instance + end + + class HandleRequestDevicePromptParameters < ::Selenium::WebDriver::BiDi::Serialization::Union + class AcceptParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader accept: untyped + attr_reader context: String + attr_reader prompt: String + attr_reader device: String + def self.new: (?accept: untyped, context: String, prompt: String, device: String) -> instance + end + class CancelParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader accept: untyped + attr_reader context: String + attr_reader prompt: String + def self.new: (?accept: untyped, context: String, prompt: String) -> instance + end + end + + class SimulateAdapterParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader context: String + attr_reader le_supported: untyped + attr_reader state: Symbol + def self.new: (context: String, ?le_supported: bool?, state: Symbol) -> instance + end + + class DisableSimulationParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader context: String + def self.new: (context: String) -> instance + end + + class SimulatePreconnectedPeripheralParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader context: String + attr_reader address: String + attr_reader name: String + attr_reader manufacturer_data: Array[::Selenium::WebDriver::BiDi::Protocol::Bluetooth::BluetoothManufacturerData] + attr_reader known_service_uuids: Array[String] + def self.new: (context: String, address: String, name: String, manufacturer_data: Array[::Selenium::WebDriver::BiDi::Protocol::Bluetooth::BluetoothManufacturerData], known_service_uuids: Array[String]) -> instance + end + + class SimulateAdvertisementParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader context: String + attr_reader scan_entry: ::Selenium::WebDriver::BiDi::Protocol::Bluetooth::SimulateAdvertisementScanEntryParameters + def self.new: (context: String, scan_entry: ::Selenium::WebDriver::BiDi::Protocol::Bluetooth::SimulateAdvertisementScanEntryParameters) -> instance + end + + class SimulateAdvertisementScanEntryParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader device_address: String + attr_reader rssi: Numeric + attr_reader scan_record: ::Selenium::WebDriver::BiDi::Protocol::Bluetooth::ScanRecord + def self.new: (device_address: String, rssi: Numeric, scan_record: ::Selenium::WebDriver::BiDi::Protocol::Bluetooth::ScanRecord) -> instance + end + + class SimulateGattConnectionResponseParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader context: String + attr_reader address: String + attr_reader code: Integer + def self.new: (context: String, address: String, code: Integer) -> instance + end + + class SimulateGattDisconnectionParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader context: String + attr_reader address: String + def self.new: (context: String, address: String) -> instance + end + + class SimulateServiceParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader context: String + attr_reader address: String + attr_reader uuid: String + attr_reader type: Symbol + def self.new: (context: String, address: String, uuid: String, type: Symbol) -> instance + end + + class SimulateCharacteristicParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader context: String + attr_reader address: String + attr_reader service_uuid: String + attr_reader characteristic_uuid: String + attr_reader characteristic_properties: untyped + attr_reader type: Symbol + def self.new: (context: String, address: String, service_uuid: String, characteristic_uuid: String, ?characteristic_properties: ::Selenium::WebDriver::BiDi::Protocol::Bluetooth::CharacteristicProperties?, type: Symbol) -> instance + end + + class SimulateCharacteristicResponseParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader context: String + attr_reader address: String + attr_reader service_uuid: String + attr_reader characteristic_uuid: String + attr_reader type: Symbol + attr_reader code: Integer + attr_reader data: untyped + def self.new: (context: String, address: String, service_uuid: String, characteristic_uuid: String, type: Symbol, code: Integer, ?data: Array[Integer]?) -> instance + end + + class SimulateDescriptorParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader context: String + attr_reader address: String + attr_reader service_uuid: String + attr_reader characteristic_uuid: String + attr_reader descriptor_uuid: String + attr_reader type: Symbol + def self.new: (context: String, address: String, service_uuid: String, characteristic_uuid: String, descriptor_uuid: String, type: Symbol) -> instance + end + + class SimulateDescriptorResponseParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader context: String + attr_reader address: String + attr_reader service_uuid: String + attr_reader characteristic_uuid: String + attr_reader descriptor_uuid: String + attr_reader type: Symbol + attr_reader code: Integer + attr_reader data: untyped + def self.new: (context: String, address: String, service_uuid: String, characteristic_uuid: String, descriptor_uuid: String, type: Symbol, code: Integer, ?data: Array[Integer]?) -> instance + end + + class RequestDevicePromptUpdatedParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader context: String + attr_reader prompt: String + attr_reader devices: Array[::Selenium::WebDriver::BiDi::Protocol::Bluetooth::RequestDeviceInfo] + def self.new: (context: String, prompt: String, devices: Array[::Selenium::WebDriver::BiDi::Protocol::Bluetooth::RequestDeviceInfo]) -> instance + end + + class GattConnectionAttemptedParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader context: String + attr_reader address: String + def self.new: (context: String, address: String) -> instance + end + + class CharacteristicEventGeneratedParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader context: String + attr_reader address: String + attr_reader service_uuid: String + attr_reader characteristic_uuid: String + attr_reader type: Symbol + attr_reader data: untyped + def self.new: (context: String, address: String, service_uuid: String, characteristic_uuid: String, type: Symbol, ?data: Array[Integer]?) -> instance + end + + class DescriptorEventGeneratedParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader context: String + attr_reader address: String + attr_reader service_uuid: String + attr_reader characteristic_uuid: String + attr_reader descriptor_uuid: String + attr_reader type: Symbol + attr_reader data: untyped + def self.new: (context: String, address: String, service_uuid: String, characteristic_uuid: String, descriptor_uuid: String, type: Symbol, ?data: Array[Integer]?) -> instance + end + + EVENT_TYPES: Hash[String, untyped] + + def handle_request_device_prompt: (context: String, prompt: String, accept: bool, ?device: String?) -> untyped + def simulate_adapter: (context: String, state: Symbol, ?le_supported: bool?) -> untyped + def disable_simulation: (context: String) -> untyped + def simulate_preconnected_peripheral: (context: String, address: String, name: String, manufacturer_data: Array[::Selenium::WebDriver::BiDi::Protocol::Bluetooth::BluetoothManufacturerData], known_service_uuids: Array[String]) -> untyped + def simulate_advertisement: (context: String, scan_entry: ::Selenium::WebDriver::BiDi::Protocol::Bluetooth::SimulateAdvertisementScanEntryParameters) -> untyped + def simulate_gatt_connection_response: (context: String, address: String, code: Integer) -> untyped + def simulate_gatt_disconnection: (context: String, address: String) -> untyped + def simulate_service: (context: String, address: String, uuid: String, type: Symbol) -> untyped + def simulate_characteristic: (context: String, address: String, service_uuid: String, characteristic_uuid: String, type: Symbol, ?characteristic_properties: ::Selenium::WebDriver::BiDi::Protocol::Bluetooth::CharacteristicProperties?) -> untyped + def simulate_characteristic_response: (context: String, address: String, service_uuid: String, characteristic_uuid: String, type: Symbol, code: Integer, ?data: Array[Integer]?) -> untyped + def simulate_descriptor: (context: String, address: String, service_uuid: String, characteristic_uuid: String, descriptor_uuid: String, type: Symbol) -> untyped + def simulate_descriptor_response: (context: String, address: String, service_uuid: String, characteristic_uuid: String, descriptor_uuid: String, type: Symbol, code: Integer, ?data: Array[Integer]?) -> untyped + end + end + end + end +end diff --git a/rb/sig/lib/selenium/webdriver/bidi/protocol/browser.rbs b/rb/sig/lib/selenium/webdriver/bidi/protocol/browser.rbs new file mode 100644 index 0000000000000..9e7ea0f296df4 --- /dev/null +++ b/rb/sig/lib/selenium/webdriver/bidi/protocol/browser.rbs @@ -0,0 +1,114 @@ +# 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. + +# This file is automatically generated. DO NOT EDIT! +# Regenerate with: bazel run //rb/lib/selenium/webdriver:bidi-generate + +module Selenium + module WebDriver + class BiDi + module Protocol + class Browser < ::Selenium::WebDriver::BiDi::Protocol::Domain + CLIENT_WINDOW_INFO_STATE: Hash[Symbol, String] + + CLIENT_WINDOW_NAMED_STATE_STATE: Hash[Symbol, String] + + class ClientWindowInfo < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader active: bool + attr_reader client_window: String + attr_reader height: Integer + attr_reader state: Symbol + attr_reader width: Integer + attr_reader x: Integer + attr_reader y: Integer + def self.new: (active: bool, client_window: String, height: Integer, state: Symbol, width: Integer, x: Integer, y: Integer) -> instance + end + + class UserContextInfo < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader user_context: String + def self.new: (user_context: String) -> instance + end + + class CreateUserContextParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader accept_insecure_certs: untyped + attr_reader proxy: untyped + attr_reader unhandled_prompt_behavior: untyped + def self.new: (?accept_insecure_certs: bool?, ?proxy: ::Selenium::WebDriver::BiDi::Protocol::Session::ProxyConfiguration?, ?unhandled_prompt_behavior: ::Selenium::WebDriver::BiDi::Protocol::Session::UserPromptHandler?) -> instance + end + + class GetClientWindowsResult < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader client_windows: Array[::Selenium::WebDriver::BiDi::Protocol::Browser::ClientWindowInfo] + def self.new: (client_windows: Array[::Selenium::WebDriver::BiDi::Protocol::Browser::ClientWindowInfo]) -> instance + end + + class GetUserContextsResult < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader user_contexts: Array[::Selenium::WebDriver::BiDi::Protocol::Browser::UserContextInfo] + def self.new: (user_contexts: Array[::Selenium::WebDriver::BiDi::Protocol::Browser::UserContextInfo]) -> instance + end + + class RemoveUserContextParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader user_context: String + def self.new: (user_context: String) -> instance + end + + class SetClientWindowStateParameters < ::Selenium::WebDriver::BiDi::Serialization::Union + class ClientWindowNamedState < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader client_window: String + attr_reader state: Symbol + def self.new: (client_window: String, state: Symbol) -> instance + end + class ClientWindowRectState < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader state: untyped + attr_reader client_window: String + attr_reader width: untyped + attr_reader height: untyped + attr_reader x: untyped + attr_reader y: untyped + def self.new: (?state: untyped, client_window: String, ?width: Integer?, ?height: Integer?, ?x: Integer?, ?y: Integer?) -> instance + end + end + + class SetDownloadBehaviorParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader download_behavior: ::Selenium::WebDriver::BiDi::Protocol::Browser::DownloadBehavior? + attr_reader user_contexts: untyped + def self.new: (download_behavior: ::Selenium::WebDriver::BiDi::Protocol::Browser::DownloadBehavior?, ?user_contexts: Array[String]?) -> instance + end + + class DownloadBehavior < ::Selenium::WebDriver::BiDi::Serialization::Union + class Allowed < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + attr_reader destination_folder: String + def self.new: (?type: untyped, destination_folder: String) -> instance + end + class Denied < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + def self.new: (?type: untyped) -> instance + end + end + + def close: () -> untyped + def create_user_context: (?accept_insecure_certs: bool?, ?proxy: ::Selenium::WebDriver::BiDi::Protocol::Session::ProxyConfiguration?, ?unhandled_prompt_behavior: ::Selenium::WebDriver::BiDi::Protocol::Session::UserPromptHandler?) -> ::Selenium::WebDriver::BiDi::Protocol::Browser::UserContextInfo + def get_client_windows: () -> ::Selenium::WebDriver::BiDi::Protocol::Browser::GetClientWindowsResult + def get_user_contexts: () -> ::Selenium::WebDriver::BiDi::Protocol::Browser::GetUserContextsResult + def remove_user_context: (user_context: String) -> untyped + def set_client_window_state: (client_window: String, state: Symbol, ?width: Integer?, ?height: Integer?, ?x: Integer?, ?y: Integer?) -> ::Selenium::WebDriver::BiDi::Protocol::Browser::ClientWindowInfo + def set_download_behavior: (download_behavior: ::Selenium::WebDriver::BiDi::Protocol::Browser::DownloadBehavior?, ?user_contexts: Array[String]?) -> untyped + end + end + end + end +end diff --git a/rb/sig/lib/selenium/webdriver/bidi/protocol/browsing_context.rbs b/rb/sig/lib/selenium/webdriver/bidi/protocol/browsing_context.rbs new file mode 100644 index 0000000000000..4a994d087e80e --- /dev/null +++ b/rb/sig/lib/selenium/webdriver/bidi/protocol/browsing_context.rbs @@ -0,0 +1,366 @@ +# 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. + +# This file is automatically generated. DO NOT EDIT! +# Regenerate with: bazel run //rb/lib/selenium/webdriver:bidi-generate + +module Selenium + module WebDriver + class BiDi + module Protocol + class BrowsingContext < ::Selenium::WebDriver::BiDi::Protocol::Domain + EVENTS: Hash[Symbol, String] + + READINESS_STATE: Hash[Symbol, String] + + USER_PROMPT_TYPE: Hash[Symbol, String] + + CREATE_TYPE: Hash[Symbol, String] + + INNER_TEXT_LOCATOR_MATCH_TYPE: Hash[Symbol, String] + + CAPTURE_SCREENSHOT_PARAMETERS_ORIGIN: Hash[Symbol, String] + + PRINT_PARAMETERS_ORIENTATION: Hash[Symbol, String] + + class Info < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader children: Array[::Selenium::WebDriver::BiDi::Protocol::BrowsingContext::Info]? + attr_reader client_window: String + attr_reader context: String + attr_reader original_opener: String? + attr_reader url: String + attr_reader user_context: String + attr_reader parent: untyped + def self.new: (children: Array[::Selenium::WebDriver::BiDi::Protocol::BrowsingContext::Info]?, client_window: String, context: String, original_opener: String?, url: String, user_context: String, ?parent: String?) -> instance + end + + class Locator < ::Selenium::WebDriver::BiDi::Serialization::Union + end + + class AccessibilityLocator < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + attr_reader value: ::Selenium::WebDriver::BiDi::Protocol::BrowsingContext::AccessibilityLocator::Value + def self.new: (?type: untyped, value: ::Selenium::WebDriver::BiDi::Protocol::BrowsingContext::AccessibilityLocator::Value) -> instance + + class Value < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader name: untyped + attr_reader role: untyped + def self.new: (?name: String?, ?role: String?) -> instance + end + end + + class CssLocator < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + attr_reader value: String + def self.new: (?type: untyped, value: String) -> instance + end + + class ContextLocator < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + attr_reader value: ::Selenium::WebDriver::BiDi::Protocol::BrowsingContext::ContextLocator::Value + def self.new: (?type: untyped, value: ::Selenium::WebDriver::BiDi::Protocol::BrowsingContext::ContextLocator::Value) -> instance + + class Value < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader context: String + def self.new: (context: String) -> instance + end + end + + class InnerTextLocator < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + attr_reader value: String + attr_reader ignore_case: untyped + attr_reader match_type: untyped + attr_reader max_depth: untyped + def self.new: (?type: untyped, value: String, ?ignore_case: bool?, ?match_type: Symbol?, ?max_depth: Integer?) -> instance + end + + class XPathLocator < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + attr_reader value: String + def self.new: (?type: untyped, value: String) -> instance + end + + class BaseNavigationInfo < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader context: String + attr_reader navigation: String? + attr_reader timestamp: Integer + attr_reader url: String + attr_reader user_context: untyped + def self.new: (context: String, navigation: String?, timestamp: Integer, url: String, ?user_context: String?) -> instance + end + + class NavigationInfo < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader context: String + attr_reader navigation: String? + attr_reader timestamp: Integer + attr_reader url: String + attr_reader user_context: untyped + def self.new: (context: String, navigation: String?, timestamp: Integer, url: String, ?user_context: String?) -> instance + end + + class ActivateParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader context: String + def self.new: (context: String) -> instance + end + + class CaptureScreenshotParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader context: String + attr_reader origin: untyped + attr_reader format: untyped + attr_reader clip: untyped + def self.new: (context: String, ?origin: Symbol?, ?format: ::Selenium::WebDriver::BiDi::Protocol::BrowsingContext::ImageFormat?, ?clip: ::Selenium::WebDriver::BiDi::Protocol::BrowsingContext::ClipRectangle?) -> instance + end + + class ImageFormat < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: String + attr_reader quality: untyped + def self.new: (type: String, ?quality: Integer?) -> instance + end + + class ClipRectangle < ::Selenium::WebDriver::BiDi::Serialization::Union + end + + class ElementClipRectangle < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + attr_reader element: ::Selenium::WebDriver::BiDi::Protocol::Script::SharedReference + def self.new: (?type: untyped, element: ::Selenium::WebDriver::BiDi::Protocol::Script::SharedReference) -> instance + end + + class BoxClipRectangle < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + attr_reader x: Numeric + attr_reader y: Numeric + attr_reader width: Numeric + attr_reader height: Numeric + def self.new: (?type: untyped, x: Numeric, y: Numeric, width: Numeric, height: Numeric) -> instance + end + + class CaptureScreenshotResult < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader data: String + def self.new: (data: String) -> instance + end + + class CloseParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader context: String + attr_reader prompt_unload: untyped + def self.new: (context: String, ?prompt_unload: bool?) -> instance + end + + class CreateParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: Symbol + attr_reader reference_context: untyped + attr_reader background: untyped + attr_reader user_context: untyped + def self.new: (type: Symbol, ?reference_context: String?, ?background: bool?, ?user_context: String?) -> instance + end + + class CreateResult < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader context: String + attr_reader user_context: untyped + def self.new: (context: String, ?user_context: String?) -> instance + end + + class GetTreeParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader max_depth: untyped + attr_reader root: untyped + def self.new: (?max_depth: Integer?, ?root: String?) -> instance + end + + class GetTreeResult < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader contexts: Array[::Selenium::WebDriver::BiDi::Protocol::BrowsingContext::Info] + def self.new: (contexts: Array[::Selenium::WebDriver::BiDi::Protocol::BrowsingContext::Info]) -> instance + end + + class HandleUserPromptParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader context: String + attr_reader accept: untyped + attr_reader user_text: untyped + def self.new: (context: String, ?accept: bool?, ?user_text: String?) -> instance + end + + class LocateNodesParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader context: String + attr_reader locator: ::Selenium::WebDriver::BiDi::Protocol::BrowsingContext::Locator + attr_reader max_node_count: untyped + attr_reader serialization_options: untyped + attr_reader start_nodes: untyped + def self.new: (context: String, locator: ::Selenium::WebDriver::BiDi::Protocol::BrowsingContext::Locator, ?max_node_count: Integer?, ?serialization_options: ::Selenium::WebDriver::BiDi::Protocol::Script::SerializationOptions?, ?start_nodes: Array[::Selenium::WebDriver::BiDi::Protocol::Script::SharedReference]?) -> instance + end + + class LocateNodesResult < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader nodes: Array[::Selenium::WebDriver::BiDi::Protocol::Script::NodeRemoteValue] + def self.new: (nodes: Array[::Selenium::WebDriver::BiDi::Protocol::Script::NodeRemoteValue]) -> instance + end + + class NavigateParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader context: String + attr_reader url: String + attr_reader wait: untyped + def self.new: (context: String, url: String, ?wait: Symbol?) -> instance + end + + class NavigateResult < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader navigation: String? + attr_reader url: String + def self.new: (navigation: String?, url: String) -> instance + end + + class PrintParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader context: String + attr_reader background: untyped + attr_reader margin: untyped + attr_reader orientation: untyped + attr_reader page: untyped + attr_reader page_ranges: untyped + attr_reader scale: untyped + attr_reader shrink_to_fit: untyped + def self.new: (context: String, ?background: bool?, ?margin: ::Selenium::WebDriver::BiDi::Protocol::BrowsingContext::PrintMarginParameters?, ?orientation: Symbol?, ?page: ::Selenium::WebDriver::BiDi::Protocol::BrowsingContext::PrintPageParameters?, ?page_ranges: Array[untyped]?, ?scale: Numeric?, ?shrink_to_fit: bool?) -> instance + end + + class PrintMarginParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader bottom: untyped + attr_reader left: untyped + attr_reader right: untyped + attr_reader top: untyped + def self.new: (?bottom: Numeric?, ?left: Numeric?, ?right: Numeric?, ?top: Numeric?) -> instance + end + + class PrintPageParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader height: untyped + attr_reader width: untyped + def self.new: (?height: Numeric?, ?width: Numeric?) -> instance + end + + class PrintResult < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader data: String + def self.new: (data: String) -> instance + end + + class ReloadParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader context: String + attr_reader ignore_cache: untyped + attr_reader wait: untyped + def self.new: (context: String, ?ignore_cache: bool?, ?wait: Symbol?) -> instance + end + + class SetBypassCSPParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader bypass: bool? + attr_reader contexts: untyped + attr_reader user_contexts: untyped + def self.new: (bypass: bool?, ?contexts: Array[String]?, ?user_contexts: Array[String]?) -> instance + end + + class SetViewportParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader context: untyped + attr_reader viewport: untyped + attr_reader device_pixel_ratio: untyped + attr_reader user_contexts: untyped + def self.new: (?context: String?, ?viewport: ::Selenium::WebDriver::BiDi::Protocol::BrowsingContext::Viewport?, ?device_pixel_ratio: Numeric?, ?user_contexts: Array[String]?) -> instance + end + + class Viewport < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader width: Integer + attr_reader height: Integer + def self.new: (width: Integer, height: Integer) -> instance + end + + class TraverseHistoryParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader context: String + attr_reader delta: Integer + def self.new: (context: String, delta: Integer) -> instance + end + + class HistoryUpdatedParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader context: String + attr_reader timestamp: Integer + attr_reader url: String + attr_reader user_context: untyped + def self.new: (context: String, timestamp: Integer, url: String, ?user_context: String?) -> instance + end + + class DownloadWillBeginParams < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader suggested_filename: String + attr_reader context: String + attr_reader navigation: String? + attr_reader timestamp: Integer + attr_reader url: String + attr_reader user_context: untyped + def self.new: (suggested_filename: String, context: String, navigation: String?, timestamp: Integer, url: String, ?user_context: String?) -> instance + end + + class DownloadEndParams < ::Selenium::WebDriver::BiDi::Serialization::Union + class CanceledParams < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader status: untyped + attr_reader context: String + attr_reader navigation: String? + attr_reader timestamp: Integer + attr_reader url: String + attr_reader user_context: untyped + def self.new: (?status: untyped, context: String, navigation: String?, timestamp: Integer, url: String, ?user_context: String?) -> instance + end + class CompleteParams < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader status: untyped + attr_reader filepath: String? + attr_reader context: String + attr_reader navigation: String? + attr_reader timestamp: Integer + attr_reader url: String + attr_reader user_context: untyped + def self.new: (?status: untyped, filepath: String?, context: String, navigation: String?, timestamp: Integer, url: String, ?user_context: String?) -> instance + end + end + + class UserPromptClosedParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader context: String + attr_reader accepted: bool + attr_reader type: Symbol + attr_reader user_context: untyped + attr_reader user_text: untyped + def self.new: (context: String, accepted: bool, type: Symbol, ?user_context: String?, ?user_text: String?) -> instance + end + + class UserPromptOpenedParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader context: String + attr_reader handler: Symbol + attr_reader message: String + attr_reader type: Symbol + attr_reader user_context: untyped + attr_reader default_value: untyped + def self.new: (context: String, handler: Symbol, message: String, type: Symbol, ?user_context: String?, ?default_value: String?) -> instance + end + + EVENT_TYPES: Hash[String, untyped] + + def activate: (context: String) -> untyped + def capture_screenshot: (context: String, ?origin: Symbol?, ?format: ::Selenium::WebDriver::BiDi::Protocol::BrowsingContext::ImageFormat?, ?clip: ::Selenium::WebDriver::BiDi::Protocol::BrowsingContext::ClipRectangle?) -> ::Selenium::WebDriver::BiDi::Protocol::BrowsingContext::CaptureScreenshotResult + def close: (context: String, ?prompt_unload: bool?) -> untyped + def create: (type: Symbol, ?reference_context: String?, ?background: bool?, ?user_context: String?) -> ::Selenium::WebDriver::BiDi::Protocol::BrowsingContext::CreateResult + def get_tree: (?max_depth: Integer?, ?root: String?) -> ::Selenium::WebDriver::BiDi::Protocol::BrowsingContext::GetTreeResult + def handle_user_prompt: (context: String, ?accept: bool?, ?user_text: String?) -> untyped + def locate_nodes: (context: String, locator: ::Selenium::WebDriver::BiDi::Protocol::BrowsingContext::Locator, ?max_node_count: Integer?, ?serialization_options: ::Selenium::WebDriver::BiDi::Protocol::Script::SerializationOptions?, ?start_nodes: Array[::Selenium::WebDriver::BiDi::Protocol::Script::SharedReference]?) -> ::Selenium::WebDriver::BiDi::Protocol::BrowsingContext::LocateNodesResult + def navigate: (context: String, url: String, ?wait: Symbol?) -> ::Selenium::WebDriver::BiDi::Protocol::BrowsingContext::NavigateResult + def print: (context: String, ?background: bool?, ?margin: ::Selenium::WebDriver::BiDi::Protocol::BrowsingContext::PrintMarginParameters?, ?orientation: Symbol?, ?page: ::Selenium::WebDriver::BiDi::Protocol::BrowsingContext::PrintPageParameters?, ?page_ranges: Array[untyped]?, ?scale: Numeric?, ?shrink_to_fit: bool?) -> ::Selenium::WebDriver::BiDi::Protocol::BrowsingContext::PrintResult + def reload: (context: String, ?ignore_cache: bool?, ?wait: Symbol?) -> ::Selenium::WebDriver::BiDi::Protocol::BrowsingContext::NavigateResult + def set_bypass_csp: (bypass: bool?, ?contexts: Array[String]?, ?user_contexts: Array[String]?) -> untyped + def set_viewport: (?context: String?, ?viewport: ::Selenium::WebDriver::BiDi::Protocol::BrowsingContext::Viewport?, ?device_pixel_ratio: Numeric?, ?user_contexts: Array[String]?) -> untyped + def traverse_history: (context: String, delta: Integer) -> untyped + end + end + end + end +end diff --git a/rb/sig/lib/selenium/webdriver/bidi/protocol/domain.rbs b/rb/sig/lib/selenium/webdriver/bidi/protocol/domain.rbs new file mode 100644 index 0000000000000..bd39c031e7a5e --- /dev/null +++ b/rb/sig/lib/selenium/webdriver/bidi/protocol/domain.rbs @@ -0,0 +1,35 @@ +# 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 + module Protocol + class Domain + @transport: Transport + + def initialize: (Driver | Transport source) -> void + + private + + def execute: (cmd: String, ?params: untyped, ?result: untyped) -> untyped + end + end + end + end +end diff --git a/rb/sig/lib/selenium/webdriver/bidi/protocol/emulation.rbs b/rb/sig/lib/selenium/webdriver/bidi/protocol/emulation.rbs new file mode 100644 index 0000000000000..aa21a0558eec6 --- /dev/null +++ b/rb/sig/lib/selenium/webdriver/bidi/protocol/emulation.rbs @@ -0,0 +1,165 @@ +# 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. + +# This file is automatically generated. DO NOT EDIT! +# Regenerate with: bazel run //rb/lib/selenium/webdriver:bidi-generate + +module Selenium + module WebDriver + class BiDi + module Protocol + class Emulation < ::Selenium::WebDriver::BiDi::Protocol::Domain + FORCED_COLORS_MODE_THEME: Hash[Symbol, String] + + SCREEN_ORIENTATION_NATURAL: Hash[Symbol, String] + + SCREEN_ORIENTATION_TYPE: Hash[Symbol, String] + + class SetForcedColorsModeThemeOverrideParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader theme: Symbol? + attr_reader contexts: untyped + attr_reader user_contexts: untyped + def self.new: (theme: Symbol?, ?contexts: Array[String]?, ?user_contexts: Array[String]?) -> instance + end + + class SetGeolocationOverrideParameters < ::Selenium::WebDriver::BiDi::Serialization::Union + class Coordinates < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader contexts: untyped + attr_reader user_contexts: untyped + attr_reader coordinates: ::Selenium::WebDriver::BiDi::Protocol::Emulation::GeolocationCoordinates? + def self.new: (?contexts: Array[String]?, ?user_contexts: Array[String]?, coordinates: ::Selenium::WebDriver::BiDi::Protocol::Emulation::GeolocationCoordinates?) -> instance + end + class Error < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader contexts: untyped + attr_reader user_contexts: untyped + attr_reader error: ::Selenium::WebDriver::BiDi::Protocol::Emulation::GeolocationPositionError + def self.new: (?contexts: Array[String]?, ?user_contexts: Array[String]?, error: ::Selenium::WebDriver::BiDi::Protocol::Emulation::GeolocationPositionError) -> instance + end + end + + class GeolocationCoordinates < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader latitude: Integer + attr_reader longitude: Integer + attr_reader accuracy: untyped + attr_reader altitude: untyped + attr_reader altitude_accuracy: untyped + attr_reader heading: untyped + attr_reader speed: untyped + def self.new: (latitude: Integer, longitude: Integer, ?accuracy: Numeric?, ?altitude: Numeric?, ?altitude_accuracy: Numeric?, ?heading: Integer?, ?speed: Numeric?) -> instance + end + + class GeolocationPositionError < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + def self.new: (?type: untyped) -> instance + end + + class SetLocaleOverrideParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader locale: String? + attr_reader contexts: untyped + attr_reader user_contexts: untyped + def self.new: (locale: String?, ?contexts: Array[String]?, ?user_contexts: Array[String]?) -> instance + end + + class SetNetworkConditionsParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader network_conditions: ::Selenium::WebDriver::BiDi::Protocol::Emulation::NetworkConditionsOffline? + attr_reader contexts: untyped + attr_reader user_contexts: untyped + def self.new: (network_conditions: ::Selenium::WebDriver::BiDi::Protocol::Emulation::NetworkConditionsOffline?, ?contexts: Array[String]?, ?user_contexts: Array[String]?) -> instance + end + + class NetworkConditionsOffline < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + def self.new: (?type: untyped) -> instance + end + + class ScreenArea < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader width: Integer + attr_reader height: Integer + def self.new: (width: Integer, height: Integer) -> instance + end + + class SetScreenSettingsOverrideParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader screen_area: ::Selenium::WebDriver::BiDi::Protocol::Emulation::ScreenArea? + attr_reader contexts: untyped + attr_reader user_contexts: untyped + def self.new: (screen_area: ::Selenium::WebDriver::BiDi::Protocol::Emulation::ScreenArea?, ?contexts: Array[String]?, ?user_contexts: Array[String]?) -> instance + end + + class ScreenOrientation < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader natural: Symbol + attr_reader type: Symbol + def self.new: (natural: Symbol, type: Symbol) -> instance + end + + class SetScreenOrientationOverrideParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader screen_orientation: ::Selenium::WebDriver::BiDi::Protocol::Emulation::ScreenOrientation? + attr_reader contexts: untyped + attr_reader user_contexts: untyped + def self.new: (screen_orientation: ::Selenium::WebDriver::BiDi::Protocol::Emulation::ScreenOrientation?, ?contexts: Array[String]?, ?user_contexts: Array[String]?) -> instance + end + + class SetUserAgentOverrideParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader user_agent: String? + attr_reader contexts: untyped + attr_reader user_contexts: untyped + def self.new: (user_agent: String?, ?contexts: Array[String]?, ?user_contexts: Array[String]?) -> instance + end + + class SetScriptingEnabledParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader enabled: bool? + attr_reader contexts: untyped + attr_reader user_contexts: untyped + def self.new: (enabled: bool?, ?contexts: Array[String]?, ?user_contexts: Array[String]?) -> instance + end + + class SetScrollbarTypeOverrideParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader scrollbar_type: untyped + attr_reader contexts: untyped + attr_reader user_contexts: untyped + def self.new: (scrollbar_type: untyped, ?contexts: Array[String]?, ?user_contexts: Array[String]?) -> instance + end + + class SetTimezoneOverrideParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader timezone: String? + attr_reader contexts: untyped + attr_reader user_contexts: untyped + def self.new: (timezone: String?, ?contexts: Array[String]?, ?user_contexts: Array[String]?) -> instance + end + + class SetTouchOverrideParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader max_touch_points: Integer? + attr_reader contexts: untyped + attr_reader user_contexts: untyped + def self.new: (max_touch_points: Integer?, ?contexts: Array[String]?, ?user_contexts: Array[String]?) -> instance + end + + def set_forced_colors_mode_theme_override: (theme: Symbol?, ?contexts: Array[String]?, ?user_contexts: Array[String]?) -> untyped + def set_geolocation_override: (?contexts: Array[String]?, ?user_contexts: Array[String]?, ?coordinates: ::Selenium::WebDriver::BiDi::Protocol::Emulation::GeolocationCoordinates?, ?error: ::Selenium::WebDriver::BiDi::Protocol::Emulation::GeolocationPositionError?) -> untyped + def set_locale_override: (locale: String?, ?contexts: Array[String]?, ?user_contexts: Array[String]?) -> untyped + def set_network_conditions: (network_conditions: ::Selenium::WebDriver::BiDi::Protocol::Emulation::NetworkConditionsOffline?, ?contexts: Array[String]?, ?user_contexts: Array[String]?) -> untyped + def set_screen_orientation_override: (screen_orientation: ::Selenium::WebDriver::BiDi::Protocol::Emulation::ScreenOrientation?, ?contexts: Array[String]?, ?user_contexts: Array[String]?) -> untyped + def set_screen_settings_override: (screen_area: ::Selenium::WebDriver::BiDi::Protocol::Emulation::ScreenArea?, ?contexts: Array[String]?, ?user_contexts: Array[String]?) -> untyped + def set_scripting_enabled: (enabled: bool?, ?contexts: Array[String]?, ?user_contexts: Array[String]?) -> untyped + def set_scrollbar_type_override: (scrollbar_type: untyped, ?contexts: Array[String]?, ?user_contexts: Array[String]?) -> untyped + def set_timezone_override: (timezone: String?, ?contexts: Array[String]?, ?user_contexts: Array[String]?) -> untyped + def set_touch_override: (max_touch_points: Integer?, ?contexts: Array[String]?, ?user_contexts: Array[String]?) -> untyped + def set_user_agent_override: (user_agent: String?, ?contexts: Array[String]?, ?user_contexts: Array[String]?) -> untyped + end + end + end + end +end diff --git a/rb/sig/lib/selenium/webdriver/bidi/protocol/input.rbs b/rb/sig/lib/selenium/webdriver/bidi/protocol/input.rbs new file mode 100644 index 0000000000000..f31dd730db030 --- /dev/null +++ b/rb/sig/lib/selenium/webdriver/bidi/protocol/input.rbs @@ -0,0 +1,195 @@ +# 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. + +# This file is automatically generated. DO NOT EDIT! +# Regenerate with: bazel run //rb/lib/selenium/webdriver:bidi-generate + +module Selenium + module WebDriver + class BiDi + module Protocol + class Input < ::Selenium::WebDriver::BiDi::Protocol::Domain + EVENTS: Hash[Symbol, String] + + POINTER_TYPE: Hash[Symbol, String] + + class ElementOrigin < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + attr_reader element: ::Selenium::WebDriver::BiDi::Protocol::Script::SharedReference + def self.new: (?type: untyped, element: ::Selenium::WebDriver::BiDi::Protocol::Script::SharedReference) -> instance + end + + class PerformActionsParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader context: String + attr_reader actions: Array[::Selenium::WebDriver::BiDi::Protocol::Input::SourceActions] + def self.new: (context: String, actions: Array[::Selenium::WebDriver::BiDi::Protocol::Input::SourceActions]) -> instance + end + + class SourceActions < ::Selenium::WebDriver::BiDi::Serialization::Union + end + + class NoneSourceActions < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + attr_reader id: String + attr_reader actions: Array[::Selenium::WebDriver::BiDi::Protocol::Input::PauseAction] + def self.new: (?type: untyped, id: String, actions: Array[::Selenium::WebDriver::BiDi::Protocol::Input::PauseAction]) -> instance + end + + class KeySourceActions < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + attr_reader id: String + attr_reader actions: Array[::Selenium::WebDriver::BiDi::Protocol::Input::KeySourceAction] + def self.new: (?type: untyped, id: String, actions: Array[::Selenium::WebDriver::BiDi::Protocol::Input::KeySourceAction]) -> instance + end + + class KeySourceAction < ::Selenium::WebDriver::BiDi::Serialization::Union + end + + class PointerSourceActions < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + attr_reader id: String + attr_reader parameters: untyped + attr_reader actions: Array[::Selenium::WebDriver::BiDi::Protocol::Input::PointerSourceAction] + def self.new: (?type: untyped, id: String, ?parameters: ::Selenium::WebDriver::BiDi::Protocol::Input::PointerParameters?, actions: Array[::Selenium::WebDriver::BiDi::Protocol::Input::PointerSourceAction]) -> instance + end + + class PointerParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader pointer_type: untyped + def self.new: (?pointer_type: Symbol?) -> instance + end + + class PointerSourceAction < ::Selenium::WebDriver::BiDi::Serialization::Union + end + + class WheelSourceActions < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + attr_reader id: String + attr_reader actions: Array[::Selenium::WebDriver::BiDi::Protocol::Input::WheelSourceAction] + def self.new: (?type: untyped, id: String, actions: Array[::Selenium::WebDriver::BiDi::Protocol::Input::WheelSourceAction]) -> instance + end + + class WheelSourceAction < ::Selenium::WebDriver::BiDi::Serialization::Union + end + + class PauseAction < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + attr_reader duration: untyped + def self.new: (?type: untyped, ?duration: Integer?) -> instance + end + + class KeyDownAction < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + attr_reader value: String + def self.new: (?type: untyped, value: String) -> instance + end + + class KeyUpAction < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + attr_reader value: String + def self.new: (?type: untyped, value: String) -> instance + end + + class PointerUpAction < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + attr_reader button: Integer + def self.new: (?type: untyped, button: Integer) -> instance + end + + class PointerDownAction < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + attr_reader button: Integer + attr_reader width: untyped + attr_reader height: untyped + attr_reader pressure: untyped + attr_reader tangential_pressure: untyped + attr_reader twist: untyped + attr_reader altitude_angle: untyped + attr_reader azimuth_angle: untyped + def self.new: (?type: untyped, button: Integer, ?width: Integer?, ?height: Integer?, ?pressure: Integer?, ?tangential_pressure: Integer?, ?twist: Integer?, ?altitude_angle: Numeric?, ?azimuth_angle: Numeric?) -> instance + end + + class PointerMoveAction < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + attr_reader x: Numeric + attr_reader y: Numeric + attr_reader duration: untyped + attr_reader origin: untyped + attr_reader width: untyped + attr_reader height: untyped + attr_reader pressure: untyped + attr_reader tangential_pressure: untyped + attr_reader twist: untyped + attr_reader altitude_angle: untyped + attr_reader azimuth_angle: untyped + def self.new: (?type: untyped, x: Numeric, y: Numeric, ?duration: Integer?, ?origin: ::Selenium::WebDriver::BiDi::Protocol::Input::Origin?, ?width: Integer?, ?height: Integer?, ?pressure: Integer?, ?tangential_pressure: Integer?, ?twist: Integer?, ?altitude_angle: Numeric?, ?azimuth_angle: Numeric?) -> instance + end + + class WheelScrollAction < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + attr_reader x: Integer + attr_reader y: Integer + attr_reader delta_x: Integer + attr_reader delta_y: Integer + attr_reader duration: untyped + attr_reader origin: untyped + def self.new: (?type: untyped, x: Integer, y: Integer, delta_x: Integer, delta_y: Integer, ?duration: Integer?, ?origin: ::Selenium::WebDriver::BiDi::Protocol::Input::Origin?) -> instance + end + + class PointerCommonProperties < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader width: untyped + attr_reader height: untyped + attr_reader pressure: untyped + attr_reader tangential_pressure: untyped + attr_reader twist: untyped + attr_reader altitude_angle: untyped + attr_reader azimuth_angle: untyped + def self.new: (?width: Integer?, ?height: Integer?, ?pressure: Integer?, ?tangential_pressure: Integer?, ?twist: Integer?, ?altitude_angle: Numeric?, ?azimuth_angle: Numeric?) -> instance + end + + class Origin < ::Selenium::WebDriver::BiDi::Serialization::Union + end + + class ReleaseActionsParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader context: String + def self.new: (context: String) -> instance + end + + class SetFilesParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader context: String + attr_reader element: ::Selenium::WebDriver::BiDi::Protocol::Script::SharedReference + attr_reader files: Array[String] + def self.new: (context: String, element: ::Selenium::WebDriver::BiDi::Protocol::Script::SharedReference, files: Array[String]) -> instance + end + + class FileDialogInfo < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader context: String + attr_reader user_context: untyped + attr_reader element: untyped + attr_reader multiple: bool + def self.new: (context: String, ?user_context: String?, ?element: ::Selenium::WebDriver::BiDi::Protocol::Script::SharedReference?, multiple: bool) -> instance + end + + EVENT_TYPES: Hash[String, untyped] + + def perform_actions: (context: String, actions: Array[::Selenium::WebDriver::BiDi::Protocol::Input::SourceActions]) -> untyped + def release_actions: (context: String) -> untyped + def set_files: (context: String, element: ::Selenium::WebDriver::BiDi::Protocol::Script::SharedReference, files: Array[String]) -> untyped + end + end + end + end +end diff --git a/rb/sig/lib/selenium/webdriver/bidi/protocol/log.rbs b/rb/sig/lib/selenium/webdriver/bidi/protocol/log.rbs new file mode 100644 index 0000000000000..3fdba6e3e6b31 --- /dev/null +++ b/rb/sig/lib/selenium/webdriver/bidi/protocol/log.rbs @@ -0,0 +1,80 @@ +# 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. + +# This file is automatically generated. DO NOT EDIT! +# Regenerate with: bazel run //rb/lib/selenium/webdriver:bidi-generate + +module Selenium + module WebDriver + class BiDi + module Protocol + class Log < ::Selenium::WebDriver::BiDi::Protocol::Domain + EVENTS: Hash[Symbol, String] + + LEVEL: Hash[Symbol, String] + + class Entry < ::Selenium::WebDriver::BiDi::Serialization::Union + end + + class BaseLogEntry < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader level: Symbol + attr_reader source: ::Selenium::WebDriver::BiDi::Protocol::Script::Source + attr_reader text: String? + attr_reader timestamp: Integer + attr_reader stack_trace: untyped + def self.new: (level: Symbol, source: ::Selenium::WebDriver::BiDi::Protocol::Script::Source, text: String?, timestamp: Integer, ?stack_trace: ::Selenium::WebDriver::BiDi::Protocol::Script::StackTrace?) -> instance + end + + class GenericLogEntry < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader level: Symbol + attr_reader source: ::Selenium::WebDriver::BiDi::Protocol::Script::Source + attr_reader text: String? + attr_reader timestamp: Integer + attr_reader stack_trace: untyped + attr_reader type: String + def self.new: (level: Symbol, source: ::Selenium::WebDriver::BiDi::Protocol::Script::Source, text: String?, timestamp: Integer, ?stack_trace: ::Selenium::WebDriver::BiDi::Protocol::Script::StackTrace?, type: String) -> instance + end + + class ConsoleLogEntry < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + attr_reader level: Symbol + attr_reader source: ::Selenium::WebDriver::BiDi::Protocol::Script::Source + attr_reader text: String? + attr_reader timestamp: Integer + attr_reader stack_trace: untyped + attr_reader method_: String + attr_reader args: Array[::Selenium::WebDriver::BiDi::Protocol::Script::RemoteValue] + def self.new: (?type: untyped, level: Symbol, source: ::Selenium::WebDriver::BiDi::Protocol::Script::Source, text: String?, timestamp: Integer, ?stack_trace: ::Selenium::WebDriver::BiDi::Protocol::Script::StackTrace?, method_: String, args: Array[::Selenium::WebDriver::BiDi::Protocol::Script::RemoteValue]) -> instance + end + + class JavascriptLogEntry < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + attr_reader level: Symbol + attr_reader source: ::Selenium::WebDriver::BiDi::Protocol::Script::Source + attr_reader text: String? + attr_reader timestamp: Integer + attr_reader stack_trace: untyped + def self.new: (?type: untyped, level: Symbol, source: ::Selenium::WebDriver::BiDi::Protocol::Script::Source, text: String?, timestamp: Integer, ?stack_trace: ::Selenium::WebDriver::BiDi::Protocol::Script::StackTrace?) -> instance + end + + EVENT_TYPES: Hash[String, untyped] + + end + end + end + end +end diff --git a/rb/sig/lib/selenium/webdriver/bidi/protocol/network.rbs b/rb/sig/lib/selenium/webdriver/bidi/protocol/network.rbs new file mode 100644 index 0000000000000..334ac6fbed150 --- /dev/null +++ b/rb/sig/lib/selenium/webdriver/bidi/protocol/network.rbs @@ -0,0 +1,403 @@ +# 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. + +# This file is automatically generated. DO NOT EDIT! +# Regenerate with: bazel run //rb/lib/selenium/webdriver:bidi-generate + +module Selenium + module WebDriver + class BiDi + module Protocol + class Network < ::Selenium::WebDriver::BiDi::Protocol::Domain + EVENTS: Hash[Symbol, String] + + COLLECTOR_TYPE: Hash[Symbol, String] + + SAME_SITE: Hash[Symbol, String] + + DATA_TYPE: Hash[Symbol, String] + + INTERCEPT_PHASE: Hash[Symbol, String] + + INITIATOR_TYPE: Hash[Symbol, String] + + CONTINUE_WITH_AUTH_NO_CREDENTIALS_ACTION: Hash[Symbol, String] + + SET_CACHE_BEHAVIOR_PARAMETERS_CACHE_BEHAVIOR: Hash[Symbol, String] + + class AuthChallenge < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader scheme: String + attr_reader realm: String + def self.new: (scheme: String, realm: String) -> instance + end + + class AuthCredentials < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + attr_reader username: String + attr_reader password: String + def self.new: (?type: untyped, username: String, password: String) -> instance + end + + class BaseParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader context: String? + attr_reader is_blocked: bool + attr_reader navigation: String? + attr_reader redirect_count: Integer + attr_reader request: ::Selenium::WebDriver::BiDi::Protocol::Network::RequestData + attr_reader timestamp: Integer + attr_reader user_context: untyped + attr_reader intercepts: untyped + def self.new: (context: String?, is_blocked: bool, navigation: String?, redirect_count: Integer, request: ::Selenium::WebDriver::BiDi::Protocol::Network::RequestData, timestamp: Integer, ?user_context: String?, ?intercepts: Array[String]?) -> instance + end + + class BytesValue < ::Selenium::WebDriver::BiDi::Serialization::Union + end + + class StringValue < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + attr_reader value: String + def self.new: (?type: untyped, value: String) -> instance + end + + class Base64Value < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + attr_reader value: String + def self.new: (?type: untyped, value: String) -> instance + end + + class Cookie < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader name: String + attr_reader value: ::Selenium::WebDriver::BiDi::Protocol::Network::BytesValue + attr_reader domain: String + attr_reader path: String + attr_reader size: Integer + attr_reader http_only: bool + attr_reader secure: bool + attr_reader same_site: Symbol + attr_reader expiry: untyped + attr_reader extensions: Hash[String, untyped] + def self.new: (name: String, value: ::Selenium::WebDriver::BiDi::Protocol::Network::BytesValue, domain: String, path: String, size: Integer, http_only: bool, secure: bool, same_site: Symbol, ?expiry: Integer?, ?extensions: untyped) -> instance + end + + class CookieHeader < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader name: String + attr_reader value: ::Selenium::WebDriver::BiDi::Protocol::Network::BytesValue + def self.new: (name: String, value: ::Selenium::WebDriver::BiDi::Protocol::Network::BytesValue) -> instance + end + + class FetchTimingInfo < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader time_origin: Numeric + attr_reader request_time: Numeric + attr_reader redirect_start: Numeric + attr_reader redirect_end: Numeric + attr_reader fetch_start: Numeric + attr_reader dns_start: Numeric + attr_reader dns_end: Numeric + attr_reader connect_start: Numeric + attr_reader connect_end: Numeric + attr_reader tls_start: Numeric + attr_reader request_start: Numeric + attr_reader response_start: Numeric + attr_reader response_end: Numeric + def self.new: (time_origin: Numeric, request_time: Numeric, redirect_start: Numeric, redirect_end: Numeric, fetch_start: Numeric, dns_start: Numeric, dns_end: Numeric, connect_start: Numeric, connect_end: Numeric, tls_start: Numeric, request_start: Numeric, response_start: Numeric, response_end: Numeric) -> instance + end + + class Header < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader name: String + attr_reader value: ::Selenium::WebDriver::BiDi::Protocol::Network::BytesValue + def self.new: (name: String, value: ::Selenium::WebDriver::BiDi::Protocol::Network::BytesValue) -> instance + end + + class Initiator < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader column_number: untyped + attr_reader line_number: untyped + attr_reader request: untyped + attr_reader stack_trace: untyped + attr_reader type: untyped + def self.new: (?column_number: Integer?, ?line_number: Integer?, ?request: String?, ?stack_trace: ::Selenium::WebDriver::BiDi::Protocol::Script::StackTrace?, ?type: Symbol?) -> instance + end + + class RequestData < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader request: String + attr_reader url: String + attr_reader method_: String + attr_reader headers: Array[::Selenium::WebDriver::BiDi::Protocol::Network::Header] + attr_reader cookies: Array[::Selenium::WebDriver::BiDi::Protocol::Network::Cookie] + attr_reader headers_size: Integer + attr_reader body_size: Integer? + attr_reader destination: String + attr_reader initiator_type: String? + attr_reader timings: ::Selenium::WebDriver::BiDi::Protocol::Network::FetchTimingInfo + def self.new: (request: String, url: String, method_: String, headers: Array[::Selenium::WebDriver::BiDi::Protocol::Network::Header], cookies: Array[::Selenium::WebDriver::BiDi::Protocol::Network::Cookie], headers_size: Integer, body_size: Integer?, destination: String, initiator_type: String?, timings: ::Selenium::WebDriver::BiDi::Protocol::Network::FetchTimingInfo) -> instance + end + + class ResponseContent < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader size: Integer + def self.new: (size: Integer) -> instance + end + + class ResponseData < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader url: String + attr_reader protocol: String + attr_reader status: Integer + attr_reader status_text: String + attr_reader from_cache: bool + attr_reader headers: Array[::Selenium::WebDriver::BiDi::Protocol::Network::Header] + attr_reader mime_type: String + attr_reader bytes_received: Integer + attr_reader headers_size: Integer? + attr_reader body_size: Integer? + attr_reader content: ::Selenium::WebDriver::BiDi::Protocol::Network::ResponseContent + attr_reader auth_challenges: untyped + def self.new: (url: String, protocol: String, status: Integer, status_text: String, from_cache: bool, headers: Array[::Selenium::WebDriver::BiDi::Protocol::Network::Header], mime_type: String, bytes_received: Integer, headers_size: Integer?, body_size: Integer?, content: ::Selenium::WebDriver::BiDi::Protocol::Network::ResponseContent, ?auth_challenges: Array[::Selenium::WebDriver::BiDi::Protocol::Network::AuthChallenge]?) -> instance + end + + class SetCookieHeader < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader name: String + attr_reader value: ::Selenium::WebDriver::BiDi::Protocol::Network::BytesValue + attr_reader domain: untyped + attr_reader http_only: untyped + attr_reader expiry: untyped + attr_reader max_age: untyped + attr_reader path: untyped + attr_reader same_site: untyped + attr_reader secure: untyped + def self.new: (name: String, value: ::Selenium::WebDriver::BiDi::Protocol::Network::BytesValue, ?domain: String?, ?http_only: bool?, ?expiry: String?, ?max_age: Integer?, ?path: String?, ?same_site: Symbol?, ?secure: bool?) -> instance + end + + class UrlPattern < ::Selenium::WebDriver::BiDi::Serialization::Union + end + + class UrlPatternPattern < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + attr_reader protocol: untyped + attr_reader hostname: untyped + attr_reader port: untyped + attr_reader pathname: untyped + attr_reader search: untyped + def self.new: (?type: untyped, ?protocol: String?, ?hostname: String?, ?port: String?, ?pathname: String?, ?search: String?) -> instance + end + + class UrlPatternString < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + attr_reader pattern: String + def self.new: (?type: untyped, pattern: String) -> instance + end + + class AddDataCollectorParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader data_types: Array[Symbol] + attr_reader max_encoded_data_size: Integer + attr_reader collector_type: untyped + attr_reader contexts: untyped + attr_reader user_contexts: untyped + def self.new: (data_types: Array[Symbol], max_encoded_data_size: Integer, ?collector_type: Symbol?, ?contexts: Array[String]?, ?user_contexts: Array[String]?) -> instance + end + + class AddDataCollectorResult < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader collector: String + def self.new: (collector: String) -> instance + end + + class AddInterceptParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader phases: Array[Symbol] + attr_reader contexts: untyped + attr_reader url_patterns: untyped + def self.new: (phases: Array[Symbol], ?contexts: Array[String]?, ?url_patterns: Array[::Selenium::WebDriver::BiDi::Protocol::Network::UrlPattern]?) -> instance + end + + class AddInterceptResult < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader intercept: String + def self.new: (intercept: String) -> instance + end + + class ContinueRequestParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader request: String + attr_reader body: untyped + attr_reader cookies: untyped + attr_reader headers: untyped + attr_reader method_: untyped + attr_reader url: untyped + def self.new: (request: String, ?body: ::Selenium::WebDriver::BiDi::Protocol::Network::BytesValue?, ?cookies: Array[::Selenium::WebDriver::BiDi::Protocol::Network::CookieHeader]?, ?headers: Array[::Selenium::WebDriver::BiDi::Protocol::Network::Header]?, ?method_: String?, ?url: String?) -> instance + end + + class ContinueResponseParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader request: String + attr_reader cookies: untyped + attr_reader credentials: untyped + attr_reader headers: untyped + attr_reader reason_phrase: untyped + attr_reader status_code: untyped + def self.new: (request: String, ?cookies: Array[::Selenium::WebDriver::BiDi::Protocol::Network::SetCookieHeader]?, ?credentials: ::Selenium::WebDriver::BiDi::Protocol::Network::AuthCredentials?, ?headers: Array[::Selenium::WebDriver::BiDi::Protocol::Network::Header]?, ?reason_phrase: String?, ?status_code: Integer?) -> instance + end + + class ContinueWithAuthParameters < ::Selenium::WebDriver::BiDi::Serialization::Union + class Credentials < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader action: untyped + attr_reader request: String + attr_reader credentials: ::Selenium::WebDriver::BiDi::Protocol::Network::AuthCredentials + def self.new: (?action: untyped, request: String, credentials: ::Selenium::WebDriver::BiDi::Protocol::Network::AuthCredentials) -> instance + end + class NoCredentials < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader request: String + attr_reader action: Symbol + def self.new: (request: String, action: Symbol) -> instance + end + end + + class DisownDataParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader data_type: Symbol + attr_reader collector: String + attr_reader request: String + def self.new: (data_type: Symbol, collector: String, request: String) -> instance + end + + class FailRequestParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader request: String + def self.new: (request: String) -> instance + end + + class GetDataParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader data_type: Symbol + attr_reader collector: untyped + attr_reader disown: untyped + attr_reader request: String + def self.new: (data_type: Symbol, ?collector: String?, ?disown: bool?, request: String) -> instance + end + + class GetDataResult < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader bytes: ::Selenium::WebDriver::BiDi::Protocol::Network::BytesValue + def self.new: (bytes: ::Selenium::WebDriver::BiDi::Protocol::Network::BytesValue) -> instance + end + + class ProvideResponseParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader request: String + attr_reader body: untyped + attr_reader cookies: untyped + attr_reader headers: untyped + attr_reader reason_phrase: untyped + attr_reader status_code: untyped + def self.new: (request: String, ?body: ::Selenium::WebDriver::BiDi::Protocol::Network::BytesValue?, ?cookies: Array[::Selenium::WebDriver::BiDi::Protocol::Network::SetCookieHeader]?, ?headers: Array[::Selenium::WebDriver::BiDi::Protocol::Network::Header]?, ?reason_phrase: String?, ?status_code: Integer?) -> instance + end + + class RemoveDataCollectorParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader collector: String + def self.new: (collector: String) -> instance + end + + class RemoveInterceptParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader intercept: String + def self.new: (intercept: String) -> instance + end + + class SetCacheBehaviorParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader cache_behavior: Symbol + attr_reader contexts: untyped + def self.new: (cache_behavior: Symbol, ?contexts: Array[String]?) -> instance + end + + class SetExtraHeadersParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader headers: Array[::Selenium::WebDriver::BiDi::Protocol::Network::Header] + attr_reader contexts: untyped + attr_reader user_contexts: untyped + def self.new: (headers: Array[::Selenium::WebDriver::BiDi::Protocol::Network::Header], ?contexts: Array[String]?, ?user_contexts: Array[String]?) -> instance + end + + class AuthRequiredParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader context: String? + attr_reader is_blocked: bool + attr_reader navigation: String? + attr_reader redirect_count: Integer + attr_reader request: ::Selenium::WebDriver::BiDi::Protocol::Network::RequestData + attr_reader timestamp: Integer + attr_reader user_context: untyped + attr_reader intercepts: untyped + attr_reader response: ::Selenium::WebDriver::BiDi::Protocol::Network::ResponseData + def self.new: (context: String?, is_blocked: bool, navigation: String?, redirect_count: Integer, request: ::Selenium::WebDriver::BiDi::Protocol::Network::RequestData, timestamp: Integer, ?user_context: String?, ?intercepts: Array[String]?, response: ::Selenium::WebDriver::BiDi::Protocol::Network::ResponseData) -> instance + end + + class BeforeRequestSentParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader context: String? + attr_reader is_blocked: bool + attr_reader navigation: String? + attr_reader redirect_count: Integer + attr_reader request: ::Selenium::WebDriver::BiDi::Protocol::Network::RequestData + attr_reader timestamp: Integer + attr_reader user_context: untyped + attr_reader intercepts: untyped + attr_reader initiator: untyped + def self.new: (context: String?, is_blocked: bool, navigation: String?, redirect_count: Integer, request: ::Selenium::WebDriver::BiDi::Protocol::Network::RequestData, timestamp: Integer, ?user_context: String?, ?intercepts: Array[String]?, ?initiator: ::Selenium::WebDriver::BiDi::Protocol::Network::Initiator?) -> instance + end + + class FetchErrorParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader context: String? + attr_reader is_blocked: bool + attr_reader navigation: String? + attr_reader redirect_count: Integer + attr_reader request: ::Selenium::WebDriver::BiDi::Protocol::Network::RequestData + attr_reader timestamp: Integer + attr_reader user_context: untyped + attr_reader intercepts: untyped + attr_reader error_text: String + def self.new: (context: String?, is_blocked: bool, navigation: String?, redirect_count: Integer, request: ::Selenium::WebDriver::BiDi::Protocol::Network::RequestData, timestamp: Integer, ?user_context: String?, ?intercepts: Array[String]?, error_text: String) -> instance + end + + class ResponseCompletedParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader context: String? + attr_reader is_blocked: bool + attr_reader navigation: String? + attr_reader redirect_count: Integer + attr_reader request: ::Selenium::WebDriver::BiDi::Protocol::Network::RequestData + attr_reader timestamp: Integer + attr_reader user_context: untyped + attr_reader intercepts: untyped + attr_reader response: ::Selenium::WebDriver::BiDi::Protocol::Network::ResponseData + def self.new: (context: String?, is_blocked: bool, navigation: String?, redirect_count: Integer, request: ::Selenium::WebDriver::BiDi::Protocol::Network::RequestData, timestamp: Integer, ?user_context: String?, ?intercepts: Array[String]?, response: ::Selenium::WebDriver::BiDi::Protocol::Network::ResponseData) -> instance + end + + class ResponseStartedParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader context: String? + attr_reader is_blocked: bool + attr_reader navigation: String? + attr_reader redirect_count: Integer + attr_reader request: ::Selenium::WebDriver::BiDi::Protocol::Network::RequestData + attr_reader timestamp: Integer + attr_reader user_context: untyped + attr_reader intercepts: untyped + attr_reader response: ::Selenium::WebDriver::BiDi::Protocol::Network::ResponseData + def self.new: (context: String?, is_blocked: bool, navigation: String?, redirect_count: Integer, request: ::Selenium::WebDriver::BiDi::Protocol::Network::RequestData, timestamp: Integer, ?user_context: String?, ?intercepts: Array[String]?, response: ::Selenium::WebDriver::BiDi::Protocol::Network::ResponseData) -> instance + end + + EVENT_TYPES: Hash[String, untyped] + + def add_data_collector: (data_types: Array[Symbol], max_encoded_data_size: Integer, ?collector_type: Symbol?, ?contexts: Array[String]?, ?user_contexts: Array[String]?) -> ::Selenium::WebDriver::BiDi::Protocol::Network::AddDataCollectorResult + def add_intercept: (phases: Array[Symbol], ?contexts: Array[String]?, ?url_patterns: Array[::Selenium::WebDriver::BiDi::Protocol::Network::UrlPattern]?) -> ::Selenium::WebDriver::BiDi::Protocol::Network::AddInterceptResult + def continue_request: (request: String, ?body: ::Selenium::WebDriver::BiDi::Protocol::Network::BytesValue?, ?cookies: Array[::Selenium::WebDriver::BiDi::Protocol::Network::CookieHeader]?, ?headers: Array[::Selenium::WebDriver::BiDi::Protocol::Network::Header]?, ?method_: String?, ?url: String?) -> untyped + def continue_response: (request: String, ?cookies: Array[::Selenium::WebDriver::BiDi::Protocol::Network::SetCookieHeader]?, ?credentials: ::Selenium::WebDriver::BiDi::Protocol::Network::AuthCredentials?, ?headers: Array[::Selenium::WebDriver::BiDi::Protocol::Network::Header]?, ?reason_phrase: String?, ?status_code: Integer?) -> untyped + def continue_with_auth: (request: String, action: Symbol, ?credentials: ::Selenium::WebDriver::BiDi::Protocol::Network::AuthCredentials?) -> untyped + def disown_data: (data_type: Symbol, collector: String, request: String) -> untyped + def fail_request: (request: String) -> untyped + def get_data: (data_type: Symbol, request: String, ?collector: String?, ?disown: bool?) -> ::Selenium::WebDriver::BiDi::Protocol::Network::GetDataResult + def provide_response: (request: String, ?body: ::Selenium::WebDriver::BiDi::Protocol::Network::BytesValue?, ?cookies: Array[::Selenium::WebDriver::BiDi::Protocol::Network::SetCookieHeader]?, ?headers: Array[::Selenium::WebDriver::BiDi::Protocol::Network::Header]?, ?reason_phrase: String?, ?status_code: Integer?) -> untyped + def remove_data_collector: (collector: String) -> untyped + def remove_intercept: (intercept: String) -> untyped + def set_cache_behavior: (cache_behavior: Symbol, ?contexts: Array[String]?) -> untyped + def set_extra_headers: (headers: Array[::Selenium::WebDriver::BiDi::Protocol::Network::Header], ?contexts: Array[String]?, ?user_contexts: Array[String]?) -> untyped + end + end + end + end +end diff --git a/rb/sig/lib/selenium/webdriver/bidi/protocol/permissions.rbs b/rb/sig/lib/selenium/webdriver/bidi/protocol/permissions.rbs new file mode 100644 index 0000000000000..0ae78f8ceb43d --- /dev/null +++ b/rb/sig/lib/selenium/webdriver/bidi/protocol/permissions.rbs @@ -0,0 +1,47 @@ +# 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. + +# This file is automatically generated. DO NOT EDIT! +# Regenerate with: bazel run //rb/lib/selenium/webdriver:bidi-generate + +module Selenium + module WebDriver + class BiDi + module Protocol + class Permissions < ::Selenium::WebDriver::BiDi::Protocol::Domain + PERMISSION_STATE: Hash[Symbol, String] + + class PermissionDescriptor < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader name: String + def self.new: (name: String) -> instance + end + + class SetPermissionParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader descriptor: ::Selenium::WebDriver::BiDi::Protocol::Permissions::PermissionDescriptor + attr_reader state: Symbol + attr_reader origin: String + attr_reader embedded_origin: untyped + attr_reader user_context: untyped + def self.new: (descriptor: ::Selenium::WebDriver::BiDi::Protocol::Permissions::PermissionDescriptor, state: Symbol, origin: String, ?embedded_origin: String?, ?user_context: String?) -> instance + end + + def set_permission: (descriptor: ::Selenium::WebDriver::BiDi::Protocol::Permissions::PermissionDescriptor, state: Symbol, origin: String, ?embedded_origin: String?, ?user_context: String?) -> untyped + end + end + end + end +end diff --git a/rb/sig/lib/selenium/webdriver/bidi/protocol/script.rbs b/rb/sig/lib/selenium/webdriver/bidi/protocol/script.rbs new file mode 100644 index 0000000000000..2adc141c6bb8f --- /dev/null +++ b/rb/sig/lib/selenium/webdriver/bidi/protocol/script.rbs @@ -0,0 +1,540 @@ +# 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. + +# This file is automatically generated. DO NOT EDIT! +# Regenerate with: bazel run //rb/lib/selenium/webdriver:bidi-generate + +module Selenium + module WebDriver + class BiDi + module Protocol + class Script < ::Selenium::WebDriver::BiDi::Protocol::Domain + EVENTS: Hash[Symbol, String] + + SPECIAL_NUMBER: Hash[Symbol, String] + + REALM_TYPE: Hash[Symbol, String] + + RESULT_OWNERSHIP: Hash[Symbol, String] + + NODE_PROPERTIES_MODE: Hash[Symbol, String] + + SERIALIZATION_OPTIONS_INCLUDE_SHADOW_TREE: Hash[Symbol, String] + + class ChannelValue < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + attr_reader value: ::Selenium::WebDriver::BiDi::Protocol::Script::ChannelProperties + def self.new: (?type: untyped, value: ::Selenium::WebDriver::BiDi::Protocol::Script::ChannelProperties) -> instance + end + + class ChannelProperties < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader channel: String + attr_reader serialization_options: untyped + attr_reader ownership: untyped + def self.new: (channel: String, ?serialization_options: ::Selenium::WebDriver::BiDi::Protocol::Script::SerializationOptions?, ?ownership: Symbol?) -> instance + end + + class EvaluateResult < ::Selenium::WebDriver::BiDi::Serialization::Union + end + + class EvaluateResultSuccess < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + attr_reader result: ::Selenium::WebDriver::BiDi::Protocol::Script::RemoteValue + attr_reader realm: String + def self.new: (?type: untyped, result: ::Selenium::WebDriver::BiDi::Protocol::Script::RemoteValue, realm: String) -> instance + end + + class EvaluateResultException < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + attr_reader exception_details: ::Selenium::WebDriver::BiDi::Protocol::Script::ExceptionDetails + attr_reader realm: String + def self.new: (?type: untyped, exception_details: ::Selenium::WebDriver::BiDi::Protocol::Script::ExceptionDetails, realm: String) -> instance + end + + class ExceptionDetails < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader column_number: Integer + attr_reader exception: ::Selenium::WebDriver::BiDi::Protocol::Script::RemoteValue + attr_reader line_number: Integer + attr_reader stack_trace: ::Selenium::WebDriver::BiDi::Protocol::Script::StackTrace + attr_reader text: String + def self.new: (column_number: Integer, exception: ::Selenium::WebDriver::BiDi::Protocol::Script::RemoteValue, line_number: Integer, stack_trace: ::Selenium::WebDriver::BiDi::Protocol::Script::StackTrace, text: String) -> instance + end + + class LocalValue < ::Selenium::WebDriver::BiDi::Serialization::Union + end + + class ArrayLocalValue < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + attr_reader value: Array[::Selenium::WebDriver::BiDi::Protocol::Script::LocalValue] + def self.new: (?type: untyped, value: Array[::Selenium::WebDriver::BiDi::Protocol::Script::LocalValue]) -> instance + end + + class DateLocalValue < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + attr_reader value: String + def self.new: (?type: untyped, value: String) -> instance + end + + class MapLocalValue < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + attr_reader value: Array[Array[untyped]] + def self.new: (?type: untyped, value: Array[Array[untyped]]) -> instance + end + + class ObjectLocalValue < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + attr_reader value: Array[Array[untyped]] + def self.new: (?type: untyped, value: Array[Array[untyped]]) -> instance + end + + class RegExpValue < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader pattern: String + attr_reader flags: untyped + def self.new: (pattern: String, ?flags: String?) -> instance + end + + class RegExpLocalValue < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + attr_reader value: ::Selenium::WebDriver::BiDi::Protocol::Script::RegExpValue + def self.new: (?type: untyped, value: ::Selenium::WebDriver::BiDi::Protocol::Script::RegExpValue) -> instance + end + + class SetLocalValue < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + attr_reader value: Array[::Selenium::WebDriver::BiDi::Protocol::Script::LocalValue] + def self.new: (?type: untyped, value: Array[::Selenium::WebDriver::BiDi::Protocol::Script::LocalValue]) -> instance + end + + class PrimitiveProtocolValue < ::Selenium::WebDriver::BiDi::Serialization::Union + end + + class UndefinedValue < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + def self.new: (?type: untyped) -> instance + end + + class NullValue < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + def self.new: (?type: untyped) -> instance + end + + class StringValue < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + attr_reader value: String + def self.new: (?type: untyped, value: String) -> instance + end + + class NumberValue < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + attr_reader value: untyped + def self.new: (?type: untyped, value: untyped) -> instance + end + + class BooleanValue < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + attr_reader value: bool + def self.new: (?type: untyped, value: bool) -> instance + end + + class BigIntValue < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + attr_reader value: String + def self.new: (?type: untyped, value: String) -> instance + end + + class RealmInfo < ::Selenium::WebDriver::BiDi::Serialization::Union + end + + class BaseRealmInfo < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader realm: String + attr_reader origin: String + def self.new: (realm: String, origin: String) -> instance + end + + class WindowRealmInfo < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + attr_reader realm: String + attr_reader origin: String + attr_reader context: String + attr_reader user_context: untyped + attr_reader sandbox: untyped + def self.new: (?type: untyped, realm: String, origin: String, context: String, ?user_context: String?, ?sandbox: String?) -> instance + end + + class DedicatedWorkerRealmInfo < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + attr_reader realm: String + attr_reader origin: String + attr_reader owners: Array[String] + def self.new: (?type: untyped, realm: String, origin: String, owners: Array[String]) -> instance + end + + class SharedWorkerRealmInfo < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + attr_reader realm: String + attr_reader origin: String + def self.new: (?type: untyped, realm: String, origin: String) -> instance + end + + class ServiceWorkerRealmInfo < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + attr_reader realm: String + attr_reader origin: String + def self.new: (?type: untyped, realm: String, origin: String) -> instance + end + + class WorkerRealmInfo < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + attr_reader realm: String + attr_reader origin: String + def self.new: (?type: untyped, realm: String, origin: String) -> instance + end + + class PaintWorkletRealmInfo < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + attr_reader realm: String + attr_reader origin: String + def self.new: (?type: untyped, realm: String, origin: String) -> instance + end + + class AudioWorkletRealmInfo < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + attr_reader realm: String + attr_reader origin: String + def self.new: (?type: untyped, realm: String, origin: String) -> instance + end + + class WorkletRealmInfo < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + attr_reader realm: String + attr_reader origin: String + def self.new: (?type: untyped, realm: String, origin: String) -> instance + end + + class RemoteReference < ::Selenium::WebDriver::BiDi::Serialization::Union + end + + class SharedReference < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader shared_id: String + attr_reader handle: untyped + attr_reader extensions: Hash[String, untyped] + def self.new: (shared_id: String, ?handle: String?, ?extensions: untyped) -> instance + end + + class RemoteObjectReference < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader handle: String + attr_reader shared_id: untyped + attr_reader extensions: Hash[String, untyped] + def self.new: (handle: String, ?shared_id: String?, ?extensions: untyped) -> instance + end + + class RemoteValue < ::Selenium::WebDriver::BiDi::Serialization::Union + end + + class SymbolRemoteValue < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + attr_reader handle: untyped + attr_reader internal_id: untyped + def self.new: (?type: untyped, ?handle: String?, ?internal_id: String?) -> instance + end + + class ArrayRemoteValue < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + attr_reader handle: untyped + attr_reader internal_id: untyped + attr_reader value: untyped + def self.new: (?type: untyped, ?handle: String?, ?internal_id: String?, ?value: Array[::Selenium::WebDriver::BiDi::Protocol::Script::RemoteValue]?) -> instance + end + + class ObjectRemoteValue < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + attr_reader handle: untyped + attr_reader internal_id: untyped + attr_reader value: untyped + def self.new: (?type: untyped, ?handle: String?, ?internal_id: String?, ?value: Array[Array[untyped]]?) -> instance + end + + class FunctionRemoteValue < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + attr_reader handle: untyped + attr_reader internal_id: untyped + def self.new: (?type: untyped, ?handle: String?, ?internal_id: String?) -> instance + end + + class RegExpRemoteValue < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + attr_reader value: ::Selenium::WebDriver::BiDi::Protocol::Script::RegExpValue + attr_reader handle: untyped + attr_reader internal_id: untyped + def self.new: (?type: untyped, value: ::Selenium::WebDriver::BiDi::Protocol::Script::RegExpValue, ?handle: String?, ?internal_id: String?) -> instance + end + + class DateRemoteValue < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + attr_reader value: String + attr_reader handle: untyped + attr_reader internal_id: untyped + def self.new: (?type: untyped, value: String, ?handle: String?, ?internal_id: String?) -> instance + end + + class MapRemoteValue < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + attr_reader handle: untyped + attr_reader internal_id: untyped + attr_reader value: untyped + def self.new: (?type: untyped, ?handle: String?, ?internal_id: String?, ?value: Array[Array[untyped]]?) -> instance + end + + class SetRemoteValue < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + attr_reader handle: untyped + attr_reader internal_id: untyped + attr_reader value: untyped + def self.new: (?type: untyped, ?handle: String?, ?internal_id: String?, ?value: Array[::Selenium::WebDriver::BiDi::Protocol::Script::RemoteValue]?) -> instance + end + + class WeakMapRemoteValue < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + attr_reader handle: untyped + attr_reader internal_id: untyped + def self.new: (?type: untyped, ?handle: String?, ?internal_id: String?) -> instance + end + + class WeakSetRemoteValue < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + attr_reader handle: untyped + attr_reader internal_id: untyped + def self.new: (?type: untyped, ?handle: String?, ?internal_id: String?) -> instance + end + + class GeneratorRemoteValue < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + attr_reader handle: untyped + attr_reader internal_id: untyped + def self.new: (?type: untyped, ?handle: String?, ?internal_id: String?) -> instance + end + + class ErrorRemoteValue < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + attr_reader handle: untyped + attr_reader internal_id: untyped + def self.new: (?type: untyped, ?handle: String?, ?internal_id: String?) -> instance + end + + class ProxyRemoteValue < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + attr_reader handle: untyped + attr_reader internal_id: untyped + def self.new: (?type: untyped, ?handle: String?, ?internal_id: String?) -> instance + end + + class PromiseRemoteValue < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + attr_reader handle: untyped + attr_reader internal_id: untyped + def self.new: (?type: untyped, ?handle: String?, ?internal_id: String?) -> instance + end + + class TypedArrayRemoteValue < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + attr_reader handle: untyped + attr_reader internal_id: untyped + def self.new: (?type: untyped, ?handle: String?, ?internal_id: String?) -> instance + end + + class ArrayBufferRemoteValue < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + attr_reader handle: untyped + attr_reader internal_id: untyped + def self.new: (?type: untyped, ?handle: String?, ?internal_id: String?) -> instance + end + + class NodeListRemoteValue < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + attr_reader handle: untyped + attr_reader internal_id: untyped + attr_reader value: untyped + def self.new: (?type: untyped, ?handle: String?, ?internal_id: String?, ?value: Array[::Selenium::WebDriver::BiDi::Protocol::Script::RemoteValue]?) -> instance + end + + class HTMLCollectionRemoteValue < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + attr_reader handle: untyped + attr_reader internal_id: untyped + attr_reader value: untyped + def self.new: (?type: untyped, ?handle: String?, ?internal_id: String?, ?value: Array[::Selenium::WebDriver::BiDi::Protocol::Script::RemoteValue]?) -> instance + end + + class NodeRemoteValue < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + attr_reader shared_id: untyped + attr_reader handle: untyped + attr_reader internal_id: untyped + attr_reader value: untyped + def self.new: (?type: untyped, ?shared_id: String?, ?handle: String?, ?internal_id: String?, ?value: ::Selenium::WebDriver::BiDi::Protocol::Script::NodeProperties?) -> instance + end + + class NodeProperties < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader node_type: Integer + attr_reader child_node_count: Integer + attr_reader attributes: untyped + attr_reader children: untyped + attr_reader local_name: untyped + attr_reader mode: untyped + attr_reader namespace_uri: untyped + attr_reader node_value: untyped + attr_reader shadow_root: untyped + def self.new: (node_type: Integer, child_node_count: Integer, ?attributes: untyped, ?children: Array[::Selenium::WebDriver::BiDi::Protocol::Script::NodeRemoteValue]?, ?local_name: String?, ?mode: Symbol?, ?namespace_uri: String?, ?node_value: String?, ?shadow_root: ::Selenium::WebDriver::BiDi::Protocol::Script::NodeRemoteValue?) -> instance + end + + class WindowProxyRemoteValue < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + attr_reader value: ::Selenium::WebDriver::BiDi::Protocol::Script::WindowProxyProperties + attr_reader handle: untyped + attr_reader internal_id: untyped + def self.new: (?type: untyped, value: ::Selenium::WebDriver::BiDi::Protocol::Script::WindowProxyProperties, ?handle: String?, ?internal_id: String?) -> instance + end + + class WindowProxyProperties < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader context: String + def self.new: (context: String) -> instance + end + + class SerializationOptions < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader max_dom_depth: untyped + attr_reader max_object_depth: untyped + attr_reader include_shadow_tree: untyped + def self.new: (?max_dom_depth: Integer?, ?max_object_depth: Integer?, ?include_shadow_tree: Symbol?) -> instance + end + + class StackFrame < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader column_number: Integer + attr_reader function_name: String + attr_reader line_number: Integer + attr_reader url: String + def self.new: (column_number: Integer, function_name: String, line_number: Integer, url: String) -> instance + end + + class StackTrace < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader call_frames: Array[::Selenium::WebDriver::BiDi::Protocol::Script::StackFrame] + def self.new: (call_frames: Array[::Selenium::WebDriver::BiDi::Protocol::Script::StackFrame]) -> instance + end + + class Source < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader realm: String + attr_reader context: untyped + attr_reader user_context: untyped + def self.new: (realm: String, ?context: String?, ?user_context: String?) -> instance + end + + class RealmTarget < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader realm: String + def self.new: (realm: String) -> instance + end + + class ContextTarget < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader context: String + attr_reader sandbox: untyped + def self.new: (context: String, ?sandbox: String?) -> instance + end + + class Target < ::Selenium::WebDriver::BiDi::Serialization::Union + end + + class AddPreloadScriptParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader function_declaration: String + attr_reader arguments: untyped + attr_reader contexts: untyped + attr_reader user_contexts: untyped + attr_reader sandbox: untyped + def self.new: (function_declaration: String, ?arguments: Array[::Selenium::WebDriver::BiDi::Protocol::Script::ChannelValue]?, ?contexts: Array[String]?, ?user_contexts: Array[String]?, ?sandbox: String?) -> instance + end + + class AddPreloadScriptResult < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader script: String + def self.new: (script: String) -> instance + end + + class DisownParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader handles: Array[String] + attr_reader target: ::Selenium::WebDriver::BiDi::Protocol::Script::Target + def self.new: (handles: Array[String], target: ::Selenium::WebDriver::BiDi::Protocol::Script::Target) -> instance + end + + class CallFunctionParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader function_declaration: String + attr_reader await_promise: bool + attr_reader target: ::Selenium::WebDriver::BiDi::Protocol::Script::Target + attr_reader arguments: untyped + attr_reader result_ownership: untyped + attr_reader serialization_options: untyped + attr_reader this: untyped + attr_reader user_activation: untyped + def self.new: (function_declaration: String, await_promise: bool, target: ::Selenium::WebDriver::BiDi::Protocol::Script::Target, ?arguments: Array[::Selenium::WebDriver::BiDi::Protocol::Script::LocalValue]?, ?result_ownership: Symbol?, ?serialization_options: ::Selenium::WebDriver::BiDi::Protocol::Script::SerializationOptions?, ?this: ::Selenium::WebDriver::BiDi::Protocol::Script::LocalValue?, ?user_activation: bool?) -> instance + end + + class EvaluateParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader expression: String + attr_reader target: ::Selenium::WebDriver::BiDi::Protocol::Script::Target + attr_reader await_promise: bool + attr_reader result_ownership: untyped + attr_reader serialization_options: untyped + attr_reader user_activation: untyped + def self.new: (expression: String, target: ::Selenium::WebDriver::BiDi::Protocol::Script::Target, await_promise: bool, ?result_ownership: Symbol?, ?serialization_options: ::Selenium::WebDriver::BiDi::Protocol::Script::SerializationOptions?, ?user_activation: bool?) -> instance + end + + class GetRealmsParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader context: untyped + attr_reader type: untyped + def self.new: (?context: String?, ?type: Symbol?) -> instance + end + + class GetRealmsResult < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader realms: Array[::Selenium::WebDriver::BiDi::Protocol::Script::RealmInfo] + def self.new: (realms: Array[::Selenium::WebDriver::BiDi::Protocol::Script::RealmInfo]) -> instance + end + + class RemovePreloadScriptParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader script: String + def self.new: (script: String) -> instance + end + + class MessageParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader channel: String + attr_reader data: ::Selenium::WebDriver::BiDi::Protocol::Script::RemoteValue + attr_reader source: ::Selenium::WebDriver::BiDi::Protocol::Script::Source + def self.new: (channel: String, data: ::Selenium::WebDriver::BiDi::Protocol::Script::RemoteValue, source: ::Selenium::WebDriver::BiDi::Protocol::Script::Source) -> instance + end + + class RealmDestroyedParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader realm: String + def self.new: (realm: String) -> instance + end + + EVENT_TYPES: Hash[String, untyped] + + def add_preload_script: (function_declaration: String, ?arguments: Array[::Selenium::WebDriver::BiDi::Protocol::Script::ChannelValue]?, ?contexts: Array[String]?, ?user_contexts: Array[String]?, ?sandbox: String?) -> ::Selenium::WebDriver::BiDi::Protocol::Script::AddPreloadScriptResult + def call_function: (function_declaration: String, await_promise: bool, target: ::Selenium::WebDriver::BiDi::Protocol::Script::Target, ?arguments: Array[::Selenium::WebDriver::BiDi::Protocol::Script::LocalValue]?, ?result_ownership: Symbol?, ?serialization_options: ::Selenium::WebDriver::BiDi::Protocol::Script::SerializationOptions?, ?this: ::Selenium::WebDriver::BiDi::Protocol::Script::LocalValue?, ?user_activation: bool?) -> ::Selenium::WebDriver::BiDi::Protocol::Script::EvaluateResult + def disown: (handles: Array[String], target: ::Selenium::WebDriver::BiDi::Protocol::Script::Target) -> untyped + def evaluate: (expression: String, target: ::Selenium::WebDriver::BiDi::Protocol::Script::Target, await_promise: bool, ?result_ownership: Symbol?, ?serialization_options: ::Selenium::WebDriver::BiDi::Protocol::Script::SerializationOptions?, ?user_activation: bool?) -> ::Selenium::WebDriver::BiDi::Protocol::Script::EvaluateResult + def get_realms: (?context: String?, ?type: Symbol?) -> ::Selenium::WebDriver::BiDi::Protocol::Script::GetRealmsResult + def remove_preload_script: (script: String) -> untyped + end + end + end + end +end diff --git a/rb/sig/lib/selenium/webdriver/bidi/protocol/session.rbs b/rb/sig/lib/selenium/webdriver/bidi/protocol/session.rbs new file mode 100644 index 0000000000000..cc2f6dc8d36b1 --- /dev/null +++ b/rb/sig/lib/selenium/webdriver/bidi/protocol/session.rbs @@ -0,0 +1,165 @@ +# 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. + +# This file is automatically generated. DO NOT EDIT! +# Regenerate with: bazel run //rb/lib/selenium/webdriver:bidi-generate + +module Selenium + module WebDriver + class BiDi + module Protocol + class Session < ::Selenium::WebDriver::BiDi::Protocol::Domain + USER_PROMPT_HANDLER_TYPE: Hash[Symbol, String] + + class CapabilitiesRequest < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader always_match: untyped + attr_reader first_match: untyped + def self.new: (?always_match: ::Selenium::WebDriver::BiDi::Protocol::Session::CapabilityRequest?, ?first_match: Array[::Selenium::WebDriver::BiDi::Protocol::Session::CapabilityRequest]?) -> instance + end + + class CapabilityRequest < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader accept_insecure_certs: untyped + attr_reader browser_name: untyped + attr_reader browser_version: untyped + attr_reader platform_name: untyped + attr_reader proxy: untyped + attr_reader unhandled_prompt_behavior: untyped + attr_reader extensions: Hash[String, untyped] + def self.new: (?accept_insecure_certs: bool?, ?browser_name: String?, ?browser_version: String?, ?platform_name: String?, ?proxy: ::Selenium::WebDriver::BiDi::Protocol::Session::ProxyConfiguration?, ?unhandled_prompt_behavior: ::Selenium::WebDriver::BiDi::Protocol::Session::UserPromptHandler?, ?extensions: untyped) -> instance + end + + class ProxyConfiguration < ::Selenium::WebDriver::BiDi::Serialization::Union + end + + class AutodetectProxyConfiguration < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader proxy_type: untyped + attr_reader extensions: Hash[String, untyped] + def self.new: (?proxy_type: untyped, ?extensions: untyped) -> instance + end + + class DirectProxyConfiguration < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader proxy_type: untyped + attr_reader extensions: Hash[String, untyped] + def self.new: (?proxy_type: untyped, ?extensions: untyped) -> instance + end + + class ManualProxyConfiguration < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader proxy_type: untyped + attr_reader http_proxy: untyped + attr_reader ssl_proxy: untyped + attr_reader socks_proxy: String + attr_reader socks_version: Integer + attr_reader no_proxy: untyped + attr_reader extensions: Hash[String, untyped] + def self.new: (?proxy_type: untyped, ?http_proxy: String?, ?ssl_proxy: String?, socks_proxy: String, socks_version: Integer, ?no_proxy: Array[String]?, ?extensions: untyped) -> instance + end + + class SocksProxyConfiguration < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader socks_proxy: String + attr_reader socks_version: Integer + def self.new: (socks_proxy: String, socks_version: Integer) -> instance + end + + class PacProxyConfiguration < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader proxy_type: untyped + attr_reader proxy_autoconfig_url: String + attr_reader extensions: Hash[String, untyped] + def self.new: (?proxy_type: untyped, proxy_autoconfig_url: String, ?extensions: untyped) -> instance + end + + class SystemProxyConfiguration < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader proxy_type: untyped + attr_reader extensions: Hash[String, untyped] + def self.new: (?proxy_type: untyped, ?extensions: untyped) -> instance + end + + class UserPromptHandler < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader alert: untyped + attr_reader before_unload: untyped + attr_reader confirm: untyped + attr_reader default: untyped + attr_reader file: untyped + attr_reader prompt: untyped + def self.new: (?alert: Symbol?, ?before_unload: Symbol?, ?confirm: Symbol?, ?default: Symbol?, ?file: Symbol?, ?prompt: Symbol?) -> instance + end + + class SubscribeParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader events: Array[String] + attr_reader contexts: untyped + attr_reader user_contexts: untyped + def self.new: (events: Array[String], ?contexts: Array[String]?, ?user_contexts: Array[String]?) -> instance + end + + class UnsubscribeByIDRequest < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader subscriptions: Array[String] + def self.new: (subscriptions: Array[String]) -> instance + end + + class UnsubscribeByAttributesRequest < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader events: Array[String] + def self.new: (events: Array[String]) -> instance + end + + class StatusResult < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader ready: bool + attr_reader message: String + def self.new: (ready: bool, message: String) -> instance + end + + class NewParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader capabilities: ::Selenium::WebDriver::BiDi::Protocol::Session::CapabilitiesRequest + def self.new: (capabilities: ::Selenium::WebDriver::BiDi::Protocol::Session::CapabilitiesRequest) -> instance + end + + class NewResult < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader session_id: String + attr_reader capabilities: ::Selenium::WebDriver::BiDi::Protocol::Session::NewResult::Capabilities + def self.new: (session_id: String, capabilities: ::Selenium::WebDriver::BiDi::Protocol::Session::NewResult::Capabilities) -> instance + + class Capabilities < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader accept_insecure_certs: bool + attr_reader browser_name: String + attr_reader browser_version: String + attr_reader platform_name: String + attr_reader set_window_rect: bool + attr_reader user_agent: String + attr_reader proxy: untyped + attr_reader unhandled_prompt_behavior: untyped + attr_reader web_socket_url: untyped + attr_reader extensions: Hash[String, untyped] + def self.new: (accept_insecure_certs: bool, browser_name: String, browser_version: String, platform_name: String, set_window_rect: bool, user_agent: String, ?proxy: ::Selenium::WebDriver::BiDi::Protocol::Session::ProxyConfiguration?, ?unhandled_prompt_behavior: ::Selenium::WebDriver::BiDi::Protocol::Session::UserPromptHandler?, ?web_socket_url: String?, ?extensions: untyped) -> instance + end + end + + class SubscribeResult < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader subscription: String + def self.new: (subscription: String) -> instance + end + + class UnsubscribeParameters < ::Selenium::WebDriver::BiDi::Serialization::Union + end + + def end_: () -> untyped + def new: (capabilities: ::Selenium::WebDriver::BiDi::Protocol::Session::CapabilitiesRequest) -> ::Selenium::WebDriver::BiDi::Protocol::Session::NewResult + def status: () -> ::Selenium::WebDriver::BiDi::Protocol::Session::StatusResult + def subscribe: (events: Array[String], ?contexts: Array[String]?, ?user_contexts: Array[String]?) -> ::Selenium::WebDriver::BiDi::Protocol::Session::SubscribeResult + def unsubscribe: (?events: Array[String]?, ?subscriptions: Array[String]?) -> untyped + end + end + end + end +end diff --git a/rb/sig/lib/selenium/webdriver/bidi/protocol/speculation.rbs b/rb/sig/lib/selenium/webdriver/bidi/protocol/speculation.rbs new file mode 100644 index 0000000000000..a6561a8ff38cb --- /dev/null +++ b/rb/sig/lib/selenium/webdriver/bidi/protocol/speculation.rbs @@ -0,0 +1,43 @@ +# 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. + +# This file is automatically generated. DO NOT EDIT! +# Regenerate with: bazel run //rb/lib/selenium/webdriver:bidi-generate + +module Selenium + module WebDriver + class BiDi + module Protocol + class Speculation < ::Selenium::WebDriver::BiDi::Protocol::Domain + EVENTS: Hash[Symbol, String] + + PRELOADING_STATUS: Hash[Symbol, String] + + class PrefetchStatusUpdatedParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader context: String + attr_reader url: String + attr_reader status: Symbol + def self.new: (context: String, url: String, status: Symbol) -> instance + end + + EVENT_TYPES: Hash[String, untyped] + + end + end + end + end +end diff --git a/rb/sig/lib/selenium/webdriver/bidi/protocol/storage.rbs b/rb/sig/lib/selenium/webdriver/bidi/protocol/storage.rbs new file mode 100644 index 0000000000000..cc8eaec2c8514 --- /dev/null +++ b/rb/sig/lib/selenium/webdriver/bidi/protocol/storage.rbs @@ -0,0 +1,118 @@ +# 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. + +# This file is automatically generated. DO NOT EDIT! +# Regenerate with: bazel run //rb/lib/selenium/webdriver:bidi-generate + +module Selenium + module WebDriver + class BiDi + module Protocol + class Storage < ::Selenium::WebDriver::BiDi::Protocol::Domain + class PartitionKey < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader user_context: untyped + attr_reader source_origin: untyped + attr_reader extensions: Hash[String, untyped] + def self.new: (?user_context: String?, ?source_origin: String?, ?extensions: untyped) -> instance + end + + class CookieFilter < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader name: untyped + attr_reader value: untyped + attr_reader domain: untyped + attr_reader path: untyped + attr_reader size: untyped + attr_reader http_only: untyped + attr_reader secure: untyped + attr_reader same_site: untyped + attr_reader expiry: untyped + attr_reader extensions: Hash[String, untyped] + def self.new: (?name: String?, ?value: ::Selenium::WebDriver::BiDi::Protocol::Network::BytesValue?, ?domain: String?, ?path: String?, ?size: Integer?, ?http_only: bool?, ?secure: bool?, ?same_site: Symbol?, ?expiry: Integer?, ?extensions: untyped) -> instance + end + + class BrowsingContextPartitionDescriptor < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + attr_reader context: String + def self.new: (?type: untyped, context: String) -> instance + end + + class StorageKeyPartitionDescriptor < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + attr_reader user_context: untyped + attr_reader source_origin: untyped + attr_reader extensions: Hash[String, untyped] + def self.new: (?type: untyped, ?user_context: String?, ?source_origin: String?, ?extensions: untyped) -> instance + end + + class PartitionDescriptor < ::Selenium::WebDriver::BiDi::Serialization::Union + end + + class GetCookiesParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader filter: untyped + attr_reader partition: untyped + def self.new: (?filter: ::Selenium::WebDriver::BiDi::Protocol::Storage::CookieFilter?, ?partition: ::Selenium::WebDriver::BiDi::Protocol::Storage::PartitionDescriptor?) -> instance + end + + class GetCookiesResult < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader cookies: Array[::Selenium::WebDriver::BiDi::Protocol::Network::Cookie] + attr_reader partition_key: ::Selenium::WebDriver::BiDi::Protocol::Storage::PartitionKey + def self.new: (cookies: Array[::Selenium::WebDriver::BiDi::Protocol::Network::Cookie], partition_key: ::Selenium::WebDriver::BiDi::Protocol::Storage::PartitionKey) -> instance + end + + class PartialCookie < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader name: String + attr_reader value: ::Selenium::WebDriver::BiDi::Protocol::Network::BytesValue + attr_reader domain: String + attr_reader path: untyped + attr_reader http_only: untyped + attr_reader secure: untyped + attr_reader same_site: untyped + attr_reader expiry: untyped + attr_reader extensions: Hash[String, untyped] + def self.new: (name: String, value: ::Selenium::WebDriver::BiDi::Protocol::Network::BytesValue, domain: String, ?path: String?, ?http_only: bool?, ?secure: bool?, ?same_site: Symbol?, ?expiry: Integer?, ?extensions: untyped) -> instance + end + + class SetCookieParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader cookie: ::Selenium::WebDriver::BiDi::Protocol::Storage::PartialCookie + attr_reader partition: untyped + def self.new: (cookie: ::Selenium::WebDriver::BiDi::Protocol::Storage::PartialCookie, ?partition: ::Selenium::WebDriver::BiDi::Protocol::Storage::PartitionDescriptor?) -> instance + end + + class SetCookieResult < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader partition_key: ::Selenium::WebDriver::BiDi::Protocol::Storage::PartitionKey + def self.new: (partition_key: ::Selenium::WebDriver::BiDi::Protocol::Storage::PartitionKey) -> instance + end + + class DeleteCookiesParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader filter: untyped + attr_reader partition: untyped + def self.new: (?filter: ::Selenium::WebDriver::BiDi::Protocol::Storage::CookieFilter?, ?partition: ::Selenium::WebDriver::BiDi::Protocol::Storage::PartitionDescriptor?) -> instance + end + + class DeleteCookiesResult < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader partition_key: ::Selenium::WebDriver::BiDi::Protocol::Storage::PartitionKey + def self.new: (partition_key: ::Selenium::WebDriver::BiDi::Protocol::Storage::PartitionKey) -> instance + end + + def delete_cookies: (?filter: ::Selenium::WebDriver::BiDi::Protocol::Storage::CookieFilter?, ?partition: ::Selenium::WebDriver::BiDi::Protocol::Storage::PartitionDescriptor?) -> ::Selenium::WebDriver::BiDi::Protocol::Storage::DeleteCookiesResult + def get_cookies: (?filter: ::Selenium::WebDriver::BiDi::Protocol::Storage::CookieFilter?, ?partition: ::Selenium::WebDriver::BiDi::Protocol::Storage::PartitionDescriptor?) -> ::Selenium::WebDriver::BiDi::Protocol::Storage::GetCookiesResult + def set_cookie: (cookie: ::Selenium::WebDriver::BiDi::Protocol::Storage::PartialCookie, ?partition: ::Selenium::WebDriver::BiDi::Protocol::Storage::PartitionDescriptor?) -> ::Selenium::WebDriver::BiDi::Protocol::Storage::SetCookieResult + end + end + end + end +end diff --git a/rb/sig/lib/selenium/webdriver/bidi/protocol/user_agent_client_hints.rbs b/rb/sig/lib/selenium/webdriver/bidi/protocol/user_agent_client_hints.rbs new file mode 100644 index 0000000000000..5151aebeed764 --- /dev/null +++ b/rb/sig/lib/selenium/webdriver/bidi/protocol/user_agent_client_hints.rbs @@ -0,0 +1,58 @@ +# 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. + +# This file is automatically generated. DO NOT EDIT! +# Regenerate with: bazel run //rb/lib/selenium/webdriver:bidi-generate + +module Selenium + module WebDriver + class BiDi + module Protocol + class UserAgentClientHints < ::Selenium::WebDriver::BiDi::Protocol::Domain + class ClientHintsMetadata < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader brands: untyped + attr_reader full_version_list: untyped + attr_reader platform: untyped + attr_reader platform_version: untyped + attr_reader architecture: untyped + attr_reader model: untyped + attr_reader mobile: untyped + attr_reader bitness: untyped + attr_reader wow64: untyped + attr_reader form_factors: untyped + def self.new: (?brands: Array[::Selenium::WebDriver::BiDi::Protocol::UserAgentClientHints::BrandVersion]?, ?full_version_list: Array[::Selenium::WebDriver::BiDi::Protocol::UserAgentClientHints::BrandVersion]?, ?platform: String?, ?platform_version: String?, ?architecture: String?, ?model: String?, ?mobile: bool?, ?bitness: String?, ?wow64: bool?, ?form_factors: Array[String]?) -> instance + end + + class BrandVersion < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader brand: String + attr_reader version: String + def self.new: (brand: String, version: String) -> instance + end + + class SetClientHintsOverrideCommandParams < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader client_hints: ::Selenium::WebDriver::BiDi::Protocol::UserAgentClientHints::ClientHintsMetadata? + attr_reader contexts: untyped + attr_reader user_contexts: untyped + def self.new: (client_hints: ::Selenium::WebDriver::BiDi::Protocol::UserAgentClientHints::ClientHintsMetadata?, ?contexts: Array[String]?, ?user_contexts: Array[String]?) -> instance + end + + def set_client_hints_override: (client_hints: ::Selenium::WebDriver::BiDi::Protocol::UserAgentClientHints::ClientHintsMetadata?, ?contexts: Array[String]?, ?user_contexts: Array[String]?) -> untyped + end + end + end + end +end diff --git a/rb/sig/lib/selenium/webdriver/bidi/protocol/web_extension.rbs b/rb/sig/lib/selenium/webdriver/bidi/protocol/web_extension.rbs new file mode 100644 index 0000000000000..bf57142593348 --- /dev/null +++ b/rb/sig/lib/selenium/webdriver/bidi/protocol/web_extension.rbs @@ -0,0 +1,68 @@ +# 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. + +# This file is automatically generated. DO NOT EDIT! +# Regenerate with: bazel run //rb/lib/selenium/webdriver:bidi-generate + +module Selenium + module WebDriver + class BiDi + module Protocol + class WebExtension < ::Selenium::WebDriver::BiDi::Protocol::Domain + class InstallParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader extension_data: ::Selenium::WebDriver::BiDi::Protocol::WebExtension::ExtensionData + def self.new: (extension_data: ::Selenium::WebDriver::BiDi::Protocol::WebExtension::ExtensionData) -> instance + end + + class ExtensionData < ::Selenium::WebDriver::BiDi::Serialization::Union + end + + class ExtensionPath < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + attr_reader path: String + def self.new: (?type: untyped, path: String) -> instance + end + + class ExtensionArchivePath < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + attr_reader path: String + def self.new: (?type: untyped, path: String) -> instance + end + + class ExtensionBase64Encoded < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader type: untyped + attr_reader value: String + def self.new: (?type: untyped, value: String) -> instance + end + + class InstallResult < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader extension: String + def self.new: (extension: String) -> instance + end + + class UninstallParameters < ::Selenium::WebDriver::BiDi::Serialization::Record + attr_reader extension: String + def self.new: (extension: String) -> instance + end + + def install: (extension_data: ::Selenium::WebDriver::BiDi::Protocol::WebExtension::ExtensionData) -> ::Selenium::WebDriver::BiDi::Protocol::WebExtension::InstallResult + def uninstall: (extension: String) -> untyped + end + end + end + end +end diff --git a/rb/sig/lib/selenium/webdriver/bidi/serialization.rbs b/rb/sig/lib/selenium/webdriver/bidi/serialization.rbs new file mode 100644 index 0000000000000..947c3a704a016 --- /dev/null +++ b/rb/sig/lib/selenium/webdriver/bidi/serialization.rbs @@ -0,0 +1,119 @@ +# 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 + module Serialization + UNSET: untyped + + def self.validate!: (String name, untyped value, untyped enum) -> void + + def self.to_wire: (untyped value, untyped enum) -> untyped + + def self.to_symbol: (String name, untyped value, untyped enum) -> untyped + + class Record < ::Data + def self.define: (**untyped spec) -> singleton(Record) + + def self.field: (Symbol name, untyped meta) -> untyped + + def self.fields: () -> Array[untyped] + + def self.extensible?: () -> bool + + def self.from_json: (untyped json_payload) -> instance + + def as_json: (*untyped) -> Hash[String, untyped] + + interface _Constructor + def fields: () -> Array[untyped] + + def extensible?: () -> bool + + def construct: (**untyped attributes) -> untyped + + def name: () -> String? + end + + module Deserializer : _Constructor + def new: (**untyped kwargs) -> untyped + + def from_json: (untyped json_payload) -> untyped + + private + + def validate_values: (Hash[Symbol, untyped] attributes) -> void + + def check_outbound_shape: (untyped field, untyped value) -> void + + def fixed?: (untyped field) -> bool + + def wire_value: (untyped field, Hash[untyped, untyped] json_payload) -> untyped + + def read: (untyped field, untyped raw) -> untyped + + def check_shape: (untyped field, untyped raw) -> void + + def enum_hash: (untyped field) -> untyped + + def read_list: (untyped raw, untyped klass) -> untyped + + def extra: (Hash[untyped, untyped] json_payload) -> Hash[untyped, untyped] + end + + interface _Serializable + def extensions: () -> Hash[String, untyped] + + def class: () -> _Constructor + end + + module Serializable : _Serializable + def self.as_json: (untyped value) -> untyped + + def as_json: (*untyped) -> Hash[String, untyped] + end + end + + class Union + def self.discriminator: (String json_key, ?Hash[Symbol, String] values) -> void + + def self.variants: (Hash[untyped, String] table) -> Hash[untyped, String] + + def self.presence: (Hash[String, Array[String]] rules) -> Hash[String, Array[String]] + + def self.fallback: (String path) -> String + + def self.from_json: (untyped json_payload) -> untyped + + def self.build: (**untyped kwargs) -> untyped + + private + + def self.select: (Hash[untyped, untyped] json_payload) -> untyped + + def self.outbound_variant: (Hash[untyped, untyped] kwargs) -> untyped + + def self.variant_for: (untyped tag) { (untyped) -> untyped } -> untyped + + def self.payload_tag: (Hash[untyped, untyped] json_payload) -> untyped + end + end + end + end +end diff --git a/rb/sig/lib/selenium/webdriver/bidi/transport.rbs b/rb/sig/lib/selenium/webdriver/bidi/transport.rbs new file mode 100644 index 0000000000000..829fbf723857c --- /dev/null +++ b/rb/sig/lib/selenium/webdriver/bidi/transport.rbs @@ -0,0 +1,37 @@ +# 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 Transport + @connection: untyped + + def initialize: (untyped connection) -> void + + def execute: (cmd: String, ?params: untyped, ?result: untyped) -> untyped + + private + + def serialize: (untyped params) -> untyped + + def error_message: (Hash[String, untyped] reply) -> String + end + end + end +end diff --git a/rb/sig/lib/selenium/webdriver/remote/bidi_bridge.rbs b/rb/sig/lib/selenium/webdriver/remote/bidi_bridge.rbs index c314ccec06019..ec33a48650628 100644 --- a/rb/sig/lib/selenium/webdriver/remote/bidi_bridge.rbs +++ b/rb/sig/lib/selenium/webdriver/remote/bidi_bridge.rbs @@ -24,6 +24,8 @@ module Selenium attr_reader bidi: BiDi + attr_reader transport: BiDi::Transport + def create_session: (untyped capabilities) -> void def get: (String url) -> void diff --git a/rb/sig/lib/selenium/webdriver/remote/bridge.rbs b/rb/sig/lib/selenium/webdriver/remote/bridge.rbs index d89af1bf499ec..b8ac697c94089 100644 --- a/rb/sig/lib/selenium/webdriver/remote/bridge.rbs +++ b/rb/sig/lib/selenium/webdriver/remote/bridge.rbs @@ -52,6 +52,8 @@ module Selenium def bidi: -> BiDi + def transport: -> BiDi::Transport + def cancel_fedcm_dialog: -> nil def click_fedcm_dialog_button: -> nil diff --git a/rb/spec/integration/selenium/webdriver/bidi/protocol_browser_spec.rb b/rb/spec/integration/selenium/webdriver/bidi/protocol_browser_spec.rb new file mode 100644 index 0000000000000..31bfdbb75b77d --- /dev/null +++ b/rb/spec/integration/selenium/webdriver/bidi/protocol_browser_spec.rb @@ -0,0 +1,86 @@ +# 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. + +require_relative '../spec_helper' +require 'selenium/webdriver/bidi/protocol' + +module Selenium + module WebDriver + class BiDi + module Protocol + describe Browser, skip_unless: {bidi: true, reason: 'only executed when bidi is enabled'} do + after { |example| reset_driver!(example: example) } + + let(:browser) { described_class.new(driver) } + + it 'creates a user context', + pending_if: {browser: %i[safari safari_preview], + reason: 'Safari does not support BiDi user contexts or getClientWindows'} do + user_context = browser.create_user_context + + expect(user_context.user_context).to be_a String + end + + it 'gets user contexts', + pending_if: {browser: %i[safari safari_preview], + reason: 'Safari does not support BiDi user contexts or getClientWindows'} do + created = browser.create_user_context.user_context + all_ids = browser.get_user_contexts.user_contexts.map(&:user_context) + + expect(all_ids).to include(created) + end + + it 'removes a user context', + pending_if: {browser: %i[safari safari_preview], + reason: 'Safari does not support BiDi user contexts or getClientWindows'} do + to_remove = browser.create_user_context.user_context + browser.remove_user_context(user_context: to_remove) + remaining = browser.get_user_contexts.user_contexts.map(&:user_context) + + expect(remaining).not_to include(to_remove) + end + + 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 + expect { + browser.remove_user_context(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', + pending_if: {browser: %i[safari safari_preview], + reason: 'Safari does not support BiDi user contexts or getClientWindows'} do + expect { + browser.remove_user_context(user_context: 'fake_context') + }.to raise_error(Error::WebDriverError) + end + + it 'gets client windows', + pending_if: {browser: %i[safari safari_preview], + reason: 'Safari does not support BiDi user contexts or getClientWindows'} do + windows = browser.get_client_windows.client_windows + + expect(windows.first).to be_a(Browser::ClientWindowInfo) + end + end + end # Protocol + end # BiDi + end # WebDriver +end # Selenium diff --git a/rb/spec/integration/selenium/webdriver/bidi/protocol_browsing_context_spec.rb b/rb/spec/integration/selenium/webdriver/bidi/protocol_browsing_context_spec.rb new file mode 100644 index 0000000000000..1aa8d90798001 --- /dev/null +++ b/rb/spec/integration/selenium/webdriver/bidi/protocol_browsing_context_spec.rb @@ -0,0 +1,136 @@ +# 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. + +require_relative '../spec_helper' +require 'selenium/webdriver/bidi/protocol' + +module Selenium + module WebDriver + class BiDi + module Protocol + describe BrowsingContext, skip_unless: {bidi: true, reason: 'only executed when bidi is enabled'} do + after { |example| reset_driver!(example: example) } + + let(:browsing_context) { described_class.new(driver) } + + it 'errors when bidi not enabled' do + reset_driver!(web_socket_url: false) do |driver| + msg = /BiDi must be enabled by setting #web_socket_url to true in options class/ + expect { described_class.new(driver) }.to raise_error(WebDriver::Error::WebDriverError, msg) + end + end + + describe '#create' do + it 'accepts a tab type' do + id = browsing_context.create(type: :tab).context + + expect(driver.window_handles).to include(id) + end + + it 'accepts a window type' do + id = browsing_context.create(type: :window).context + + expect(driver.window_handles).to include(id) + end + + it 'accepts a reference context' do + id = driver.window_handle + result = browsing_context.create(type: :tab, reference_context: id).context + + expect(driver.window_handles).to include(id, result) + end + + it 'rejects an unknown type before sending it' do + expect { + browsing_context.create(type: :unknown) + }.to raise_error(ArgumentError, /type must be one of/) + end + end + + it 'closes a window' do + window1 = browsing_context.create(type: :tab).context + window2 = browsing_context.create(type: :tab).context + + browsing_context.close(context: window2) + + handles = driver.window_handles + expect(handles).to include(window1) + expect(handles).not_to include(window2) + end + + it 'sets the viewport' do + browsing_context.set_viewport( + context: driver.window_handle, + viewport: BrowsingContext::Viewport.new(width: 800, height: 600), + device_pixel_ratio: 2.0 + ) + + expect(driver.execute_script('return [window.innerWidth, window.innerHeight]')).to eq([800, 600]) + end + + it 'accepts users prompts without text', + pending_if: {browser: %i[edge chrome], + reason: 'https://github.com/GoogleChromeLabs/chromium-bidi/issues/3281'} do + driver.navigate.to url_for('alerts.html') + driver.find_element(id: 'alert').click + wait_for_alert + browsing_context.handle_user_prompt(context: driver.window_handle, accept: true) + wait_for_no_alert + + expect(driver.title).to eq('Testing Alerts') + end + + it 'accepts users prompts with text', + pending_if: {browser: %i[edge chrome], + reason: 'https://github.com/GoogleChromeLabs/chromium-bidi/issues/3281'} do + driver.navigate.to url_for('alerts.html') + driver.find_element(id: 'prompt').click + wait_for_alert + browsing_context.handle_user_prompt(context: driver.window_handle, accept: true, user_text: 'Hello, world!') + wait_for_no_alert + + expect(driver.title).to eq('Testing Alerts') + end + + it 'rejects users prompts', + pending_if: {browser: %i[edge chrome], + reason: 'https://github.com/GoogleChromeLabs/chromium-bidi/issues/3281'} do + driver.navigate.to url_for('alerts.html') + driver.find_element(id: 'alert').click + wait_for_alert + browsing_context.handle_user_prompt(context: driver.window_handle, accept: false) + wait_for_no_alert + + expect(driver.title).to eq('Testing Alerts') + end + + it 'activates a browser context', + pending_if: {browser: %i[safari safari_preview], reason: 'Safari does not focus the activated context'} do + window = driver.window_handle + browsing_context.create(type: :tab) + + expect(driver.execute_script('return document.hasFocus();')).to be_falsey + browsing_context.activate(context: window) + expect(driver.execute_script('return document.hasFocus();')).to be_truthy + end + end + end # Protocol + end # BiDi + end # WebDriver +end # Selenium diff --git a/rb/spec/unit/selenium/webdriver/bidi/protocol_spec.rb b/rb/spec/unit/selenium/webdriver/bidi/protocol_spec.rb new file mode 100644 index 0000000000000..964476fc4349e --- /dev/null +++ b/rb/spec/unit/selenium/webdriver/bidi/protocol_spec.rb @@ -0,0 +1,97 @@ +# 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. + +require File.expand_path('../spec_helper', __dir__) +require File.expand_path('../../../../../lib/selenium/webdriver/bidi/protocol', __dir__) +require File.expand_path('../../../../../lib/selenium/webdriver/bidi/transport', __dir__) + +module Selenium + module WebDriver + class BiDi + module Protocol + describe 'generated command surface' do + let(:connection) { instance_double(WebDriver::WebSocketConnection) } + let(:transport) { Transport.new(connection) } + + describe 'construction' do + it 'is driven by the transport it is given' do + expect(BrowsingContext.new(transport).instance_variable_get(:@transport)).to be(transport) + end + + it 'raises without a driver or transport' do + expect { BrowsingContext.new(Object.new) } + .to raise_error(Error::WebDriverError, /Driver or Transport/) + end + end + + describe 'enum argument validation' do + it 'raises on a value outside the allowed enum set, before any wire call' do + expect { BrowsingContext.new(transport).navigate(context: 'c', url: 'x', wait: :tomorrow) } + .to raise_error(ArgumentError, /wait must be one of/) + end + + it 'validates each element of a list-valued enum' do + expect { Network.new(transport).add_data_collector(data_types: %i[bogus], max_encoded_data_size: 1) } + .to raise_error(ArgumentError, /dataTypes must be one of/) + end + + it 'validates a union discriminator against the combined allowed set' do + expect { Network.new(transport).continue_with_auth(request: 'r', action: :bogus) } + .to raise_error(ArgumentError, /action must be one of.*provide_credentials.*default.*cancel/) + end + + it 'passes an allowed value through to the transport' do + allow(connection).to receive(:send_cmd).and_return('result' => {'navigation' => 'n', 'url' => 'u'}) + + BrowsingContext.new(transport).navigate(context: 'c', url: 'u', wait: :complete) + + expect(connection).to have_received(:send_cmd) + .with(method: 'browsingContext.navigate', params: hash_including('wait' => 'complete')) + end + end + + describe 'a command driven through the transport' do + it 'marshals params (dropping nils) and parses the typed result' do + allow(connection).to receive(:send_cmd).and_return('result' => {'navigation' => 'n1', 'url' => 'https://x'}) + + result = BrowsingContext.new(transport).navigate(context: 'c', url: 'https://x') + + expect(connection).to have_received(:send_cmd) + .with(method: 'browsingContext.navigate', params: {'context' => 'c', 'url' => 'https://x'}) + expect(result).to be_a(BrowsingContext::NavigateResult) + expect(result.url).to eq('https://x') + expect(result.navigation).to eq('n1') + end + end + + describe 'inbound event dispatch' do + it 'maps an event wire method to the type its params parse into' do + type = BrowsingContext::EVENT_TYPES['browsingContext.load'] + parsed = type.from_json('context' => 'c', 'navigation' => 'n', 'timestamp' => 1, 'url' => 'https://x') + + expect(type).to eq(BrowsingContext::NavigationInfo) + expect(parsed).to be_a(BrowsingContext::NavigationInfo) + expect(parsed.url).to eq('https://x') + end + end + end + end # Protocol + end # BiDi + end # WebDriver +end # Selenium diff --git a/rb/spec/unit/selenium/webdriver/bidi/serialization_spec.rb b/rb/spec/unit/selenium/webdriver/bidi/serialization_spec.rb new file mode 100644 index 0000000000000..4b91a473807c4 --- /dev/null +++ b/rb/spec/unit/selenium/webdriver/bidi/serialization_spec.rb @@ -0,0 +1,273 @@ +# 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. + +require File.expand_path('../spec_helper', __dir__) +require File.expand_path('../../../../../lib/selenium/webdriver/bidi/protocol', __dir__) + +module Selenium + module WebDriver + class BiDi + module Protocol + describe 'serialization runtime' do + describe 'a record with a baked discriminator' do + it 'round-trips through the wire' do + locator = BrowsingContext::CssLocator.new(value: '.foo') + + expect(locator.as_json).to eq('type' => 'css', 'value' => '.foo') + expect(BrowsingContext::CssLocator.from_json(locator.as_json)).to eq(locator) + end + + it 'forces the discriminator and omits an unset field (required-enforcement is Phase 4)' do + expect(BrowsingContext::CssLocator.new.as_json).to eq('type' => 'css') + end + end + + describe 'discriminated union dispatch' do + it 'selects the variant by its discriminator value' do + parsed = BrowsingContext::Locator.from_json('type' => 'css', 'value' => '.x') + + expect(parsed).to be_a(BrowsingContext::CssLocator) + expect(parsed.value).to eq('.x') + end + + it 'selects a variant by which fields are present when there is no discriminator' do + parsed = Script::RemoteReference.from_json('sharedId' => 'abc') + + expect(parsed).to be_a(Script::SharedReference) + expect(parsed.shared_id).to eq('abc') + end + + it 'dispatches the LocalValue date and regexp variants restored upstream' do + expect(Script::LocalValue.from_json('type' => 'date', 'value' => '2026-01-01')) + .to be_a(Script::DateLocalValue) + expect(Script::LocalValue.from_json('type' => 'regexp', 'value' => {'pattern' => 'ab+c'})) + .to be_a(Script::RegExpLocalValue) + end + + it 'dispatches NullValue by its "null" string tag and bakes the tag on serialization' do + expect(Script::NullValue.new.as_json).to eq('type' => 'null') + expect(Script::LocalValue.from_json('type' => 'null')).to eq(Script::NullValue.new) + end + + it 'raises on a variant outside our schema instead of passing the raw payload through' do + payload = {'type' => 'futuristic', 'value' => 'x'} + + expect { BrowsingContext::Locator.from_json(payload) } + .to raise_error(Error::WebDriverError, /variant not in this Selenium's BiDi schema/) + end + end + + describe 'nested structured fields' do + let(:cookie) do + Network::Cookie.new( + name: 'sid', value: Network::StringValue.new(value: 'YQ=='), + domain: 'example.com', path: '/', size: 3, + http_only: false, secure: true, same_site: :none + ) + end + + it 'serializes a nested value object into its wire hash' do + expect(cookie.as_json).to include('value' => {'type' => 'string', 'value' => 'YQ=='}) + end + + it 'parses a nested wire hash back into the value object' do + parsed = Network::Cookie.from_json(cookie.as_json) + + expect(parsed.value).to eq(Network::StringValue.new(value: 'YQ==')) + expect(parsed).to eq(cookie) + end + end + + describe 'recursive structured types' do + it 'round-trips a nested LocalValue tree through the union dispatcher' do + inner = Script::ArrayLocalValue.new(value: [Script::StringValue.new(value: 'x')]) + outer = Script::ArrayLocalValue.new(value: [Script::NumberValue.new(value: 1), inner]) + + expect(outer.as_json).to eq( + 'type' => 'array', + 'value' => [ + {'type' => 'number', 'value' => 1}, + {'type' => 'array', 'value' => [{'type' => 'string', 'value' => 'x'}]} + ] + ) + expect(Script::LocalValue.from_json(outer.as_json)).to eq(outer) + end + + it 'parses nested RemoteValues inside an object/map result (list of pairs)' do + parsed = Script::ObjectRemoteValue.from_json( + 'type' => 'object', + 'value' => [['k', {'type' => 'number', 'value' => 2}]] + ) + + key, value = parsed.value.first + expect(key).to eq('k') + expect(value).to be_a(Script::NumberValue) + expect(value.value).to eq(2) + end + end + + describe 'optional + nullable fields' do + it 'omits an unset field but emits explicit null for a nullable one' do + omitted = BrowsingContext::SetViewportParameters.new(context: 'c') + explicit = BrowsingContext::SetViewportParameters.new(context: 'c', device_pixel_ratio: nil) + + expect(omitted.as_json).to eq('context' => 'c') + expect(explicit.as_json).to eq('context' => 'c', 'devicePixelRatio' => nil) + end + end + + describe 'a const-or-null param' do + it 'sends the literal or an explicit null (not a baked tag)' do + expect(BrowsingContext::SetBypassCSPParameters.new(bypass: true).as_json).to eq('bypass' => true) + expect(BrowsingContext::SetBypassCSPParameters.new(bypass: nil).as_json).to eq('bypass' => nil) + end + end + + describe 'extensible records' do + it 'captures unknown keys and merges them back on serialization' do + parsed = Script::SharedReference.from_json('sharedId' => 's1', 'webdriverValue' => 42) + + expect(parsed.shared_id).to eq('s1') + expect(parsed.extensions).to eq('webdriverValue' => 42) + expect(parsed.as_json).to eq('sharedId' => 's1', 'webdriverValue' => 42) + end + end + + describe 'outbound union command params' do + it 'sends explicit null for a nullable union field a flat hash would have dropped' do + params = Emulation::SetGeolocationOverrideParameters.build(coordinates: nil) + + expect(params).to be_a(Emulation::SetGeolocationOverrideParameters::Coordinates) + expect(params.as_json).to eq('coordinates' => nil) + end + + it 'dispatches a structural union by which field is supplied' do + params = Emulation::SetGeolocationOverrideParameters.build(error: Emulation::GeolocationPositionError.new) + + expect(params).to be_a(Emulation::SetGeolocationOverrideParameters::Error) + expect(params.as_json).to eq('error' => {'type' => 'positionUnavailable'}) + end + + it 'rejects a non-nullable variant field set to nil (it would be dropped on the wire)' do + expect { Emulation::SetGeolocationOverrideParameters.build(error: nil) } + .to raise_error(ArgumentError, /error cannot be nil/) + end + + it 'rejects a field that does not belong to the selected variant' do + expect { Network::ContinueWithAuthParameters.build(request: 'r', action: :default, credentials: 'x') } + .to raise_error(ArgumentError, /invalid combination/) + end + + it 'dispatches a discriminated union by its value, falling back to the default variant' do + provide = Network::ContinueWithAuthParameters.build( + request: 'r', action: :provide_credentials, + credentials: Network::AuthCredentials.new(username: 'u', password: 'p') + ) + default = Network::ContinueWithAuthParameters.build(request: 'r', action: :default) + + expect(provide).to be_a(Network::ContinueWithAuthParameters::Credentials) + expect(provide.as_json).to include('action' => 'provideCredentials', + 'credentials' => {'type' => 'password', 'username' => 'u', + 'password' => 'p'}) + expect(default).to be_a(Network::ContinueWithAuthParameters::NoCredentials) + expect(default.as_json).to eq('request' => 'r', 'action' => 'default') + end + end + + describe 'value-object enum validation' do + it 'rejects an out-of-set enum value at construction, so an invalid object cannot exist' do + expect { Network::Cookie.new(name: 'c', same_site: :sideways) } + .to raise_error(ArgumentError, /Cookie#same_site must be one of/) + end + + it 'rejects an unknown keyword at construction' do + expect { Network::Cookie.new(name: 'c', bogus: 'x') } + .to raise_error(ArgumentError, /unknown keyword: :bogus/) + end + + it 'rejects a non-nullable field set to nil, instead of silently dropping it' do + expect { BrowsingContext::NavigateParameters.new(context: nil, url: 'x') } + .to raise_error(ArgumentError, /context cannot be nil/) + end + + it 'rejects a scalar passed for a list-typed field at construction' do + expect { Network::AddInterceptParameters.new(phases: :before_request_sent) } + .to raise_error(ArgumentError, /phases expected a list/) + end + + it 'rejects a non-Array enumerable for a scalar enum instead of coercing it' do + expect { Network::Cookie.new(name: 'c', same_site: Set[:none]) } + .to raise_error(ArgumentError, /same_site must be one of/) + end + + it 'raises on an inbound enum value outside our schema' do + expect { Log::ConsoleLogEntry.from_json('type' => 'console', 'level' => 'futureLevel') } + .to raise_error(Error::WebDriverError, /level received an unknown value.*futureLevel/) + end + end + + describe 'enum symbol coercion' do + it 'takes an idiomatic symbol and serializes the wire token (kebab included)' do + params = Bluetooth::SimulateAdapterParameters.new(context: 'c', state: :powered_off) + + expect(params.state).to eq(:powered_off) + expect(params.as_json).to include('state' => 'powered-off') + end + + it 'deserializes a wire token back into its symbol' do + parsed = Bluetooth::SimulateAdapterParameters.from_json('context' => 'c', 'state' => 'powered-off') + + expect(parsed.state).to eq(:powered_off) + end + + it 'raises on an unrecognized inbound token' do + expect { Bluetooth::SimulateAdapterParameters.from_json('context' => 'c', 'state' => 'powered-sideways') } + .to raise_error(Error::WebDriverError, /state received an unknown value.*powered-sideways/) + end + + it 'coerces each element of a list-valued enum' do + params = Network::AddInterceptParameters.new(phases: %i[before_request_sent auth_required]) + + expect(params.as_json).to include('phases' => %w[beforeRequestSent authRequired]) + expect(Network::AddInterceptParameters.from_json(params.as_json).phases) + .to eq(%i[before_request_sent auth_required]) + end + end + + describe 'inbound shape validation' do + it 'raises when a non-nullable field arrives as explicit null' do + expect { Network::Cookie.from_json('name' => nil) } + .to raise_error(Error::WebDriverError, /Cookie#name received null but is not nullable/) + end + + it 'raises when a list-typed field arrives as a scalar' do + expect { Network::AddInterceptParameters.from_json('phases' => 'beforeRequestSent') } + .to raise_error(Error::WebDriverError, /phases expected a list/) + end + + it 'raises when a scalar-typed field arrives as a list' do + expect { Network::Cookie.from_json('sameSite' => %w[none]) } + .to raise_error(Error::WebDriverError, /same_site expected a single value/) + end + end + end + end # Protocol + end # BiDi + end # WebDriver +end # Selenium diff --git a/rb/spec/unit/selenium/webdriver/bidi/support/bidi_generate_spec.rb b/rb/spec/unit/selenium/webdriver/bidi/support/bidi_generate_spec.rb new file mode 100644 index 0000000000000..6e85cf2a1f6af --- /dev/null +++ b/rb/spec/unit/selenium/webdriver/bidi/support/bidi_generate_spec.rb @@ -0,0 +1,47 @@ +# 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. + +require File.expand_path('../../spec_helper', __dir__) +require File.expand_path('../../../../../../lib/selenium/webdriver/bidi/support/bidi_generate', __dir__) + +module BiDiGenerate + describe '.camel_to_snake' do + it 'splits camelCase on word boundaries' do + expect(BiDiGenerate.camel_to_snake('browsingContext')).to eq('browsing_context') + end + + it 'keeps acronym runs together' do + expect(BiDiGenerate.camel_to_snake('setBypassCSP')).to eq('set_bypass_csp') + end + end + + describe '.enum_key' do + it 'maps a leading minus before a word to neg_' do + expect(BiDiGenerate.enum_key('-Infinity')).to eq('neg_infinity') + end + + it 'maps a leading minus before a digit to neg (no underscore, stays normalcase)' do + expect(BiDiGenerate.enum_key('-0')).to eq('neg0') + end + + it 'collapses punctuation' do + expect(BiDiGenerate.enum_key('dedicated-worker')).to eq('dedicated_worker') + end + end +end diff --git a/rb/spec/unit/selenium/webdriver/bidi/transport_spec.rb b/rb/spec/unit/selenium/webdriver/bidi/transport_spec.rb new file mode 100644 index 0000000000000..a6f83d043df1f --- /dev/null +++ b/rb/spec/unit/selenium/webdriver/bidi/transport_spec.rb @@ -0,0 +1,81 @@ +# 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. + +require File.expand_path('../spec_helper', __dir__) +require File.expand_path('../../../../../lib/selenium/webdriver/bidi/protocol', __dir__) +require File.expand_path('../../../../../lib/selenium/webdriver/bidi/transport', __dir__) + +module Selenium + module WebDriver + class BiDi + describe Transport do + let(:connection) { instance_double(WebDriver::WebSocketConnection) } + let(:transport) { described_class.new(connection) } + + def stub_result(result = {}) + allow(connection).to receive(:send_cmd).and_return('result' => result) + end + + it 'serializes a params object and returns the raw result by default' do + stub_result('handle' => 'h1') + params = Protocol::Browser::CreateUserContextParameters.new(accept_insecure_certs: true) + + expect(transport.execute(cmd: 'browser.createUserContext', params: params)).to eq('handle' => 'h1') + expect(connection).to have_received(:send_cmd) + .with(method: 'browser.createUserContext', params: {'acceptInsecureCerts' => true}) + end + + it 'parses the result into the declared type' do + stub_result('navigation' => 'n1', 'url' => 'https://x') + params = Protocol::BrowsingContext::NavigateParameters.new(context: 'c', url: 'https://x') + + result = transport.execute(cmd: 'browsingContext.navigate', params: params, + result: Protocol::BrowsingContext::NavigateResult) + + expect(result).to be_a(Protocol::BrowsingContext::NavigateResult) + expect(result.url).to eq('https://x') + end + + it 'sends an empty payload when there are no params' do + stub_result + transport.execute(cmd: 'browser.close') + expect(connection).to have_received(:send_cmd).with(method: 'browser.close', params: {}) + end + + it 'emits explicit wire null for a nullable field set to nil, omitting UNSET ones' do + stub_result + params = Protocol::BrowsingContext::SetViewportParameters.new(context: 'c', viewport: nil) + + transport.execute(cmd: 'browsingContext.setViewport', params: params) + + expect(connection).to have_received(:send_cmd) + .with(method: 'browsingContext.setViewport', params: {'context' => 'c', 'viewport' => nil}) + end + + it 'raises on an error reply' do + allow(connection).to receive(:send_cmd) + .and_return('error' => 'no such frame', 'message' => 'gone', 'stacktrace' => '') + + expect { transport.execute(cmd: 'browsingContext.navigate') } + .to raise_error(Error::WebDriverError, /no such frame: gone/) + end + end + end # BiDi + end # WebDriver +end # Selenium