Skip to content

Commit 2101441

Browse files
committed
Add activate method to browser context
1 parent e23c025 commit 2101441

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ 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 activate(context_id: nil)
99+
context_id ||= @bridge.window_handle
100+
@bidi.send_cmd('browsingContext.activate', context: context_id)
101+
end
97102
end
98103
end # BiDi
99104
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 activate: (String? context_id) -> Hash[nil, nil]
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: 12 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,17 @@ class BiDi
7372
expect(handles).to include(window1)
7473
expect(handles).not_to include(window2)
7574
end
75+
76+
it 'activates a browser context' do
77+
reset_driver!(web_socket_url: true) do |driver|
78+
browsing_context = described_class.new(driver)
79+
browsing_context.create
80+
81+
expect(driver.execute_script('return document.hasFocus();')).to be_falsey
82+
browsing_context.activate
83+
expect(driver.execute_script('return document.hasFocus();')).to be_truthy
84+
end
85+
end
7686
end
7787
end # BiDi
7888
end # WebDriver

0 commit comments

Comments
 (0)