Skip to content

[rb][BiDi] Add Browser context activate command #15365

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 5, 2025
Merged
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
5 changes: 5 additions & 0 deletions rb/lib/selenium/webdriver/bidi/browsing_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ def set_viewport(context_id: nil, width: nil, height: nil, device_pixel_ratio: n
def handle_user_prompt(context_id, accept: true, text: nil)
@bidi.send_cmd('browsingContext.handleUserPrompt', context: context_id, accept: accept, text: text)
end

def activate(context_id: nil)
context_id ||= @bridge.window_handle
@bidi.send_cmd('browsingContext.activate', context: context_id)
end
end
end # BiDi
end # WebDriver
Expand Down
2 changes: 2 additions & 0 deletions rb/sig/lib/selenium/webdriver/bidi/browsing_context.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ module Selenium

def handle_user_prompt: (String context, bool accept, String text) -> untyped

def activate: (String? context_id) -> Hash[nil, nil]

def navigate: (String url, String? context_id) -> void

def set_viewport: (String context_id, Integer width, Integer height, Float device_pixel_ratio) -> Hash[nil, nil]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,17 @@ class BiDi
expect(driver.page_source).to include('goodbye')
end
end

it 'activates a browser context' do
reset_driver!(web_socket_url: true) do |driver|
browsing_context = described_class.new(driver)
browsing_context.create

expect(driver.execute_script('return document.hasFocus();')).to be_falsey
browsing_context.activate
expect(driver.execute_script('return document.hasFocus();')).to be_truthy
end
end
end
end # BiDi
end # WebDriver
Expand Down
Loading