Skip to content

Commit 3ff6f9a

Browse files
authored
[rb] Add websocket-port parameter to firefox service (#15458)
* Add --websocket-port parameter to firefox service * Correct identation issue * Add guard to test * Improve unit test * Improve unit test * fix identation * Simplifying test and fixing formatting issue * Simplifying test and fixing formatting issue * Use the PortProber isntead of Sockets * Change port to 9222
1 parent 479d197 commit 3ff6f9a

File tree

3 files changed

+41
-3
lines changed

3 files changed

+41
-3
lines changed

rb/lib/selenium/webdriver/firefox/service.rb

+9
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ class Service < WebDriver::Service
2525
EXECUTABLE = 'geckodriver'
2626
SHUTDOWN_SUPPORTED = false
2727
DRIVER_PATH_ENV_KEY = 'SE_GECKODRIVER'
28+
29+
def initialize(path: nil, port: nil, log: nil, args: nil)
30+
args ||= []
31+
unless args.any? { |arg| arg.include?('--connect-existing') }
32+
args << '--websocket-port'
33+
args << WebDriver::PortProber.above(9222).to_s
34+
end
35+
super
36+
end
2837
end # Service
2938
end # Firefox
3039
end # WebDriver

rb/spec/integration/selenium/webdriver/firefox/service_spec.rb

+15
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,21 @@ module Firefox
3737
it 'can be started outside driver' do
3838
expect(service_manager.uri).to be_a(URI)
3939
end
40+
41+
context 'with BiDi enabled', exclusive: {bidi: true, reason: 'only executed when bidi is enabled'} do
42+
it 'ensures two service instances use different websocket port' do
43+
service1 = described_class.new
44+
service2 = described_class.new
45+
46+
ws_index1 = service1.args.index('--websocket-port')
47+
ws_index2 = service2.args.index('--websocket-port')
48+
49+
port1 = service1.args[ws_index1 + 1].to_i
50+
port2 = service2.args[ws_index2 + 1].to_i
51+
52+
expect(port1).not_to eq(port2)
53+
end
54+
end
4055
end
4156
end # Firefox
4257
end # WebDriver

rb/spec/unit/selenium/webdriver/firefox/service_spec.rb

+17-3
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ module Firefox
5151
it 'does not create args by default' do
5252
service = described_class.new
5353

54-
expect(service.extra_args).to be_empty
54+
expect(service.extra_args.count).to eq 2
5555
end
5656

5757
it 'uses sets log path to stdout' do
@@ -73,9 +73,23 @@ module Firefox
7373
end
7474

7575
it 'uses provided args' do
76-
service = described_class.new(args: ['--foo', '--bar'])
76+
service = described_class.new(args: %w[--foo --bar])
77+
expect(service.extra_args).to include(*%w[--foo --bar])
78+
end
7779

78-
expect(service.extra_args).to eq ['--foo', '--bar']
80+
it 'there is a random port for websocket' do
81+
service = described_class.new
82+
ws_index = service.extra_args.index('--websocket-port')
83+
port = service.extra_args[ws_index + 1].to_i
84+
expect(port).to be_positive
85+
end
86+
87+
context 'with connect existing' do
88+
it 'does not uses websocket-port' do
89+
service = described_class.new(args: ['--connect-existing'])
90+
expect(service.extra_args).not_to include('--websocket-port')
91+
expect(service.extra_args).to eq(['--connect-existing'])
92+
end
7993
end
8094
end
8195

0 commit comments

Comments
 (0)