Skip to content

Commit b94159e

Browse files
committed
[rb] with Server using PortProber, the specs cannot be hard coded
1 parent 8306553 commit b94159e

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

rb/spec/unit/selenium/server_spec.rb

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ module Selenium
2525
let(:mock_process) { instance_double(WebDriver::ChildProcess).as_null_object }
2626
let(:mock_poller) { instance_double(WebDriver::SocketPoller, connected?: true, closed?: true) }
2727
let(:repo) { 'https://api.github.com/repos/seleniumhq/selenium/releases' }
28+
let(:port) { WebDriver::PortProber.above(4444) }
2829
let(:example_json) do
2930
[{url: "#{repo}/41272273",
3031
assets: {
@@ -62,28 +63,28 @@ module Selenium
6263
it 'waits for the server process by default' do
6364
allow(File).to receive(:exist?).with('selenium_server_deploy.jar').and_return(true)
6465
allow(WebDriver::ChildProcess).to receive(:build)
65-
.with('java', '-jar', 'selenium_server_deploy.jar', 'standalone', '--port', '4444')
66+
.with('java', '-jar', 'selenium_server_deploy.jar', 'standalone', '--port', port.to_s)
6667
.and_return(mock_process)
6768

68-
server = described_class.new('selenium_server_deploy.jar')
69+
server = described_class.new('selenium_server_deploy.jar', port: port)
6970
allow(server).to receive(:socket).and_return(mock_poller)
7071
allow(mock_process).to receive(:wait)
7172

7273
server.start
7374

7475
expect(File).to have_received(:exist?).with('selenium_server_deploy.jar')
7576
expect(WebDriver::ChildProcess).to have_received(:build)
76-
.with('java', '-jar', 'selenium_server_deploy.jar', 'standalone', '--port', '4444')
77+
.with('java', '-jar', 'selenium_server_deploy.jar', 'standalone', '--port', port.to_s)
7778
expect(mock_process).to have_received(:wait)
7879
end
7980

8081
it 'adds additional args' do
8182
allow(File).to receive(:exist?).with('selenium_server_deploy.jar').and_return(true)
8283
allow(WebDriver::ChildProcess).to receive(:build)
83-
.with('java', '-jar', 'selenium_server_deploy.jar', 'standalone', '--port', '4444', 'foo', 'bar')
84+
.with('java', '-jar', 'selenium_server_deploy.jar', 'standalone', '--port', port.to_s, 'foo', 'bar')
8485
.and_return(mock_process)
8586

86-
server = described_class.new('selenium_server_deploy.jar', background: true)
87+
server = described_class.new('selenium_server_deploy.jar', port: port, background: true)
8788
allow(server).to receive(:socket).and_return(mock_poller)
8889

8990
server << %w[foo bar]
@@ -92,7 +93,7 @@ module Selenium
9293
expect(File).to have_received(:exist?).with('selenium_server_deploy.jar')
9394
expect(WebDriver::ChildProcess).to have_received(:build)
9495
.with('java', '-jar', 'selenium_server_deploy.jar', 'standalone',
95-
'--port', '4444', 'foo', 'bar')
96+
'--port', port.to_s, 'foo', 'bar')
9697
end
9798

9899
it 'adds additional JAVA options args' do
@@ -102,7 +103,7 @@ module Selenium
102103
'-Dwebdriver.chrome.driver=/bin/chromedriver',
103104
'-jar', 'selenium_server_deploy.jar',
104105
'standalone',
105-
'--port', '4444',
106+
'--port', port.to_s,
106107
'foo',
107108
'bar')
108109
.and_return(mock_process)
@@ -120,7 +121,7 @@ module Selenium
120121
'-Dwebdriver.chrome.driver=/bin/chromedriver',
121122
'-jar', 'selenium_server_deploy.jar',
122123
'standalone',
123-
'--port', '4444',
124+
'--port', port.to_s,
124125
'foo',
125126
'bar')
126127
end
@@ -206,7 +207,7 @@ module Selenium
206207
it 'sets options after instantiation' do
207208
allow(File).to receive(:exist?).with('selenium_server_deploy.jar').and_return(true)
208209
server = described_class.new('selenium_server_deploy.jar')
209-
expect(server.port).to eq(4444)
210+
expect(server.port).to eq(port)
210211
expect(server.timeout).to eq(30)
211212
expect(server.background).to be false
212213
expect(server.log).to be_nil

0 commit comments

Comments
 (0)