Skip to content

Commit

Permalink
[rb] Use Bazel JDK in remote tests
Browse files Browse the repository at this point in the history
  • Loading branch information
p0deje committed May 2, 2024
1 parent 8688ad2 commit b456e60
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
3 changes: 2 additions & 1 deletion rb/lib/selenium/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ def download_server(uri, destination)
def initialize(jar, opts = {})
raise Errno::ENOENT, jar unless File.exist?(jar)

@java = opts.fetch(:java, 'java')
@jar = jar
@host = '127.0.0.1'
@role = opts.fetch(:role, 'standalone')
Expand Down Expand Up @@ -241,7 +242,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] + properties + args + @additional_args
cp = WebDriver::ChildProcess.build(*server_command)

if @log.is_a?(String)
Expand Down
10 changes: 10 additions & 0 deletions rb/spec/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,13 @@ rb_library(
"//rb/spec/unit/selenium/webdriver/support:select",
],
)

genrule(
name = "java-location",
srcs = [],
outs = ["java-location.txt"],
cmd = "echo $(JAVA) > $@",
toolchains = ["@bazel_tools//tools/jdk:current_java_runtime"],
visibility = ["//rb/spec:__subpackages__"],
)
.
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def app_server
def remote_server
@remote_server ||= Selenium::Server.new(
remote_server_jar,
java: bazel_java,
port: random_port,
log_level: WebDriver.logger.debug? && 'FINE',
background: true,
Expand All @@ -95,6 +96,12 @@ def remote_server
)
end

def bazel_java
return unless ENV.key?('WD_BAZEL_JAVA_LOCATION')

File.expand_path(File.read(File.expand_path(ENV.fetch('WD_BAZEL_JAVA_LOCATION'))).chomp)
end

def reset_remote_server
@remote_server&.stop
@remote_server = nil
Expand Down
7 changes: 6 additions & 1 deletion rb/spec/tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,13 @@ def rb_integration_test(name, srcs, deps = [], data = [], browsers = BROWSERS.ke
data = BROWSERS[browser]["data"] + data + [
"//common/src/web",
"//java/src/org/openqa/selenium/grid:selenium_server_deploy.jar",
"//rb/spec:java-location",
"@bazel_tools//tools/jdk:current_java_runtime",
],
env = BROWSERS[browser]["env"] | {"WD_SPEC_DRIVER": "remote"},
env = BROWSERS[browser]["env"] | {
"WD_BAZEL_JAVA_LOCATION": "$(rootpath //rb/spec:java-location)",
"WD_SPEC_DRIVER": "remote",
},
main = "@bundle//bin:rspec",
tags = COMMON_TAGS + BROWSERS[browser]["tags"] + tags + [
"{}-remote".format(browser),
Expand Down

0 comments on commit b456e60

Please sign in to comment.