在 Firefox 或 IE 中使用 Protractor

Using Protractor with Firefox or IE

Protractor 在 Chrome 上运行良好,但我无法启动 Firefox 或 Internet Explorer。

来自 package.json 的片段:

"scripts": {
    ....
    "webdriver-manager-update": "webdriver-manager update --ie",
    "protractor": "protractor protractor.conf.js",
    ...
},
...
"devDependencies": {
    ...
    "protractor": "5.1.1",
    ...
}

protractor.conf.js:

exports.config = {
    capabilities: {
      browserName: "firefox" // or "internet explorer"
    },
    specs: ["target/e2e/**/*.e2e-spec.js"]
};

在 运行 npm run webdriver-manager-update 之后,<project-home>\node_modules\protractor\node_modules\webdriver-manager\selenium\ 包含文件 chromedriver_2.28.exegeckodriver-v0.15.0.exeIEDriverServer3.3.0.exe

当运行npm run protractor时,我得到一个错误:

[12:29:45] I/launcher - Running 1 instances of WebDriver
[12:29:45] I/local - Starting selenium standalone server...
[12:29:46] I/local - Selenium standalone server started at http://192.168.213.25:62661/wd/hub
[12:29:46] E/launcher - The path to the driver executable must be set by the webdriver.gecko.driver system property

(对于IE,指的是webdriver.ie.driver系统属性)

经过大量谷歌搜索,我尝试了以下修复方法:

a) 添加<project-home>\node_modules\protractor\node_modules\webdriver-manager\selenium\到系统环境变量Path。这似乎没有什么区别。

b) 将以下行添加到 protractor.conf.js:

seleniumArgs: ["-Dwebdriver.gecko.driver=<project-home>\node_modules\protractor\node_modules\webdriver-manager\selenium\geckodriver-v0.15.0.exe"],

现在 npm run protractor 产量:

[12:40:35] I/launcher - Running 1 instances of WebDriver
[12:40:35] I/local - Starting selenium standalone server...
[12:40:35] E/launcher - Error: Error: Server terminated early with status 1
    at Error (native)
    at earlyTermination.catch.e (<project-home>\node_modules\selenium-webdriver\remote\index.js:252:52)
    at process._tickCallback (internal/process/next_tick.js:103:7)
[12:40:35] E/launcher - Process exited with error code 100

(与 IE 类似的行为)

我的搜索结果表明我不是唯一遇到此问题的人,但不幸的是,我没有找到解决方案。

最后我在 answer by Nick Tomlin:

中找到了解决方案

您需要设置的不是seleniumArgs,而是localSeleniumStandaloneOpts.jvmArgs。所以,在protractor.conf.js中写:

localSeleniumStandaloneOpts: {
    jvmArgs: ["-Dwebdriver.gecko.driver=<project-home>\node_modules\protractor\node_modules\webdriver-manager\selenium\geckodriver-v0.15.0.exe"]
  },

(与 IE 类似)

你可以用 localSeleniumStandaloneOpts 来做到这一点。本地驱动程序选项允许您在 Protractor 测试之前启动 selenium 独立服务器,运行 测试,最后关闭服务器。

另一种方法是在配置文件中使用 webdriver-manager start --ieseleniumAddress。在您的配置文件中,您将设置 seleniumAddress: "http://127.0.0.1:4444/wd/hub".

关于 Firefox 的快速说明。确保您使用的是最新的 gecko 驱动程序和 Firefox 版本 运行。如果 Firefox 测试未正确 运行ning,请查看 gecko driver github issues page.

关于 Internet Explorer 的另一个注意事项。您应该使用 IE11 和 32 位驱动程序版本。如果您查看 Protractor issues page,已确定 iedriver 存在问题。我认为这些问题不会得到解决。