protractor/selenium “could not find chromedriver a

2019-03-08 10:12发布

I installed protractor following this tutorial and when i use webdriver-manager update it says:

selenium standalone is up to date.
chromedriver is up to date.

thou when i try to run the protractor tests, it says:

C:\Users\****\AppData\Roaming\npm\node_modules\protractor\lib\driverProviders\local.dp.js:42
            throw new Error('Could not find chromedriver at ' +
                  ^
    Error: Could not find chromedriver at C:\Users\****\AppData\Roaming\npm\node_modules\protractor\selenium\chromedriver.exe
        at LocalDriverProvider.addDefaultBinaryLocs_ (C:\Users\****\AppData\Roaming\npm\node_modules\protractor\lib\driverProviders\local.dp.js:42:15)
        at LocalDriverProvider.setupEnv (C:\Users\****\AppData\Roaming\npm\node_modules\protractor\lib\driverProviders\local.dp.js:59:8)
        at Runner.run (C:\Users\****\AppData\Roaming\npm\node_modules\protractor\lib\runner.js:308:31)
        at process.<anonymous> (C:\Users\****\AppData\Roaming\npm\node_modules\protractor\lib\runFromLauncher.js:32:14)
        at process.EventEmitter.emit (events.js:98:17)
        at handleMessage (child_process.js:318:10)
        at Pipe.channel.onread (child_process.js:345:11)
    [launcher] Runner Process Exited With Error Code: 8

I checked the local.dp.js and saw that it tried to load the chromedriver from ..\node_modules\protractor\selenium\chromedriver but there only was an empty zip file called chromedriver_2.9.

So i downloaded the chromedriver manually and copied it to this location, producing a new error:

C:\Users\****\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:1549
      throw error;
            ^
Error: Server exited with 1
    at Error (<anonymous>)
    at ChildProcess.onServerExit (C:\Users\****\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\remote\index.js:193:11)
    at ChildProcess.g (events.js:180:16)
    at ChildProcess.EventEmitter.emit (events.js:98:17)
    at Process.ChildProcess._handle.onexit (child_process.js:797:12)
[launcher] Runner Process Exited With Error Code: 8

Anyone any Ideas?

14条回答
时光不老,我们不散
2楼-- · 2019-03-08 10:32

The standalone selenium file was corrupt so i had to overwrite it, copying it into the folder directly.

C:/Users/****/AppData/Roaming/npm/node_modules/protractor/selenium/

Also i had to rename the chromedriver so it is actually called "chromedriver" and not "chromedriver.exe".

C:/Users/****/AppData/Roaming/npm/node_modules/protractor/selenium/chromedriver

This partially happened because i did not set the proxy in webdriver. You can see the Solution for this in the accepted answer.

查看更多
放我归山
3楼-- · 2019-03-08 10:37

I encountered similar issue when I followed angular's tutorial:

https://docs.angularjs.org/tutorial/step_03

and checked out the code accordingly:

git checkout -f step-3

Within angular-phonecat/package.json devDependencies, the protractor version is "~1.0.0", which caused npm always download a corrupted file:

angular-phonecat/node_modules/protractor/selenium/chromedriver_2.10.zip

Because the above zip file can't be opened properly, so below error exists:

/Users/karlli/dev/projects/angular-phonecat/node_modules/protractor/node_modules/adm-zip/zipFile.js:66 throw Utils.Errors.INVALID_FORMAT; ^ Invalid or unsupported zip format. No END header found

There are 2 solutions:

  1. symbol link the correct one instead

ln -sf ~/dev/projects/angular-phonecat/node_modules/chromedriver/bin/chromedriver node_modules/protractor/selenium/chromedriver.exe

Thanks @bronson :-)

  1. upgrade protractor's dependency version After several tests, I found the minimal workable version is 1.1.0.

angular-phonecat/package.json

"devDependencies": {
    "karma": "^0.12.16",
    "karma-chrome-launcher": "^0.1.4",
    "karma-jasmine": "^0.1.5",
    "protractor": "~1.1.0",
    "http-server": "^0.6.1",
    "tmp": "0.0.23",
    "bower": "^1.3.1",
    "shelljs": "^0.2.6"
},
查看更多
一夜七次
4楼-- · 2019-03-08 10:37

Just add the "preprotractor":" npm install chromedriver" to your package.json

That will down load the latest one all the time.

查看更多
Lonely孤独者°
5楼-- · 2019-03-08 10:40

I was facing this error too and by the time I read the tutorial, it did not cover how to install protractor and the webdriver as local dependencies to your project (which are located in ./node_modules).

If this is what you prefer (probably because you might want to use grunt-protractor-runner and run your test later in a continuous build manner as I neede) instead of installing it globally, this solution worked for me:

  1. Install protractor:

npm install protractor --save-dev

  1. Install selenium and the webdrivers with the webdriver-manager by running:

./node_modules/protractor/bin/webdriver-manager update

After calling this command have a look at ./node_modules/protractor and it subfolders to verify it. A folder called selenium with the chromedriver in should be available in it.

Note that as protractor was not installed as "global", calling it from the command line will result in a "commnad not found" error. You can run it instead with this command: ./node_modules/protractor/bin/protractor

Additionaly, it might be a good idea to add a script definition to your package.json, so that next time you install all your dependencies from zero, npm setup the webdrivers automaticaly. For that add this to your package.json file: "scripts": { "postinstall": "./node_modules/protractor/bin/webdriver-manager update" }

Hope this helps you further...

查看更多
啃猪蹄的小仙女
6楼-- · 2019-03-08 10:40

If on Windows, you may need to set an HTTP_PROXY environment variable. Try these steps in your command prompt, assuming your proxy server is http://proxy.you.com:8080.

  1. SETX HTTP_PROXY http://proxy.you.com:8080 (It should return SUCCESS: Specified value was saved. You can also do this in System Properties...Advanced...Environment Variables)
  2. Close your command prompt window and reopen. (This ensures your new environment variable will be used in your session.)
  3. Now run your command: webdriver-manager update
查看更多
Ridiculous、
7楼-- · 2019-03-08 10:41

If you are behind a proxy then try setting proxy first and then run webdriver update:

npm config set proxy http://<proxy.com>:port

webdriver-manager update
查看更多
登录 后发表回答