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

Update Ruby BiDi script structs to match spec (as of 2024-07-08) #14236

Merged
Merged
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
4 changes: 2 additions & 2 deletions rb/lib/selenium/webdriver/bidi/log_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ module Selenium
module WebDriver
class BiDi
class LogHandler
ConsoleLogEntry = BiDi::Struct.new(:level, :text, :timestamp, :method, :args, :type)
JavaScriptLogEntry = BiDi::Struct.new(:level, :text, :timestamp, :stack_trace, :type)
ConsoleLogEntry = BiDi::Struct.new(:level, :text, :timestamp, :stack_trace, :type, :source, :method, :args)
JavaScriptLogEntry = BiDi::Struct.new(:level, :text, :timestamp, :stack_trace, :type, :source)

def initialize(bidi)
@bidi = bidi
Expand Down
49 changes: 46 additions & 3 deletions rb/spec/integration/selenium/webdriver/bidi/script_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@ module WebDriver
only: {browser: %i[chrome edge firefox]} do
after { |example| reset_driver!(example: example) }

# Helper to match the expected pattern of `script.StackFrame` objects.
# https://w3c.github.io/webdriver-bidi/#type-script-StackFrame
#
# Pass in any fields you want to check more specific values for, e.g:
# a_stack_frame('functionName' => 'someFunction')
def a_stack_frame(**options)
include({
'columnNumber' => an_instance_of(Integer),
'functionName' => an_instance_of(String),
'lineNumber' => an_instance_of(Integer),
'url' => an_instance_of(String)
}.merge(options))
end

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/
Expand All @@ -45,10 +59,27 @@ module WebDriver
expect(log_entries.size).to eq(1)
log_entry = log_entries.first
expect(log_entry).to be_a BiDi::LogHandler::ConsoleLogEntry
expect(log_entry.type).to eq 'console'
expect(log_entry.level).to eq 'info'
expect(log_entry.method).to eq 'log'
expect(log_entry.text).to eq 'Hello, world!'
expect(log_entry.type).to eq 'console'
expect(log_entry.args).to eq [
{'type' => 'string', 'value' => 'Hello, world!'}
]
expect(log_entry.timestamp).to be_an_integer
expect(log_entry.source).to match(
'context' => an_instance_of(String),
'realm' => an_instance_of(String)
)
# Stack traces on console messages are optional.
expect(log_entry.stack_trace).to be_nil.or match(
# Some browsers include stack traces from parts of the runtime, so we
# just check the first frames that come from user code.
'callFrames' => start_with(
a_stack_frame('functionName' => 'helloWorld'),
a_stack_frame('functionName' => 'onclick')
)
)
end

it 'logs multiple console messages' do
Expand Down Expand Up @@ -97,10 +128,22 @@ module WebDriver
expect(log_entries.size).to eq(1)
log_entry = log_entries.first
expect(log_entry).to be_a BiDi::LogHandler::JavaScriptLogEntry
expect(log_entry.level).to eq 'error'
expect(log_entry.type).to eq 'javascript'
expect(log_entry.level).to eq 'error'
expect(log_entry.text).to eq 'Error: Not working'
expect(log_entry.stack_trace).not_to be_empty
expect(log_entry.timestamp).to be_an_integer
expect(log_entry.source).to match(
'context' => an_instance_of(String),
'realm' => an_instance_of(String)
)
expect(log_entry.stack_trace).to match(
# Some browsers include stack traces from parts of the runtime, so we
# just check the first frames that come from user code.
'callFrames' => start_with(
a_stack_frame('functionName' => 'createError'),
a_stack_frame('functionName' => 'onclick')
)
)
end

it 'errors removing non-existent handler' do
Expand Down