Skip to content

Commit c6e2c05

Browse files
titusfortneraguspe
andauthored
[rb] create user-friendly method for enabling bidi (#14284)
* Add support for bidi as an initialization parameter * change which tests guard for bidi --------- Co-authored-by: aguspe <[email protected]>
1 parent b154cc7 commit c6e2c05

File tree

5 files changed

+94
-2
lines changed

5 files changed

+94
-2
lines changed

rb/lib/selenium/webdriver/common/options.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ def set_capabilities
7171
def initialize(**opts)
7272
self.class.set_capabilities
7373

74+
opts[:web_socket_url] = opts.delete(:bidi) if opts.key?(:bidi)
75+
7476
@options = opts
7577
@options[:browser_name] = self.class::BROWSER
7678
end
@@ -91,6 +93,14 @@ def add_option(name, value = nil)
9193
@options[name] = value
9294
end
9395

96+
def enable_bidi!
97+
@options[:web_socket_url] = true
98+
end
99+
100+
def bidi?
101+
!!@options[:web_socket_url]
102+
end
103+
94104
def ==(other)
95105
return false unless other.is_a? self.class
96106

rb/sig/lib/selenium/webdriver/common/options.rbs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ module Selenium
3939

4040
def ==: (untyped other) -> bool
4141

42+
def bidi?: -> bool
43+
44+
def enable_bidi!: -> bool
45+
4246
alias eql? ==
4347

4448
def as_json: (*untyped) -> untyped

rb/spec/integration/selenium/webdriver/chrome/options_spec.rb

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
module Selenium
2323
module WebDriver
2424
module Chrome
25-
describe Options, exclusive: [{bidi: false, reason: 'Not yet implemented with BiDi'}, {browser: :chrome}] do
25+
describe Options, exclusive: {browser: :chrome} do
2626
it 'passes emulated device correctly' do
2727
reset_driver!(emulation: {device_name: 'Nexus 5'}) do |driver|
2828
ua = driver.execute_script 'return window.navigator.userAgent'
@@ -43,6 +43,39 @@ module Chrome
4343
expect(ua).to eq('foo;bar')
4444
end
4545
end
46+
47+
it 'enables bidi', exclusive: {bidi: true, reason: 'bazel does not have dependencies otherwise'} do
48+
quit_driver
49+
50+
options = Selenium::WebDriver::Options.chrome
51+
expect(options.web_socket_url).to be_nil
52+
expect(options.bidi?).to be false
53+
54+
options.enable_bidi!
55+
expect(options.web_socket_url).to be true
56+
expect(options.bidi?).to be true
57+
58+
driver = Selenium::WebDriver.for :chrome, options: options
59+
60+
expect(driver.capabilities.web_socket_url).to be_a String
61+
62+
driver.quit
63+
end
64+
65+
it 'enables BiDi on initialization',
66+
exclusive: {bidi: true, reason: 'bazel does not have dependencies otherwise'} do
67+
quit_driver
68+
69+
options = Selenium::WebDriver::Options.chrome(bidi: true)
70+
expect(options.web_socket_url).to be true
71+
expect(options.bidi?).to be true
72+
73+
driver = Selenium::WebDriver.for :chrome, options: options
74+
75+
expect(driver.capabilities.web_socket_url).to be_a String
76+
77+
driver.quit
78+
end
4679
end
4780
end # Chrome
4881
end # WebDriver

rb/spec/integration/selenium/webdriver/edge/options_spec.rb

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
module Selenium
2323
module WebDriver
2424
module Edge
25-
describe Options, exclusive: [{bidi: false, reason: 'Not yet implemented with BiDi'}, {browser: :edge}] do
25+
describe Options, exclusive: {browser: :edge} do
2626
it 'passes emulated device correctly' do
2727
reset_driver!(emulation: {device_name: 'Nexus 5'}) do |driver|
2828
ua = driver.execute_script 'return window.navigator.userAgent'
@@ -43,6 +43,39 @@ module Edge
4343
expect(ua).to eq('foo;bar')
4444
end
4545
end
46+
47+
it 'enables bidi', exclusive: {bidi: true, reason: 'bazel does not have dependencies otherwise'} do
48+
quit_driver
49+
50+
options = Selenium::WebDriver::Options.chrome
51+
expect(options.web_socket_url).to be_nil
52+
expect(options.bidi?).to be false
53+
54+
options.enable_bidi!
55+
expect(options.web_socket_url).to be true
56+
expect(options.bidi?).to be true
57+
58+
driver = Selenium::WebDriver.for :chrome, options: options
59+
60+
expect(driver.capabilities.web_socket_url).to be_a String
61+
62+
driver.quit
63+
end
64+
65+
it 'enables BiDi on initialization',
66+
exclusive: {bidi: true, reason: 'bazel does not have dependencies otherwise'} do
67+
quit_driver
68+
69+
options = Selenium::WebDriver::Options.edge(bidi: true)
70+
expect(options.web_socket_url).to be true
71+
expect(options.bidi?).to be true
72+
73+
driver = Selenium::WebDriver.for :edge, options: options
74+
75+
expect(driver.capabilities.web_socket_url).to be_a String
76+
77+
driver.quit
78+
end
4679
end
4780
end # Edge
4881
end # WebDriver

rb/spec/unit/selenium/webdriver/chrome/options_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,18 @@ module Chrome
141141
end
142142
end
143143

144+
describe '#enable_bidi!' do
145+
it 'allows setting and querying bidi' do
146+
expect(options.web_socket_url).to be_nil
147+
expect(options.bidi?).to be false
148+
149+
options.enable_bidi!
150+
151+
expect(options.bidi?).to be true
152+
expect(options.web_socket_url).to be true
153+
end
154+
end
155+
144156
describe '#add_extension' do
145157
it 'adds an extension' do
146158
allow(File).to receive(:file?).and_return(true)

0 commit comments

Comments
 (0)