【问题标题】:Not able to run protractor test with phantomjs无法使用 phantomjs 运行量角器测试
【发布时间】:2016-06-24 12:18:10
【问题描述】:

我正在使用量角器来测试 Angular 代码。当我通过默认带有 webdriver-manager 的 chrome 驱动程序运行测试时,测试运行良好。现在我想用 phantomjs(无头浏览器)运行相同的测试,因为我需要通过服务器运行这个测试。但是在通过 phantomjs 运行测试时出现错误:

失败:在页面 URL 上找不到 Angular:重试查找 Angular 超出范围

配置文件是:

exports.config = {
framework: 'jasmine',
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['demo-test.js'],
capabilities: {
  browserName: 'phantomjs',
  version: '',
  platform: 'ANY'
};

demo-test.js 文件看起来像:

// demo-test.js
describe('Protractor Demo App', function() {
jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000000;

beforeEach(function() {
    browser.driver.manage().window().setSize(1280, 1024);
});
it('should have a title', function() {
  browser.get('URL');

  expect(browser.getTitle()).toEqual('Title');

});

请帮帮我。我已经按照官方site 的说明安装了量角器,并通过

安装了phantomjs

sudo apt-get install phantomjs

【问题讨论】:

  • 我不推荐使用量角器的 phantomJS。而是尝试在您的服务器上使用带有 chrome 的 XVFB 来运行带有虚拟显示器的浏览器。
  • 嘿@martin770 感谢您的建议,您能否提供任何文档链接,我可以在其中找到如何执行此操作?

标签: angularjs phantomjs protractor


【解决方案1】:

你增加了错误的超时时间:

jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000000;

这个超时是为了让 jasmine 测试不要运行太久。如果您想在页面上等待页面加载和角度更长的时间 - 将其添加到量角器配置文件中:

getPageTimeout: timeout_in_millis  //default 10 sec
allScriptsTimeout: timeout_in_millis  //default 11 sec

在此处了解有关超时的更多信息 - http://www.protractortest.org/#/timeouts

还要检查您是否指向正确的根元素:

  // CSS Selector for the element housing the angular app - this defaults to
  // body, but is necessary if ng-app is on a descendant of <body>.
  rootElement: 'body',

我不建议在 phantomJS 上运行量角器测试,它的工作方式与真正的浏览器完全不同,有时您可能会跳过真正的错误,或者找到特定于 phantomJS 的东西。

【讨论】:

  • 如果您的大多数用户都使用 chrome,请使用 chrome 或 firefox。
猜你喜欢
  • 2013-12-02
  • 1970-01-01
  • 2020-05-15
  • 1970-01-01
  • 1970-01-01
  • 2015-05-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多