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

[3.7.0] Crashes with Jruby Windows #41

Closed
mascolim opened this issue Mar 25, 2019 · 7 comments · Fixed by #50
Closed

[3.7.0] Crashes with Jruby Windows #41

mascolim opened this issue Mar 25, 2019 · 7 comments · Fixed by #50

Comments

@mascolim
Copy link

mascolim commented Mar 25, 2019

Expected Behavior:

chrome_on_windows returns the version number. When the environment is Windows and language is Jruby

Actual Behavior:

An error is thrown and program halts as the command is not translated properly when sent to powershell.

20:10:35.983 Get-ItemProperty : Cannot find path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\App' because it does not exist. 20:10:35.983 At line:1 char:12 20:10:35.983 + (Get-Item (Get-ItemProperty HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\App ... 20:10:35.983 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 20:10:35.983 + CategoryInfo : ObjectNotFound: (HKLM:\SOFTWARE\...rentVersion\App:String) [Get-ItemProperty], ItemNotFo 20:10:35.983 undException 20:10:35.983 + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetItemPropertyCommand 20:10:35.983 20:10:36.149 Default : The term 'Default' is not recognized as the name of a cmdlet, function, script file, or operable program. 20:10:36.149 Check the spelling of the name, or if a path was included, verify that the path is correct and try again. 20:10:36.149 At line:1 char:100 20:10:36.149 + ... s\chrome.exe).(Default)).VersionInfo.ProductVersion 20:10:36.149 + ~~~~~~~ 20:10:36.149 + CategoryInfo : ObjectNotFound: (Default:String) [], CommandNotFoundException 20:10:36.149 + FullyQualifiedErrorId : CommandNotFoundException

Steps to Reproduce

  1. Copy the contents of the chrome_on_windows method to a new .rb file.
    reg = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe'
    ps = "(Get-Item (Get-ItemProperty '#{reg}').'(Default)').VersionInfo.ProductVersion"
    puts `powershell #{ps}`
  2. Execute the file using Jruby on a 64bit Windows OS (Confirmed with Windows 10, JDK 1.8, and Jruby 9.2.4) Also confirmed with (Windows Server 2012, JDK 1.8, Jruby 9.2)
  3. View the error above if reproduced successfully. Otherwise the chrome version is printed in the console as intended.

Potential Work-around

The following code executes the intended operation through Jruby Windows. This requires using the exec() command, escaping the space in App Paths with a ` character, and double escaping the single quotes.

This solution is not yet verified in vanilla Ruby
exec("powershell (Get-Item -Path ((Get-ItemProperty \"HKLM:\\Software\\Microsoft\\Windows\\CurrentVersion\\App` Paths\\chrome.exe\").\\'(default)\\')).VersionInfo.ProductVersion")

Note

I believe this issue stems from a long living Jruby Windows issue jruby/jruby#3725

@mascolim
Copy link
Author

mascolim commented Mar 25, 2019

I believe #39 will resolve this issue as the following line executes successfully on Jruby Windows.
puts `powershell (Get-ItemProperty '#{Selenium::WebDriver::Chrome.path}').VersionInfo.ProductVersion`

@kapoorlakshya
Copy link
Collaborator

kapoorlakshya commented Mar 25, 2019

Hi @mascolim, I tested your potential workaround in vanilla Ruby/MRI on Windows 10 and it did not work unfortunately.

irb(main):001:0> exec("powershell (Get-Item -Path ((Get-ItemProperty \"HKLM:\\Software\\Microsoft\\Windows\\CurrentVersion\\App` Paths\\chrome.exe\").\\'(default)\\')).VersionInfo.ProductVersion")
At line:1 char:107
+ ... ware\Microsoft\Windows\CurrentVersion\App` Paths\chrome.exe).\'(defau ...
+                                                                  ~
Missing property name after reference operator.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : MissingPropertyName

Since this seems to be a Jruby specific issue with a workaround through #39, as mentioned in your comment, can we mark this as resolved?

@mascolim
Copy link
Author

3.7.1 works when Selenium::WebDriver::Chrome.path is set to a custom path that has no spaces, but if Selenium::WebDriver::Chrome.path has spaces or is not set it will continue to fail. If no one else uses JRuby on Windows then we can close the issue as the real issue is with Jruby, and a full work-around may be messy.

@kapoorlakshya
Copy link
Collaborator

Ah, that's annoying. Well, I have the following working for Google Chrome (based on your fix): https://github.com/kapoorlakshya/webdrivers/blob/41_jruby_support_on_windows/lib/webdrivers/chromedriver.rb#L94

Spec is here: https://github.com/kapoorlakshya/webdrivers/blob/41_jruby_support_on_windows/spec/chromedriver_spec.rb#L67

Would you mind testing it locally? I successfully tested it on Jruby 9.1.7.0.

P.S. The Selenium::WebDriver::Chrome.path still won't work if it the path spaces in it. I'm not sure if there is an easy fix for that.

@mascolim
Copy link
Author

Yes, thank you! The 41_jruby_support_on_windows branch was verified successfully with [Jruby 9.2.4 Windows 10] and [9.2.0 Windows Server 2012] for unset Chrome.path

@kapoorlakshya
Copy link
Collaborator

Nice! I'll submit the PR later today and then release it in v3.7.2.

@kapoorlakshya
Copy link
Collaborator

@mascolim Submitted #50 if you'd like to test the final code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants