Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion rb/lib/selenium/webdriver/bidi/browser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ module Selenium
module WebDriver
class BiDi
class Browser
Window = Struct.new(:handle, :active, :height, :width, :x, :y, :state) do
def active?
active
end
end
def initialize(bidi)
@bidi = bidi
end
Expand All @@ -36,7 +41,24 @@ def user_contexts
def remove_user_context(user_context)
@bidi.send_cmd('browser.removeUserContext', userContext: user_context)
end
end

def windows
response = @bidi.send_cmd('browser.getClientWindows')

response['clientWindows'].map do |win_data|
attributes = {
handle: win_data['clientWindow'],
active: win_data['active'],
height: win_data['height'],
width: win_data['width'],
x: win_data['x'],
y: win_data['y'],
state: win_data['state']
}
Window.new(**attributes)
end
end
end # Browser
end # BiDi
end # WebDriver
end # Selenium
2 changes: 1 addition & 1 deletion rb/lib/selenium/webdriver/bidi/browsing_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def activate(context_id: nil)
context_id ||= @bridge.window_handle
@bidi.send_cmd('browsingContext.activate', context: context_id)
end
end
end # BrowsingContext
end # BiDi
end # WebDriver
end # Selenium
2 changes: 2 additions & 0 deletions rb/sig/lib/selenium/webdriver/bidi/browser.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ module Selenium
module WebDriver
class BiDi
class Browser
Window: Selenium::WebDriver::BiDi::Browser::Window

@bidi: BiDi

def initialize: (BiDi bidi) -> void
Expand Down
33 changes: 31 additions & 2 deletions rb/spec/integration/selenium/webdriver/bidi/browser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
module Selenium
module WebDriver
class BiDi
describe Browser, exclusive: {bidi: true, reason: 'only executed when bidi is enabled'},
only: {browser: %i[chrome edge firefox]} do
describe Browser, exclusive: { bidi: true, reason: 'only executed when bidi is enabled' },
only: { browser: %i[chrome edge firefox] } do
it 'creates an user context' do
reset_driver!(web_socket_url: true) do |driver|
browser = described_class.new(driver.bidi)
Expand Down Expand Up @@ -71,6 +71,35 @@ class BiDi
}.to raise_error(Error::WebDriverError)
end
end

it 'get windows' do
reset_driver!(web_socket_url: true) do |driver|
browser = described_class.new(driver.bidi)
windows = browser.windows

window = windows.first

expect(window).to be_a(Selenium::WebDriver::BiDi::Browser::Window)
expect(window).to have_attributes(
handle: an_instance_of(String),
active: be(false),
state: 'normal',
height: an_instance_of(Integer),
width: an_instance_of(Integer)
)
end
end

it 'checks if a window is active' do
reset_driver!(web_socket_url: true) do |driver|
browser = described_class.new(driver.bidi)
driver.execute_script('window.focus();')
browser.windows.find(&:active?)

expect(active_window).to be_a(Selenium::WebDriver::BiDi::Browser::Window)
expect(active_window.active?).to be(true)
end
end
end
end
end
Expand Down
Loading