Skip to content

Commit

Permalink
[rb] Improve stability of BiDi specs for Edge
Browse files Browse the repository at this point in the history
  • Loading branch information
p0deje committed May 23, 2024
1 parent a961ede commit 062c125
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 41 deletions.
86 changes: 49 additions & 37 deletions rb/spec/integration/selenium/webdriver/bidi/log_inspector_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,83 +27,93 @@ class BiDi

it 'can listen to console log' do
reset_driver!(web_socket_url: true) do |driver|
log_entry = nil
log_entries = []
log_inspector = described_class.new(driver)
log_inspector.on_console_entry { |log| log_entry = log }
log_inspector.on_console_entry { |log| log_entries << log }

driver.navigate.to url_for(page)
driver.find_element(id: 'consoleLog').click
wait.until { !log_entry.nil? }
log_entry = wait.until { log_entries.find { _1.text == 'Hello, world!' } }

expect(log_entry).to have_attributes(
text: 'Hello, world!',
realm: nil,
type: 'console',
level: LogInspector::LOG_LEVEL[:INFO],
method: 'log'
method: 'log',
args: [{
'type' => 'string',
'value' => 'Hello, world!'
}]
)
expect(log_entry.args.size).to eq(1)
end
end

it 'can listen to console log with different consumers' do
reset_driver!(web_socket_url: true) do |driver|
log_entry = nil
log_entries1 = []
log_entries2 = []
log_inspector = described_class.new(driver)
log_inspector.on_console_entry { |log| log_entry = log }

log_entry_text = nil
log_inspector.on_console_entry { |log| log_entry_text = log.text }
log_inspector.on_console_entry { |log| log_entries1 << log }
log_inspector.on_console_entry { |log| log_entries2 << log }

driver.navigate.to url_for(page)
driver.find_element(id: 'consoleLog').click
wait.until { !log_entry.nil? }

expect(log_entry).to have_attributes(
text: 'Hello, world!',
realm: nil,
type: 'console',
level: LogInspector::LOG_LEVEL[:INFO],
method: 'log'
log_entry1 = wait.until { log_entries1.find { _1.text == 'Hello, world!' } }
log_entry2 = wait.until { log_entries2.find { _1.text == 'Hello, world!' } }

expect([log_entry1, log_entry2]).to all(
have_attributes(
text: 'Hello, world!',
realm: nil,
type: 'console',
level: LogInspector::LOG_LEVEL[:INFO],
method: 'log',
args: [{
'type' => 'string',
'value' => 'Hello, world!'
}]
)
)
expect(log_entry.args.size).to eq(1)
expect(log_entry_text).to eq('Hello, world!')
end
end

it 'can filter console info level log' do
reset_driver!(web_socket_url: true) do |driver|
log_entry = nil
log_entries = []
log_inspector = described_class.new(driver)
log_inspector.on_console_entry(FilterBy.log_level('info')) { |log| log_entry = log }
log_inspector.on_console_entry(FilterBy.log_level('info')) { |log| log_entries << log }

driver.navigate.to url_for(page)
driver.find_element(id: 'consoleLog').click
wait.until { !log_entry.nil? }
log_entry = wait.until { log_entries.find { _1.text == 'Hello, world!' } }

expect(log_entry).to have_attributes(
text: 'Hello, world!',
realm: nil,
type: 'console',
level: LogInspector::LOG_LEVEL[:INFO],
method: 'log'
method: 'log',
args: [{
'type' => 'string',
'value' => 'Hello, world!'
}]
)
expect(log_entry.args.size).to eq(1)
end
end

it 'can filter console log' do
reset_driver!(web_socket_url: true) do |driver|
log_entry = nil
log_entries = []
log_inspector = described_class.new(driver)
log_inspector.on_console_entry(FilterBy.log_level('error')) { |log| log_entry = log }
log_inspector.on_console_entry(FilterBy.log_level('error')) { |log| log_entries << log }

driver.navigate.to url_for(page)
# Generating info level log but we are filtering by error level
wait.until { driver.find_element(id: 'consoleLog').displayed? }
driver.find_element(id: 'consoleLog').click

expect(log_entry).to be_nil
expect(log_entries).to be_empty
end
end

Expand Down Expand Up @@ -178,29 +188,31 @@ class BiDi

it 'can listen to any log' do
reset_driver!(web_socket_url: true) do |driver|
log_entry = nil
log_entries = []
log_inspector = described_class.new(driver)
log_inspector.on_log { |log| log_entry = log }
log_inspector.on_log { |log| log_entries << log }

driver.navigate.to url_for(page)
driver.find_element(id: 'consoleError').click
wait.until { !log_entry.nil? }
log_entry = wait.until { log_entries.find { _1['text'] == 'I am console error' } }

expect(log_entry['text']).to eq('I am console error')
expect(log_entry['type']).to eq('console')
expect(log_entry['method']).to eq(LogInspector::LOG_LEVEL[:ERROR])
expect(log_entry).to include(
'text' => 'I am console error',
'type' => 'console',
'level' => LogInspector::LOG_LEVEL[:ERROR]
)
end
end

it 'can filter any log' do
reset_driver!(web_socket_url: true) do |driver|
log_entry = nil
log_entries = []
log_inspector = described_class.new(driver)
log_inspector.on_log(FilterBy.log_level('info')) { |log| log_entry = log }
log_inspector.on_log(FilterBy.log_level('info')) { |log| log_entries << log }

driver.navigate.to url_for(page)
driver.find_element(id: 'consoleLog').click
wait.until { !log_entry.nil? }
log_entry = wait.until { log_entries.find { _1['text'] == 'Hello, world!' } }

expect(log_entry['text']).to eq('Hello, world!')
expect(log_entry['realm']).to be_nil
Expand Down
7 changes: 3 additions & 4 deletions rb/spec/integration/selenium/webdriver/bidi_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ module WebDriver
end

it 'can navigate and listen to errors' do
log_entry = nil
log_entries = []
log_inspector = BiDi::LogInspector.new(driver)
log_inspector.on_javascript_exception { |log| log_entry = log }
log_inspector.on_javascript_exception { |log| log_entries << log }

browsing_context = BiDi::BrowsingContext.new(driver: driver, browsing_context_id: driver.window_handle)
info = browsing_context.navigate(url: url_for('/bidi/logEntryAdded.html'))
Expand All @@ -51,8 +51,7 @@ module WebDriver
js_exception = wait.until { driver.find_element(id: 'jsException') }
js_exception.click

wait.until { !log_entry.nil? }

log_entry = wait.until { log_entries.find { _1.text == 'Error: Not working' } }
expect(log_entry).to have_attributes(
text: 'Error: Not working',
type: 'javascript',
Expand Down

0 comments on commit 062c125

Please sign in to comment.