量角器给出“无法启动 Web 驱动程序会话”错误

Protractor gives "Unable to start a WebDriver session" error

本文关键字:驱动程序 Web 会话 错误 无法启动 启动 量角器      更新时间:2023-09-26

我已经用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

我的配置文件如下所示:

exports.config = {
    specs: [
        'test/*.js'
    ],
    capabilities: {
        'browserName': 'chrome'
    },
    seleniumAddress: 'http://127.0.0.1:4444/wd/hub'
};

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

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

您需要将 chrome 安装在chromedriver期望的位置,或者在binary设置中指定可执行chrome的路径:

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

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

我在 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"
        }
    }

注意:当发生不受支持的网络驱动程序版本错误时,我还必须更新chrome版本。