Skip to content

Commit e85fcd3

Browse files
committed
Add support for handling user prompt
1 parent 3c87e6b commit e85fcd3

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

rb/lib/selenium/webdriver/bidi/browsing_context.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ def create(type: nil, context_id: nil)
9494
result = @bidi.send_cmd('browsingContext.create', type: type.to_s, referenceContext: context_id)
9595
result['context']
9696
end
97+
98+
def handle_user_prompt(context_id, accept: true, text: nil)
99+
@bidi.send_cmd('browsingContext.handleUserPrompt', context: context_id, accept: accept, text: text)
100+
end
97101
end
98102
end # BiDi
99103
end # WebDriver

rb/sig/lib/selenium/webdriver/bidi/browsing_context.rbs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ module Selenium
88

99
def initialize: (Remote::Bridge bridge) -> void
1010

11+
def handle_user_prompt: (String context, bool accept, String text) -> untyped
12+
1113
def navigate: (String url, String? context_id) -> void
1214

1315
def traverse_history: (Integer delta, String? context_id) -> void

rb/spec/integration/selenium/webdriver/bidi/browsing_context_spec.rb

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222
module Selenium
2323
module WebDriver
2424
class BiDi
25-
describe BrowsingContext, exclusive: {bidi: true, reason: 'only executed when bidi is enabled'},
26-
only: {browser: %i[chrome edge firefox]} do
25+
describe BrowsingContext do
2726
after { |example| reset_driver!(example: example) }
2827

2928
let(:bridge) { driver.instance_variable_get(:@bridge) }
@@ -73,6 +72,39 @@ class BiDi
7372
expect(handles).to include(window1)
7473
expect(handles).not_to include(window2)
7574
end
75+
76+
it 'accepts users prompts without text' do
77+
reset_driver!(web_socket_url: true) do |driver|
78+
browsing_context = described_class.new(driver)
79+
window = browsing_context.create
80+
81+
browsing_context.handle_user_prompt(window, accept: true)
82+
83+
expect(driver.page_source).to include('hello')
84+
end
85+
end
86+
87+
it 'accepts users prompts with text' do
88+
reset_driver!(web_socket_url: true) do |driver|
89+
browsing_context = described_class.new(driver)
90+
window = browsing_context.create
91+
92+
browsing_context.handle_user_prompt(window, accept: true, text: 'Hello, world!')
93+
94+
expect(driver.page_source).to include('hello')
95+
end
96+
end
97+
98+
it 'rejects users prompts' do
99+
reset_driver!(web_socket_url: true) do |driver|
100+
browsing_context = described_class.new(driver)
101+
window = browsing_context.create
102+
103+
browsing_context.handle_user_prompt(window, accept: false)
104+
105+
expect(driver.page_source).to include('goodbye')
106+
end
107+
end
76108
end
77109
end # BiDi
78110
end # WebDriver

0 commit comments

Comments
 (0)