【问题标题】:e2e tests with Protractor using Phantom.js使用 Phantom.js 使用 Protractor 进行 e2e 测试
【发布时间】:2016-01-13 20:37:15
【问题描述】:

我正在阅读Angular tutorial,在第一章中,他们解释了如何运行单元测试和 e2e 测试。在本教程中,他们使用 Chrome 和 Firefox。由于我在没有 GUI 的 Ubuntu 14 虚拟机上运行应用程序,我决定使用 Phantomjs 浏览器。

最终我能够使用 Phantom 运行单元测试,但我遇到了 e2e 问题。

这是 protractor-conf.js 的样子:

exports.config = {
allScriptsTimeout: 11000,

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

  capabilities: {
    'browserName': 'phantomjs',
    'phantomjs.binary.path':'./node_modules/phantomjs/bin/phantomjs',
    'phantomjs.ghostdriver.cli.args': ['--loglevel=DEBUG']
  },

  chromeOnly:true,

  baseUrl: 'http://localhost:8000/',

  framework: 'jasmine',

  jasmineNodeOpts: {
defaultTimeoutInterval: 30000
}
};

但是当我运行测试时出现以下错误:

Starting selenium standalone server...
[launcher] Running 1 instances of WebDriver
[launcher] Process exited with error code 1

events.js:72
    throw er; // Unhandled 'error' event
          ^
Error: spawn ENOENT
at errnoException (child_process.js:988:11)
at Process.ChildProcess._handle.onexit (child_process.js:779:34)
npm ERR! weird error 8
npm WARN This failure might be due to the use of legacy binary "node"
npm WARN For further explanations, please read
/usr/share/doc/nodejs/README.Debian

npm ERR! not ok code 0

我是否错过了配置中的某些内容?这种情况下如何获取更详细的错误描述?

【问题讨论】:

  • 你用的是什么版本的节点node --version,什么版本的量角器?
  • @martin770 节点版本为 v0.10.25。量角器版本是 2.5.1。
  • 该版本的节点应该与该版本的量角器兼容,我之前使用过相同的配置,但不使用 phantomJS。除非您真的需要幻像,否则我建议您使用 xvfb-run 进行虚拟显示,并为您的浏览器使用 chrome。

标签: angularjs phantomjs protractor e2e-testing


【解决方案1】:

这个特殊问题(奇怪的错误8)可以通过安装java来解决:

sudo apt-get install openjdk-7-jdk

但是,由于发生了另一个问题,我仍然无法运行测试。在我的情况下是:

UnknownError: Error communicating with the remote browser. It may have died.

看起来使用phantomjs是一条充满折磨的道路,也许我应该像@martin770建议的那样尝试使用xvfb的firefox。


更新

如果您遇到死亡 phantom.js https://gist.github.com/tfnico/8471223987654321@ 的问题,这篇文章也会有所帮助

用户 barzik 建议在 beforeEach 中添加以下命令:

browser.ignoreSynchronization = true; 
browser.get('/');  //or any page you are going to test 
browser.waitForAngular();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-01-31
    • 2020-07-06
    • 1970-01-01
    • 2016-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多