javascript 量角器给出“无法启动 WebDriver 会话”错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27493715/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 07:33:20  来源:igfitidea点击:

Protractor gives "Unable to start a WebDriver session" error

javascriptgoogle-chrometestingprotractorend-to-end

提问by cgsd

I already have started a server with webdriver-manager start, but I get this error when I try to run protractor:

我已经用 启动了一个服务器webdriver-manager start,但是当我尝试运行量角器时出现此错误:

Using the selenium server at http://127.0.0.1:4444/wd/hub
[launcher] Running 1 instances of WebDriver
ERROR - Unable to start a WebDriver session.

C:\...\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\atoms\error.js:113
  var template = new Error(this.message);
                 ^
UnknownError: unknown error: cannot find Chrome binary

My config file looks like this:

我的配置文件如下所示:

exports.config = {
    specs: [
        'test/*.js'
    ],

    capabilities: {
        'browserName': 'chrome'
    },
    seleniumAddress: 'http://127.0.0.1:4444/wd/hub'

};

I have also tried pointing to the binary in the capabilities object as well as adding chromeDriver and seleniumServerJar keys to no avail. Any ideas?

我还尝试指向功能对象中的二进制文件以及添加 chromeDriver 和 seleniumServerJar 键无济于事。有任何想法吗?

回答by alecxe

According to the relevant github issue, the problem is that chromedrivercannot find chromebrowser executeable- on different operating systems it searches for it in different places.

根据相关的github issue,问题是chromedriver找不到chrome浏览器可执行文件——在不同的操作系统上,它在不同的地方搜索。

You need to either have chrome installedwhere chromedriverexpects it to be, or specify the path to the chromeexecuteable in the binarysetting:

您需要将chrome 安装chromedriver预期的位置,或者chromebinary设置中指定可执行文件的路径:

capabilities: {
    "browserName": "chrome",
    "chromeOptions": {
        binary: "D:/Program Files/Chrome/chrome.exe",
        args: [],
        extensions: [],
    }
},

回答by Shekhar Sahu

I generated code using JHipster and had similar error where e2e was not working. I provided binary path. But upon npm run e2ethe browser opened and displayed data;in the address bar.

我使用 JHipster 生成了代码,并且在 e2e 无法正常工作时遇到了类似的错误。我提供了二进制路径。但是在npm run e2e浏览器打开并显示data;在地址栏中。

I shuffled and provided the binary at the end of chromeOptions after the args and it worked.

我在 args 之后的 chromeOptions 末尾改组并提供了二进制文件并且它起作用了。

capabilities: {
        browserName: 'chrome',
        chromeOptions: {
            args: process.env.JHI_E2E_HEADLESS
                ? [ "--headless", "--disable-gpu", "--window-size=800,600" ]
                : [ "--disable-gpu", "--window-size=800,600" ],
            binary: "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe"
        }
    }

Note: I also had to update the chrome version when an unsupported webdriver version error occurred.

注意:当发生不受支持的 webdriver 版本错误时,我还必须更新 chrome 版本。