[ruby][bidi] Add test for using BiDi to navigate and get exceptions
@@ -22,12 +22,37 @@ require_relative 'spec_helper'
module Selenium
module WebDriver
describe BiDi, exclusive: {browser: %i[chrome firefox]} do
+ before do
+ quit_driver
+ create_driver!(web_socket_url: true)
+ end
+
it 'gets session status' do
- reset_driver!(web_socket_url: true) do |driver|
status = driver.bidi.session.status
expect(status).to respond_to(:ready)
expect(status.message).not_to be_empty
end
+
+ it 'can navigate and listen to errors' do
+ log_entry = nil
+ log_inspector = BiDi::LogInspector.new(driver)
+ log_inspector.on_javascript_exception { |log| log_entry = log }
+
+ browsing_context = BiDi::BrowsingContext.new(driver: driver, browsing_context_id: driver.window_handle)
+ info = browsing_context.navigate(url: url_for('/bidi/logEntryAdded.html'))
+
+ expect(browsing_context.id).not_to be_nil
+ expect(info.navigation_id).to be_nil
+ expect(info.url).to include('/bidi/logEntryAdded.html')
+
+ driver.find_element(id: 'jsException').click
+ wait.until { !log_entry.nil? }
+
+ expect(log_entry).to have_attributes(
+ text: "Error: Not working",
+ type: "javascript",
+ level: BiDi::LogInspector::LOG_LEVEL[:ERROR]
+ )
end
end
end
