在Firefox或IE中使用Protractor

时间:2017-03-29 10:53:12

标签: selenium-webdriver protractor webdriver-manager

Protractor适用于Chrome,但我无法启动它来启动Firefox或Internet Explorer。

  • Windows 7
  • 节点v6.9.1

来自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的类似行为)

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

2 个答案:

答案 0 :(得分:5)

最后,我在answer by Nick Tomlin中找到了解决方案:

您需要设置seleniumArgslocalSeleniumStandaloneOpts.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类似)

答案 1 :(得分:1)

您可以使用localSeleniumStandaloneOpts执行此操作。本地驱动程序选项允许您在Protractor测试之前启动selenium独立服务器,运行测试,最后关闭服务器。

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

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

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