Protractor on offline machine

2019-04-12 22:07发布

问题:

  • Angular 4 cli project We have private network with private npm repository. (There is no connection to the internet). so after all modules are downloaded I want to run e2e tests.

Protractor use webdriver-manager to download the latest chrome driver. but he can't download the driver so I get this error :

etaddrinfo ENOTFOUND chromedriver.storage.googleapis.com chromedriver.storage.googleapis.com:443

I tried to download the driver manually, and inside the protactor-config :

{
  chromeDriver: "../../chromedriver.exe", // I also tried with "./chromedriver_2.30.exe"

.... }

(I don't know if the chromedriver is relative path to the protractor.config or to the webdriver-manager module inside protractor)

But I keep getting this error, how can I treat this error without an internet connection at all?

btw, something to consider, we develop on windows, but how can our ci/cd server (linux) will get a driver suitable for linux??

回答1:

I had a similar issue. After trying different approaches like manually copying the driver or changing the protractor module, I found that the best workaround is to install a local Web server and provide the required driver for download through that local server. This solution worked and is also useful to provide other files (e.g. files that are directly downloaded during "npm install"). Steps are listed below.

  • Install Apache on the offline system or any other system accessible to that offline system.
  • On an online system, download the driver from (https://chromedriver.storage.googleapis.com/ - the site that the update command tries to access). Accessing this site in the browser displays a file (download.xml) that lists different versions of the web driver for different platforms. You can download the required version by appending the "Key" shown in that file to the end of the URL e.g. (https://chromedriver.storage.googleapis.com/2.33/chromedriver_win32.zip) to download version 2.33 of the chrome driver for windows. I tried newer versions but found that 2.33 worked on Win 10 (64 bit)/Chrome 61.
  • Manually copy the downloaded zip file to the offline system in the Apache htdocs folder using the same path as in the key e.g. (c:\\htdocs\2.33\chromedriver_win32.zip)
  • Make a download.xml file similar to the one on the actual site (https://chromedriver.storage.googleapis.com) but only list one entry for the driver version that you need.
  • Modify your Apache config file (conf\httpd.conf) to make download.xml as DirectoryIndex file
  • Run Apache (bin\httpd.exe)
  • Change your windows hosts file to add an entry to map (chromedriver.storage.googleapis.com) to the IP of the system where Apache is running.
  • Run "ng e2e". "webdriver-manager update" will download this local driver and tests will continue.


回答2:

I had a similar issue. Found this answer with googling and I tried it. Seems to work.

With recent changes in protractor you can use:

ng e2e --webdriver-update=false


回答3:

I had the same problems and my solution it's not the best, but it works.

Locally:

  • run webdriver-manager update in my example I had to run it with -ignore_ssl
  • go to the \node_modules\protractor\node_modules\webdriver-manager\selenium\and copy all files (except update-config.json) to some root folder
  • commit and push changes (I know, we are pushing web drivers to the repo which is not the best solution)

On Offline Machine - TFS in my case

  • run npm install
  • copy webdrivers back to the folder node_modules\protractor\node_modules\webdriver-manager\selenium\
  • I use Angular CLI so run ng e2e --no-webdriver-update


回答4:

The best way is to put it in your angular.json:

"e2e": {
  "builder": "@angular-devkit/build-angular:protractor",
  "options": {
    "webdriverUpdate": false,
    "protractorConfig": "e2e/protractor.conf.ts",
    "devServerTarget": "myproject:serve"
  },