Skip to content

Commit de5cee5

Browse files
aguspesandeepsuryaprasad
authored andcommitted
Add support for handling user prompt (SeleniumHQ#15291)
* Add support for handling user prompt * Remove missing guards
1 parent 57399d8 commit de5cee5

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

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

+4
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ def set_viewport(context_id: nil, width: nil, height: nil, device_pixel_ratio: n
100100
params = {context: context_id, viewport: {width:, height:}, device_pixel_ratio:}
101101
@bidi.send_cmd('browsingContext.setViewport', **params)
102102
end
103+
104+
def handle_user_prompt(context_id, accept: true, text: nil)
105+
@bidi.send_cmd('browsingContext.handleUserPrompt', context: context_id, accept: accept, text: text)
106+
end
103107
end
104108
end # BiDi
105109
end # WebDriver

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

+2
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 set_viewport: (String context_id, Integer width, Integer height, Float device_pixel_ratio) -> Hash[nil, nil]

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

+33
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,39 @@ class BiDi
8282
expect(driver.execute_script('return window.devicePixelRatio')).to eq(2.0)
8383
end
8484
end
85+
86+
it 'accepts users prompts without text' do
87+
reset_driver!(web_socket_url: true) do |driver|
88+
browsing_context = described_class.new(driver)
89+
window = browsing_context.create
90+
91+
browsing_context.handle_user_prompt(window, accept: true)
92+
93+
expect(driver.page_source).to include('hello')
94+
end
95+
end
96+
97+
it 'accepts users prompts with text' do
98+
reset_driver!(web_socket_url: true) do |driver|
99+
browsing_context = described_class.new(driver)
100+
window = browsing_context.create
101+
102+
browsing_context.handle_user_prompt(window, accept: true, text: 'Hello, world!')
103+
104+
expect(driver.page_source).to include('hello')
105+
end
106+
end
107+
108+
it 'rejects users prompts' do
109+
reset_driver!(web_socket_url: true) do |driver|
110+
browsing_context = described_class.new(driver)
111+
window = browsing_context.create
112+
113+
browsing_context.handle_user_prompt(window, accept: false)
114+
115+
expect(driver.page_source).to include('goodbye')
116+
end
117+
end
85118
end
86119
end # BiDi
87120
end # WebDriver

0 commit comments

Comments
 (0)