Skip to content

Allow Java options when starting a standalone selenium server in Ruby#3444

Closed
aliking wants to merge 3 commits intoSeleniumHQ:masterfrom
animoto:rb_server_java_options
Closed

Allow Java options when starting a standalone selenium server in Ruby#3444
aliking wants to merge 3 commits intoSeleniumHQ:masterfrom
animoto:rb_server_java_options

Conversation

@aliking
Copy link
Copy Markdown
Contributor

@aliking aliking commented Feb 2, 2017

Existing server allows additional args to be passed in, but they are only placed at the end of the constructed command line. For any options to the java command, they need to be placed before the -jar switch.

This pulls out any additional args that start with -D and put them in the right place.

Also includes a change to the gemspec checking that the FILE location is the same as the pwd. This will probably be unnecessary form most people, but was failing on my jenkins server, due to mounted directories.

The existing server allows additional args to be passed in, but they are
only placed at the end of the constructed command line. For any options
to the `java` command, they need to be placed before the `-jar` switch.

This pulls out any additional args that start with `-D` and put them in
the right place in the command.
Changes a check in gemspec that the __FILE__
location is the same as the pwd. This will probably be unnecessary for
most people, but was failing on my jenkins server, due to mounted
directories. `File.realpath` always returns the full, actual path for
comparison.
@titusfortner titusfortner added the C-rb Ruby Bindings label Feb 2, 2017
@lmtierney
Copy link
Copy Markdown
Member

Just out of curiosity, why are you starting standalone with ruby?

Copy link
Copy Markdown
Member

@titusfortner titusfortner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm good with adding these in, but I'm curious the use case. This should only be necessary when running on a local machine, and at that point you're better off using the Ruby bindings directly.


root = File.expand_path(File.dirname(__FILE__))
raise "cwd must be #{root} when reading gemspec" if root != Dir.pwd
root = File.realpath(File.dirname(__FILE__))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this giving you that #expand_path does not? Do you have some kind of symlink set up?

Gem::Specification.new do |s|
s.name = 'selenium-webdriver'
s.version = '3.0.5'
s.version = '3.0.6'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't include this in the PR, please. We'll bump it when we're ready to do another release.

cp = ChildProcess.build('java', '-jar', @jar, '-port', @port.to_s, *@additional_args)
# extract any additional_args that start with -D as options
options = if @additional_args
@additional_args.dup - @additional_args.delete_if{|arg| arg.match(/^-D.*$/)}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@additional_args is always going to return true since it defaults to []
let's name it properties or system_properties, and we should avoid using #match where possible. Otherwise this is good. :)
I think my preference would be:

properties = @additional_args.dup - @additional_args.delete_if { |arg| arg[/^-D/] }

@aliking
Copy link
Copy Markdown
Contributor Author

aliking commented Feb 3, 2017

Addressed comments. Thanks for being so responsive.

These are both a bit unique to our setup. Our jenkins box has two levels of symlinking on the jenkins home directory - with expand_path I was getting two paths that were logically the same, but lexically different.

The reason that we're starting Selenium server in this way is down to a framework that we're using which connects to the selenium server as though it is remote regardless of where it is. I've considered changing it, but it keeps other code consistent.

@titusfortner
Copy link
Copy Markdown
Member

Merged into master, will be available on next release.

@aliking - is this an open source framework, or something custom for your company? Thanks for this contribution.

@aliking
Copy link
Copy Markdown
Contributor Author

aliking commented Feb 3, 2017

It's https://github.com/chemistrykit/chemistrykit and https://github.com/chemistrykit/selenium-connect. At this point our fork has diverged a lot from that, but I'm less concerned since it's not being updated. I'm trying to unpick some of the dependencies on small customizations on old forks of other things, so I'm super glad to not have to do that with selenium. Thanks again!

@titusfortner
Copy link
Copy Markdown
Member

Ah Dave's framework. The different chemistry terms confused me too much, and it looked like it replicated a lot of test runner things that I didn't see use for. So your fork is not open source?

@titusfortner
Copy link
Copy Markdown
Member

titusfortner commented Feb 4, 2017

@aliking - Bad news on the File#realpath usage. All of Selenium is built with an old customized version of JRuby. So far we haven't been able to get everything working with an updated JRuby, so we're stuck with its limitations. For the most part it doesn't matter for the rest of the Ruby code. Except it needs to read the gemspec file to build the gem, and it is too old to know about #realpath.

@p0deje - I think I need to revert this before the next release. We could theoretically work around the JRuby build process for this, but that way lies madness. I'm not sure how close you were to figuring out the updated JRuby, and now that we have things working in Buck with what is there it isn't any kind of a priority any longer. Any other thoughts?

You can see the error with: ./go //rb:gem:build --trace

@p0deje
Copy link
Copy Markdown
Member

p0deje commented Feb 5, 2017

@titusfortner I've spent a couple of hours trying to upgrade JRuby once again, but it's much more complicated than it was before because it now uses ChildProcess inside :( I can definitely figure it out but I don't want to do this again if it's not going to be merged like with #2210. Need your advice on this :)

@titusfortner
Copy link
Copy Markdown
Member

Thanks @p0deje, I went ahead and reverted this change for now.

I was the one who pointed @shs96c to use ChildProcess. The issue had to do with something he needed in a standard library that wasn't working with our legacy JRuby (I'd have to dig through conversations from last summer to refresh my memory). Let's come up with a plan for this when we're all face to face at the Selenium Conference in April.

@p0deje
Copy link
Copy Markdown
Member

p0deje commented Feb 6, 2017

Let's come up with a plan for this when we're all face to face at the Selenium Conference in April.

Sounds reasonable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-rb Ruby Bindings

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants