Skip to content

Commit 61a54ce

Browse files
committed
Add get windows for ruby bindings
1 parent d03e95b commit 61a54ce

File tree

4 files changed

+57
-4
lines changed

4 files changed

+57
-4
lines changed

rb/lib/selenium/webdriver/bidi/browser.rb

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ module Selenium
2121
module WebDriver
2222
class BiDi
2323
class Browser
24+
Window = Struct.new(:handle, :active, :height, :width, :x, :y, :state) do
25+
def active?
26+
active
27+
end
28+
end
2429
def initialize(bidi)
2530
@bidi = bidi
2631
end
@@ -36,7 +41,24 @@ def user_contexts
3641
def remove_user_context(user_context)
3742
@bidi.send_cmd('browser.removeUserContext', userContext: user_context)
3843
end
39-
end
44+
45+
def windows
46+
response = @bidi.send_cmd('browser.getClientWindows')
47+
48+
response['clientWindows'].map do |win_data|
49+
attributes = {
50+
handle: win_data['clientWindow'],
51+
active: win_data['active'],
52+
height: win_data['height'],
53+
width: win_data['width'],
54+
x: win_data['x'],
55+
y: win_data['y'],
56+
state: win_data['state']
57+
}
58+
Window.new(**attributes)
59+
end
60+
end
61+
end # Browser
4062
end # BiDi
4163
end # WebDriver
4264
end # Selenium

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def activate(context_id: nil)
109109
context_id ||= @bridge.window_handle
110110
@bidi.send_cmd('browsingContext.activate', context: context_id)
111111
end
112-
end
112+
end # BrowsingContext
113113
end # BiDi
114114
end # WebDriver
115115
end # Selenium

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ module Selenium
22
module WebDriver
33
class BiDi
44
class Browser
5+
Window: Selenium::WebDriver::BiDi::Browser::Window
6+
57
@bidi: BiDi
68

79
def initialize: (BiDi bidi) -> void

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

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
module Selenium
2323
module WebDriver
2424
class BiDi
25-
describe Browser, exclusive: {bidi: true, reason: 'only executed when bidi is enabled'},
26-
only: {browser: %i[chrome edge firefox]} do
25+
describe Browser, exclusive: { bidi: true, reason: 'only executed when bidi is enabled' },
26+
only: { browser: %i[chrome edge firefox] } do
2727
it 'creates an user context' do
2828
reset_driver!(web_socket_url: true) do |driver|
2929
browser = described_class.new(driver.bidi)
@@ -71,6 +71,35 @@ class BiDi
7171
}.to raise_error(Error::WebDriverError)
7272
end
7373
end
74+
75+
it 'get windows' do
76+
reset_driver!(web_socket_url: true) do |driver|
77+
browser = described_class.new(driver.bidi)
78+
windows = browser.windows
79+
80+
window = windows.first
81+
82+
expect(window).to be_a(Selenium::WebDriver::BiDi::Browser::Window)
83+
expect(window).to have_attributes(
84+
handle: an_instance_of(String),
85+
active: be(false),
86+
state: 'normal',
87+
height: an_instance_of(Integer),
88+
width: an_instance_of(Integer)
89+
)
90+
end
91+
end
92+
93+
it 'checks if a window is active' do
94+
reset_driver!(web_socket_url: true) do |driver|
95+
browser = described_class.new(driver.bidi)
96+
driver.execute_script('window.focus();')
97+
browser.windows.find(&:active?)
98+
99+
expect(active_window).to be_a(Selenium::WebDriver::BiDi::Browser::Window)
100+
expect(active_window.active?).to be(true)
101+
end
102+
end
74103
end
75104
end
76105
end

0 commit comments

Comments
 (0)