From 062c125c062eea270c9ce8dafcb8f92f32e1bf51 Mon Sep 17 00:00:00 2001 From: Alex Rodionov Date: Thu, 23 May 2024 15:41:35 -0700 Subject: [PATCH] [rb] Improve stability of BiDi specs for Edge --- .../webdriver/bidi/log_inspector_spec.rb | 86 +++++++++++-------- .../selenium/webdriver/bidi_spec.rb | 7 +- 2 files changed, 52 insertions(+), 41 deletions(-) diff --git a/rb/spec/integration/selenium/webdriver/bidi/log_inspector_spec.rb b/rb/spec/integration/selenium/webdriver/bidi/log_inspector_spec.rb index d546657d6aa5f..24da3ede70771 100644 --- a/rb/spec/integration/selenium/webdriver/bidi/log_inspector_spec.rb +++ b/rb/spec/integration/selenium/webdriver/bidi/log_inspector_spec.rb @@ -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 @@ -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 diff --git a/rb/spec/integration/selenium/webdriver/bidi_spec.rb b/rb/spec/integration/selenium/webdriver/bidi_spec.rb index 7604bd1cfb504..6b447803b0546 100644 --- a/rb/spec/integration/selenium/webdriver/bidi_spec.rb +++ b/rb/spec/integration/selenium/webdriver/bidi_spec.rb @@ -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')) @@ -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',