Skip to content
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

[rb] Use Bazel JDK when starting server #13771

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 14 additions & 1 deletion rb/lib/selenium/server.rb
Expand Up @@ -241,7 +241,7 @@ def process
# extract any additional_args that start with -D as options
properties = @additional_args.dup - @additional_args.delete_if { |arg| arg[/^-D/] }
args = ['-jar', @jar, @role, '--port', @port.to_s]
server_command = ['java'] + properties + args + @additional_args
server_command = [java_bin] + properties + args + @additional_args
cp = WebDriver::ChildProcess.build(*server_command)

if @log.is_a?(String)
Expand All @@ -256,6 +256,19 @@ def process
end
end

def java_bin
pp(ENV)
if ENV.key?('BAZEL_TEST') && (java_home = ENV.fetch('JAVA_HOME', nil))
if WebDriver::Platform.windows?
"#{java_home}/bin/java.exe"
else
"#{java_home}/bin/java"
end
else
'java'
end
end

def poll_for_service
return if socket.connected?

Expand Down
18 changes: 9 additions & 9 deletions rb/spec/unit/selenium/server_spec.rb
Expand Up @@ -48,7 +48,7 @@ module Selenium
it 'uses the given jar file and port' do
allow(File).to receive(:exist?).with('selenium_server_deploy.jar').and_return(true)
allow(WebDriver::ChildProcess).to receive(:build)
.with('java', '-jar', 'selenium_server_deploy.jar', 'standalone', '--port', '1234')
.with(a_string_ending_with('java'), '-jar', 'selenium_server_deploy.jar', 'standalone', '--port', '1234')
.and_return(mock_process)

server = described_class.new('selenium_server_deploy.jar', port: 1234, background: true)
Expand All @@ -57,13 +57,13 @@ module Selenium
server.start
expect(File).to have_received(:exist?).with('selenium_server_deploy.jar')
expect(WebDriver::ChildProcess).to have_received(:build)
.with('java', '-jar', 'selenium_server_deploy.jar', 'standalone', '--port', '1234')
.with(a_string_ending_with('java'), '-jar', 'selenium_server_deploy.jar', 'standalone', '--port', '1234')
end

it 'waits for the server process by default' do
allow(File).to receive(:exist?).with('selenium_server_deploy.jar').and_return(true)
allow(WebDriver::ChildProcess).to receive(:build)
.with('java', '-jar', 'selenium_server_deploy.jar', 'standalone', '--port', port.to_s)
.with(a_string_ending_with('java'), '-jar', 'selenium_server_deploy.jar', 'standalone', '--port', port.to_s)
.and_return(mock_process)

server = described_class.new('selenium_server_deploy.jar', port: port)
Expand All @@ -74,14 +74,14 @@ module Selenium

expect(File).to have_received(:exist?).with('selenium_server_deploy.jar')
expect(WebDriver::ChildProcess).to have_received(:build)
.with('java', '-jar', 'selenium_server_deploy.jar', 'standalone', '--port', port.to_s)
.with(a_string_ending_with('java'), '-jar', 'selenium_server_deploy.jar', 'standalone', '--port', port.to_s)
expect(mock_process).to have_received(:wait)
end

it 'adds additional args' do
allow(File).to receive(:exist?).with('selenium_server_deploy.jar').and_return(true)
allow(WebDriver::ChildProcess).to receive(:build)
.with('java', '-jar', 'selenium_server_deploy.jar', 'standalone', '--port', port.to_s, 'foo', 'bar')
.with(a_string_ending_with('java'), '-jar', 'selenium_server_deploy.jar', 'standalone', '--port', port.to_s, 'foo', 'bar')
.and_return(mock_process)

server = described_class.new('selenium_server_deploy.jar', port: port, background: true)
Expand All @@ -92,14 +92,14 @@ module Selenium
server.start
expect(File).to have_received(:exist?).with('selenium_server_deploy.jar')
expect(WebDriver::ChildProcess).to have_received(:build)
.with('java', '-jar', 'selenium_server_deploy.jar', 'standalone',
.with(a_string_ending_with('java'), '-jar', 'selenium_server_deploy.jar', 'standalone',
'--port', port.to_s, 'foo', 'bar')
end

it 'adds additional JAVA options args' do
allow(File).to receive(:exist?).with('selenium_server_deploy.jar').and_return(true)
allow(WebDriver::ChildProcess).to receive(:build)
.with('java',
.with(a_string_ending_with('java'),
'-Dwebdriver.chrome.driver=/bin/chromedriver',
'-jar', 'selenium_server_deploy.jar',
'standalone',
Expand All @@ -117,7 +117,7 @@ module Selenium
server.start
expect(File).to have_received(:exist?).with('selenium_server_deploy.jar')
expect(WebDriver::ChildProcess).to have_received(:build)
.with('java',
.with(a_string_ending_with('java'),
'-Dwebdriver.chrome.driver=/bin/chromedriver',
'-jar', 'selenium_server_deploy.jar',
'standalone',
Expand Down Expand Up @@ -194,7 +194,7 @@ module Selenium
it 'raises Selenium::Server::Error if the server is not launched within the timeout' do
allow(File).to receive(:exist?).with('selenium_server_deploy.jar').and_return(true)
allow(WebDriver::ChildProcess).to receive(:build)
.with('java', '-jar', 'selenium_server_deploy.jar', 'standalone', '--port', port.to_s)
.with(a_string_ending_with('java'), '-jar', 'selenium_server_deploy.jar', 'standalone', '--port', port.to_s)
.and_return(mock_process)

poller = instance_double(WebDriver::SocketPoller)
Expand Down