SeleniumHQ / selenium-google-code-issue-archive

Archive, please see main selenium repo
https://github.com/seleniumhq/selenium
345 stars 195 forks source link

Extensions not working with RemoteWebDriver in Windows/Linux Grid. #8254

Closed lukeis closed 8 years ago

lukeis commented 8 years ago

Originally reported on Google Code with ID 8254

What steps will reproduce the problem?
1. Set up a selenium 2 hub with a single Firefox node attached. Both running on Ubuntu
12.04.
2. Execute a webdriver test from a Windows machine, which creates a profile with some
custom extensions and uses it run test using RemoteWebDriver:

   DesiredCapabilities cap = DesiredCapabilities.firefox();
   FirefoxProfile firefoxProfile = new FirefoxProfile();
   firefoxProfile.addExtension(new File("JSErrorCollector.xpi"));
   firefoxProfile.addExtension(ResourceProvider.getResource("firebug-1.12.0.xpi"));
   cap.setCapability(FirefoxDriver.PROFILE, firefoxProfile);
   RemoteWebDriver remoteWebDriver = new RemoteWebDriver(hubURL, cap);  

What is the expected output? What do you see instead?

A profile directory created on remote ubuntu node does not load the required extensions.
When I use the same profile with FirefoxDriver on Windows or connect via RemoteWebDriver
to other Windows node - it works ok.

I noticed that extension related files are badly written to the profile directory on
remote linux node. They end up in a file at profile root instead of inside extensions
dir,  for example i got:

   /tmp/[profileDir]/"extensions\JSErrorCollector@jsourcerer.com\build.sh"

where "extensions\JSErrorCollector@jsourcerer.com\build.sh" is a long file name. I
expected it to be:

   /tmp/[profileDir]/extensions/JSErrorCollector@jsourcerer.com/build.sh"

where "build.sh" is a file and "extensions" and "JSErrorCollector@jsourcerer.com" are
parent dirs.

Selenium version: 2.43.1
OS: Ubuntu 12.04, Windows 7
Browser: Firefox
Browser version: 31.0 

- I tried adding extensions in different forms: xpi files, dirs, as resource in jar
all give same behaviour
- I tried 2 different plugins with same result: JSErrorCollector.xpi and firebug-1.12.0.xpi
- both sides are running Oracle java 1.6
- custom properties set in profile are transmitted and enabled properly, only plugins
are a problem.
- looked at FileExtension class in Selenium repo, I suspect there is some error in
serialization / deserialization of the profile, but frankly I have problems understanding
internals of selenium (I first time had to look at it :)).

Reported by tporeba on 2014-12-04 13:17:43

lukeis commented 8 years ago

Reported by barancev on 2014-12-04 18:20:10

lukeis commented 8 years ago
Summarizing experiments:
- test runner: Win 7,  node: Ubuntu -> FAIL
- test runner: Ubuntu, node: Ubuntu -> OK
- test runner: Ubuntu, node: Win 7  -> OK

Reported by tporeba on 2014-12-04 22:17:05

lukeis commented 8 years ago
I have made some further review and I think the problem is in method org.openqa.selenium.io.Zip.addToZip:

    private void addToZip(String basePath, ZipOutputStream zos, File toAdd) throws
IOException {
    [...]
       String name = toAdd.getAbsolutePath().substring(basePath.length() + 1);
       ZipEntry entry = new ZipEntry(name);
    [...]

We use here File.getAbsolutePath() in ZipEntry name and on Windows there will be system-dependent
'\' separators inside that path. It should be enough to replace it with os-independent
'/' separator. Actually this is even how the zip file spec says it should be done (http://www.pkware.com/documents/casestudies/APPNOTE.TXT):

       4.4.17 file name: (Variable)

       4.4.17.1 The name of the file, with optional relative path.
       The path stored MUST not contain a drive or
       device letter, or a leading slash.  All slashes
       MUST be forward slashes '/' as opposed to
       backwards slashes '\' for compatibility with Amiga
       and UNIX file systems etc.  If input came from standard
       input, there is no file name field.  

See also:
https://community.oracle.com/message/8607134
http://stackoverflow.com/questions/2549766/create-zip-file-in-windows-and-extract-zip-file-in-linux
http://tdruryjavanotes.blogspot.com/2011/10/zipentry-names-are-not-paths.html
http://cephas.net/blog/2007/11/18/java-zipentry-bug-on-windows/

Reported by tporeba on 2014-12-13 21:48:24

lukeis commented 8 years ago
Back to the point, I believe this should work:
   private void addToZip(String basePath, ZipOutputStream zos, File toAdd) throws IOException
{
   [...]
      String name = toAdd.getAbsolutePath().substring(basePath.length() + 1);
      ZipEntry entry = new ZipEntry(name.replace('\\', '/'));
   [...]

I will submit a patch as soon as I learn to build & test Selenium ;)

Reported by tporeba on 2014-12-13 21:50:30

lukeis commented 8 years ago
I checked the fix and it is working for me in Windows->Linux configuration. ZipTest
tests are passing.

Created pull request: https://github.com/SeleniumHQ/selenium/pull/299

Reported by tporeba on 2014-12-14 21:38:44

lukeis commented 8 years ago
Merged in 07c2118308959463bb860c03605e03452689bd14

Reported by kristian.rosenvold on 2014-12-15 19:16:06

lukeis commented 8 years ago
Ahem. Seems I need to commit more. Now fixed in 967286a7dc4acae58e95d53435c272a69b115d87
and pushed on proper repo.

Reported by kristian.rosenvold on 2014-12-16 05:21:35

lukeis commented 8 years ago

Reported by luke.semerau on 2015-09-17 18:24:56