使用Phantom.js与Protractor进行e2e测试

时间:2016-01-13 20:37:16

标签: angularjs phantomjs protractor e2e-testing

我正在读这个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

我是否遗漏了配置中的内容?在这种情况下如何获得更详细的错误描述?

1 个答案:

答案 0 :(得分:2)

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

来解决
sudo apt-get install openjdk-7-jdk

但是,由于发生了其他问题,我仍然无法运行测试。就我而言,它是:

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

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

UPD

如果你遇到了死亡的问题,这篇文章也很有帮助。https://gist.github.com/tfnico/8471223

用户 barzik 建议将以下命令添加到beforeEach:

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