【问题标题】:Running protractor with phantomjs使用 phantomjs 运行量角器
【发布时间】:2015-05-07 22:07:21
【问题描述】:

我正在尝试解决在尝试使用 phantomJS 运行量角器测试时遇到的错误。

Exception thrown: Keeping the Selenium server alive
ERROR - Unable to start a WebDriver session.

/Users/test/projects/test/node_modules/protractor/node_modules/selenium-webdriver/lib/atoms/error.js:113
var template = new Error(this.message);
             ^
UnknownError: org.openqa.selenium.browserlaunchers.Proxies

我使用的版本是:

{
   'phantomsjs': '1.9.16',
   'selenium-server-standalone': '2.44.0',
   'protractor': '1.7.0',
   'jasmine-reporters': '2.0.4',
   'grunt-protractor-webdriver:'0.2.0'
}

我的量角器配置文件是:

exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',

baseUrl: 'http://localhost:9000/',

"capabilities": {
    "browserName": "phantomjs",
    "phantomjs.binary.path": require("phantomjs").path,
    "phantomjs.ghostdriver.cli.args": ["--loglevel=DEBUG"]
},

specs: ['../test/e2e/**/*.js'],

// Options to be passed to Jasmine-node.
jasmineNodeOpts: {
//onComplete: false,//use function to teardown database and rebuild etc....
    isVerbose: false,
    showColors: true,
    includeStackTrace: true
}
};

我的 grunt 任务配置如下:

protractor: {
   e2e: {
            configFile: "config/protractor.conf.test.js"
        },

        run: {}
},

我将任务注册为:

grunt.registerTask('test', function () {
    grunt.task.run([
        'build',
        'browserify:spec',
        'karma:unit',
        'protractor_webdriver:start',
        'protractor:e2e'
    ]);
});

我能够使用 chrome 运行配置,但 phantomjs 一直失败。

【问题讨论】:

  • 我读到了一位 Angular 团队成员的评论,他说 Phantom 并不完全适合 Protractor 测试。 DOM 渲染存在太多不规则和问题,无法完全依赖它。尽管我确实使用 PhantomJS 进行单元测试,但我只将 Chrome 用于 Protractor。

标签: selenium-webdriver gruntjs jasmine phantomjs protractor


【解决方案1】:

这篇文章有一些关于 PhantomJS 问题的详细信息以及如果您可以以某种方式使用 Linux(可能通过 Docker 或 Vagrant)的解决方案http://tobyho.com/2015/01/09/headless-browser-testing-xvfb/

来自文章

虽然它是建立在 WebKit 之上的 - 两者都是相同的渲染引擎 Safari 和 Chrome 使用,它的行为方式仍然与 那些浏览器,这可能会导致误报(测试失败时 没有真正的缺陷),在某些情况下性能下降 你的测试套件。由于 PhantomJS 在某种意义上不是真正的浏览器 没有最终用户实际使用它,专门为 PhantomJS 成为测试套件的维护成本,而不是 直接改进产品的东西。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-17
    • 2014-07-01
    • 1970-01-01
    • 2015-09-27
    相关资源
    最近更新 更多