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 1 commit
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
Prev Previous commit
Next Next commit
[rb][bidi] added script module command and types with test
  • Loading branch information
TamsilAmani committed Jun 22, 2023
commit 93bfbba3c752014562b64be7696f9adefd066bdb
4 changes: 4 additions & 0 deletions rb/.rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,15 @@ Metrics/ModuleLength:
- 'lib/selenium/webdriver/common/platform.rb'
- 'spec/**/*'

Metrics/ParameterLists:
Enabled: false

Metrics/PerceivedComplexity:
Max: 9
Exclude:
- 'lib/selenium/webdriver/common/local_driver.rb'
- 'lib/selenium/webdriver/common/logger.rb'
- 'lib/selenium/webdriver/bidi/script/protocol_value/remote_value.rb'

Naming/FileName:
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# frozen_string_literal: true

# 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 EvaluateResultException
attr_accessor :result_type, :realm_id, :exception_details

def initialize(realm_id, exception_details)
@result_type = EvaluateResultType::EXCEPTION
@realm_id = realm_id
@exception_details = exception_details
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# frozen_string_literal: true

# 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 EvaluateResultSuccess
attr_accessor :result_type, :realm_id, :result

def initialize(realm_id, value)
@result_type = EvaluateResultType::SUCCESS
@realm_id = realm_id
@result = value
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# frozen_string_literal: true

# 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 EvaluateResultType
SUCCESS = 'success'
EXCEPTION = 'exception'
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# frozen_string_literal: true

# 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 ExceptionDetails
attr_accessor :column_number, :exception, :line_number, :stack_trace, :text

def initialize(exception_details)
@column_number = exception_details.key?('columnNumber') ? exception_details['columnNumber'] : nil
@exception = exception_details.key?('exception') ? exception_details['exception'] : nil
@line_number = exception_details.key?('lineNumber') ? exception_details['lineNumber'] : nil
@stack_trace = exception_details.key?('stackTrace') ? exception_details['stackTrace'] : nil
@text = exception_details.key?('text') ? exception_details['text'] : nil
end
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ module NonPrimitiveType

def self.find_by_name(name)
NonPrimitiveType.constants.each do |type|
return true if name.casecmp(type)
return NonPrimitiveType.const_get(type) if name.casecmp?(NonPrimitiveType.const_get(type))
end
nil
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ module PrimitiveType

def self.find_by_name(name)
PrimitiveType.constants.each do |type|
return true if name.casecmp(type)
end
return PrimitiveType.const_get(type) if name.casecmp?(PrimitiveType.const_get(type))
end; nil
end
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# frozen_string_literal = true
# frozen_string_literal: true

# Licensed to the Software Freedom Conservancy (SFC) under one
# or more contributor license agreements. See the NOTICE file
Expand Down Expand Up @@ -39,8 +39,9 @@ module RemoteType

def self.find_by_name(name)
RemoteType.constants.each do |type|
return true if name.casecmp(type)
return RemoteType.const_get(type) if name.casecmp?(RemoteType.const_get(type))
end
nil
end
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# frozen_string_literal = true
# frozen_string_literal: true

# Licensed to the Software Freedom Conservancy (SFC) under one
# or more contributor license agreements. See the NOTICE file
Expand Down
101 changes: 101 additions & 0 deletions rb/lib/selenium/webdriver/bidi/script/protocol_value/local_value.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# 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 '../protocol_type/primitive_type'
require_relative '../protocol_type/non_primitive_type'
require_relative '../protocol_type/remote_type'
require_relative '../protocol_type/special_number_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
end
end
end
Original file line number Diff line number Diff line change
@@ -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.

module Selenium
module WebDriver
class BiDi
class ReferenceValue
REMOTE_REFERENCE_TYPE = {
HANDLE: 'handle',
SHARED_ID: 'shareId'
}.freeze

def initialize(handle, share_id)
if handle.eql? REMOTE_REFERENCE_TYPE[:HANDLE]
@handle = share_id
else
@handle = handle
@share_id = share_id
end
end

def as_map
to_return = {}
to_return[REMOTE_REFERENCE_TYPE[:HANDLE]] = @handle unless @handle.nil?
to_return[REMOTE_REFERENCE_TYPE[:SHARED_ID]] = @share_id unless @share_id.nil?
to_return
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# 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 RegExpValue
def self.create(pattern:, flags: nil)
{
'pattern' => pattern,
'flags' => flags
}
end
end
end
end
end
Loading