From e85fcd3de5088379fb20d283e61c00fcdd1f0601 Mon Sep 17 00:00:00 2001 From: aguspe Date: Sun, 16 Feb 2025 23:02:51 +0100 Subject: [PATCH 1/2] Add support for handling user prompt --- .../webdriver/bidi/browsing_context.rb | 4 +++ .../webdriver/bidi/browsing_context.rbs | 2 ++ .../webdriver/bidi/browsing_context_spec.rb | 36 +++++++++++++++++-- 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/rb/lib/selenium/webdriver/bidi/browsing_context.rb b/rb/lib/selenium/webdriver/bidi/browsing_context.rb index b8f33227ce8a6..7b8e4a71bb6a3 100644 --- a/rb/lib/selenium/webdriver/bidi/browsing_context.rb +++ b/rb/lib/selenium/webdriver/bidi/browsing_context.rb @@ -94,6 +94,10 @@ def create(type: nil, context_id: nil) result = @bidi.send_cmd('browsingContext.create', type: type.to_s, referenceContext: context_id) result['context'] end + + def handle_user_prompt(context_id, accept: true, text: nil) + @bidi.send_cmd('browsingContext.handleUserPrompt', context: context_id, accept: accept, text: text) + end end end # BiDi end # WebDriver diff --git a/rb/sig/lib/selenium/webdriver/bidi/browsing_context.rbs b/rb/sig/lib/selenium/webdriver/bidi/browsing_context.rbs index 1577c22073561..102280e9f8662 100644 --- a/rb/sig/lib/selenium/webdriver/bidi/browsing_context.rbs +++ b/rb/sig/lib/selenium/webdriver/bidi/browsing_context.rbs @@ -8,6 +8,8 @@ module Selenium def initialize: (Remote::Bridge bridge) -> void + def handle_user_prompt: (String context, bool accept, String text) -> untyped + def navigate: (String url, String? context_id) -> void def traverse_history: (Integer delta, String? context_id) -> void diff --git a/rb/spec/integration/selenium/webdriver/bidi/browsing_context_spec.rb b/rb/spec/integration/selenium/webdriver/bidi/browsing_context_spec.rb index 353847a4c0bd7..836921b75bb49 100644 --- a/rb/spec/integration/selenium/webdriver/bidi/browsing_context_spec.rb +++ b/rb/spec/integration/selenium/webdriver/bidi/browsing_context_spec.rb @@ -22,8 +22,7 @@ module Selenium module WebDriver class BiDi - describe BrowsingContext, exclusive: {bidi: true, reason: 'only executed when bidi is enabled'}, - only: {browser: %i[chrome edge firefox]} do + describe BrowsingContext do after { |example| reset_driver!(example: example) } let(:bridge) { driver.instance_variable_get(:@bridge) } @@ -73,6 +72,39 @@ class BiDi expect(handles).to include(window1) expect(handles).not_to include(window2) end + + it 'accepts users prompts without text' do + reset_driver!(web_socket_url: true) do |driver| + browsing_context = described_class.new(driver) + window = browsing_context.create + + browsing_context.handle_user_prompt(window, accept: true) + + expect(driver.page_source).to include('hello') + end + end + + it 'accepts users prompts with text' do + reset_driver!(web_socket_url: true) do |driver| + browsing_context = described_class.new(driver) + window = browsing_context.create + + browsing_context.handle_user_prompt(window, accept: true, text: 'Hello, world!') + + expect(driver.page_source).to include('hello') + end + end + + it 'rejects users prompts' do + reset_driver!(web_socket_url: true) do |driver| + browsing_context = described_class.new(driver) + window = browsing_context.create + + browsing_context.handle_user_prompt(window, accept: false) + + expect(driver.page_source).to include('goodbye') + end + end end end # BiDi end # WebDriver From 03ac8c09554f0b83226f7d07788f38cbf18f1052 Mon Sep 17 00:00:00 2001 From: aguspe Date: Mon, 3 Mar 2025 14:57:12 +0100 Subject: [PATCH 2/2] Remove missing guards --- .../selenium/webdriver/bidi/browsing_context_spec.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rb/spec/integration/selenium/webdriver/bidi/browsing_context_spec.rb b/rb/spec/integration/selenium/webdriver/bidi/browsing_context_spec.rb index 836921b75bb49..b919a6ad142a4 100644 --- a/rb/spec/integration/selenium/webdriver/bidi/browsing_context_spec.rb +++ b/rb/spec/integration/selenium/webdriver/bidi/browsing_context_spec.rb @@ -22,7 +22,8 @@ module Selenium module WebDriver class BiDi - describe BrowsingContext do + describe BrowsingContext, exclusive: {bidi: true, reason: 'only executed when bidi is enabled'}, + only: {browser: %i[chrome edge firefox]} do after { |example| reset_driver!(example: example) } let(:bridge) { driver.instance_variable_get(:@bridge) }