Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rb][BiDi] Add Script module commands and types #12082

Open
wants to merge 5 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions rb/.rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ Metrics/ModuleLength:
- 'lib/selenium/webdriver/common/platform.rb'
- 'spec/**/*'

Metrics/ParameterLists:
Enabled: false

Metrics/PerceivedComplexity:
Max: 9
Exclude:
Expand Down
1 change: 1 addition & 0 deletions rb/lib/selenium/webdriver/bidi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class BiDi
autoload :Session, 'selenium/webdriver/bidi/session'
autoload :LogInspector, 'selenium/webdriver/bidi/log_inspector'
autoload :BrowsingContext, 'selenium/webdriver/bidi/browsing_context'
autoload :ScriptManager, 'selenium/webdriver/bidi/script_manager'

def initialize(url:)
@ws = WebSocketConnection.new(url: url)
Expand Down
99 changes: 99 additions & 0 deletions rb/lib/selenium/webdriver/bidi/script/local_value.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# 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 './primitive_type'
require_relative './non_primitive_type'

module Selenium
module WebDriver
class BiDi
class LocalValue
TYPE_CONSTANT = 'type'
VALUE_CONSTANT = 'value'

def initialize(type, value: nil)
@type = type
@value = value unless type.eql?(PrimitiveType::UNDEFINED) && type.eql?(PrimitiveType::NULL)
end

def self.create_string_value(value)
LocalValue.new(PrimitiveType::STRING, value: value).as_json
end

def self.create_number_value(value)
LocalValue.new(PrimitiveType::NUMBER, value: value).as_json
end

def self.create_special_number_value(value)
LocalValue.new(PrimitiveType::SPECIAL_NUMBER, value: value).as_json
end

def self.create_undefined_value
LocalValue.new(PrimitiveType::UNDEFINED).as_json
end

def self.create_null_value
LocalValue.new(PrimitiveType::NULL).as_json
end

def self.create_boolean_value(value)
LocalValue.new(PrimitiveType::BOOLEAN, value: value).as_json
end

def self.create_big_int_value(value)
LocalValue.new(PrimitiveType::BIGINT, value: value).as_json
end

def self.create_array_value(value)
LocalValue.new(NonPrimitiveType::ARRAY, value: value).as_json
end

def self.create_date_value(value)
LocalValue.new(NonPrimitiveType::DATE, value: value).as_json
end

def self.create_map_value(map)
value = []
map.each { |k, v| value.push([k, v]) }
LocalValue.new(NonPrimitiveType::MAP, value: value).as_json
end

def self.create_object_value(map)
value = []
map.each { |k, v| value.push([k, v]) }
LocalValue.new(NonPrimitiveType::OBJECT, value: value).as_json
end

def self.create_regular_expression_value(value)
LocalValue.new(NonPrimitiveType::REGULAR_EXPRESSION, value: value).as_json
end

def self.create_set_value(value)
LocalValue.new(NonPrimitiveType::SET, value: value).as_json
end

def as_json
to_return = {'type' => @type}
to_return['value'] = @value unless @type.eql?(PrimitiveType::NULL) && @type.eql?(PrimitiveType::UNDEFINED)
to_return
end
end # LocalValue
end # BiDi
end # WebDriver
end # Selenium
40 changes: 40 additions & 0 deletions rb/lib/selenium/webdriver/bidi/script/non_primitive_type.rb
Original file line number Diff line number Diff line change
@@ -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 NonPrimitiveType
ARRAY = 'array'
DATE = 'date'
MAP = 'map'
OBJECT = 'object'
REGULAR_EXPRESSION = 'regexp'
SET = 'set'

def self.find_by_name(name)
NonPrimitiveType.constants.each do |type|
return NonPrimitiveType.const_get(type) if name.casecmp?(NonPrimitiveType.const_get(type))
end
nil
end
end # NonPrimitiveType
end # BiDi
end # WebDriver
end # Selenium
40 changes: 40 additions & 0 deletions rb/lib/selenium/webdriver/bidi/script/primitive_type.rb
Original file line number Diff line number Diff line change
@@ -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 PrimitiveType
UNDEFINED = 'undefined'
NULL = 'null'
STRING = 'string'
NUMBER = 'number'
SPECIAL_NUMBER = 'number'
BOOLEAN = 'boolean'
BIGINT = 'bigint'

def self.find_by_name(name)
PrimitiveType.constants.each do |type|
return PrimitiveType.const_get(type) if name.casecmp?(PrimitiveType.const_get(type))
end; nil
end
end # PrimitiveType
end # BiDi
end # WebDriver
end # Selenium
38 changes: 38 additions & 0 deletions rb/lib/selenium/webdriver/bidi/script/reference_value.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# frozen_string_literal: true

# Licensed to the Software Freedom Conservancy (SFC) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The SFC licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

module Selenium
module WebDriver
class BiDi
class ReferenceValue
def initialize(handle: nil, share_id: nil)
@handle = handle
@share_id = share_id
end

def as_map
{
handle: @handle,
shareId: @share_id
}
end
end # ReferenceValue
end # BiDi
end # WebDriver
end # Selenium
Loading