Error: Invalid or corrupt jarfile ./node_modules/p

2019-06-20 02:10发布

问题:

When running webdriver-manager update, it downloads a file with -alpha-1.zip.jar. This does not appear to be the right file format. The example below is to just download the selenium standalone jar file:

> ./webdriver-manager update --standalone --chrome false --gecko false

webdriver-manager: using global installed version 12.1.1
[13:34:08] I/downloader - curl -o/path/to/selenium-server-standalone-4.0.0-alpha-1.zip.jar https://selenium-release.storage.googleapis.com/4.0/selenium-server-standalone-4.0.0-alpha-1.zip

This is an invalid file when trying to run webdriver-manager start. What's going on and how do we fix this?

回答1:

For context, what was happening in 12.1.1?

We download the xml file from https://selenium-release.storage.googleapis.com. This xml file previously did not have .zip files. So webdriver-manager update would find the latest from this list. For the 3.141/selenium-server-standalone-3.141.59 the xml Contents has only a jar file:

<Contents>
  <Key>3.141/selenium-server-standalone-3.141.59.jar</Key>
  <Generation>1542184006302312</Generation>
  <MetaGeneration>1</MetaGeneration>
  <LastModified>2018-11-14T08:26:46.300Z</LastModified>
  <ETag>"947e57925b4185ae04d03ceec175a34a"</ETag>
  <Size>10649948</Size>
</Contents>

When 4.0.0-alpha.1 was released the xml file has both a jar and zip extension:

<Contents>
  <Key>4.0/selenium-server-standalone-4.0.0-alpha-1.jar</Key>
  <Generation>1556122620115927</Generation>
  <MetaGeneration>1</MetaGeneration>
  <LastModified>2019-04-24T16:17:00.115Z</LastModified>
  <ETag>"ac553ec987d16d2af8c8e3ef9061772c"</ETag>
  <Size>12564804</Size>
</Contents>
<Contents>
  <Key>4.0/selenium-server-standalone-4.0.0-alpha-1.zip</Key>
  <Generation>1556122620996687</Generation>
  <MetaGeneration>1</MetaGeneration>
  <LastModified>2019-04-24T16:17:00.996Z</LastModified>
  <ETag>"1974b11f970bad6e15c84e3840ec3897"</ETag>
  <Size>12342093</Size>
</Contents>

During the download, it was taking the first Contents Key that matched the latest version. So the assumption was that it would be a jar file and did not check the file extension. As part of the rename process, it would generate the file name. This was a pattern used for chromedriver where we would tack on the version to the binary. So chromedriver binary would be renamed to chromedriver_2.44. This is why we have a .zip.jar file.

In addition, we were not downloading beta versions of jar files. Another issue is that it is downloading an alpha version.

How to update your webdriver-manager to 12.1.4?

Huzzah! This is an issue that is now resolved with webdriver-manager@12.1.2 released yesterday morning. But 12.1.4 has all the other fixes (More info here: When using Protractor 5.4.2, webdriver-manager downloads 2.46 which is not compatible with Chrome 74)

It fixes downloading the .zip file and renaming it to a .zip.jar. It will only download jar files. Also we are not downloading alpha and beta versions of the jar. We should use stable versions of selenium standalone server.

To update to 12.1.4 if you are using Protractor:

  • It should get the latest version of webdriver-manager based on "webdriver-manager": "^12.0.6". So to get this, you'll need to force install your node modules (npm install -f) or clean your workspace (removing your node modules and doing a fresh install).

If you are using webdriver-manager installed globally:

  • npm install -g webdriver-manager@12.1.4

Links

The issues that have tracked this in Protractor and webdriver manager are: - angular/protractor#5224 - angular/webdriver-manager#370

The fix to this was in pull request: angular/webdriver-manager#371.

Other post for StackOverflow for the other fixes: When using Protractor 5.4.2, webdriver-manager downloads 2.46 which is not compatible with Chrome 74