【问题标题】:Protractor tests complete with Chrome / Firefox but fail in phantomjs量角器测试使用 Chrome / Firefox 完成,但在 phantomjs 中失败
【发布时间】:2014-09-19 07:43:16
【问题描述】:

我已经使用运行 firefox 和 chrome 的量角器编写了相当多的 E2E 测试,并且一切正常,但是当我尝试使用 phantomjs 以便我们可以让它们在我们的 CI 服务器上运行时,它们失败并显示以下行:

UnknownError: Error communicating with the remote browser. It may have died.
Build info: version: '2.42.2', revision: '6a6995d', time: '2014-06-03 17:42:03'
System info: host: 'referenemesimac.home', ip: '192.168.1.67', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.9.4', java.version: '1.6.0_65'
Driver info: driver.version: EventFiringWebDriver

以前有人参与过吗?这是我的 protractor.conf.js

exports.config = {
  // The address of a running selenium server.
  seleniumAddress: 'http://localhost:4444/wd/hub',

  // Capabilities to be passed to the webdriver instance.
  capabilities: {
    'browserName': 'phantomjs'
  },

  onPrepare: function () {
    var width = 1440;
    var height = 900;
    browser.driver.manage().window().setSize(width, height);
  },

  // Spec patterns are relative to the current working directly when
  // protractor is called.
  specs: ['protractor_specs/**/*.js'],

  baseUrl: 'http://localhost:3000',

  // Options to be passed to Jasmine-node.
  jasmineNodeOpts: {
    showColors: true,
    defaultTimeoutInterval: 30000
  },

};

【问题讨论】:

    标签: angularjs selenium phantomjs protractor


    【解决方案1】:

    如上所述here

    您应该使用 ignoreSynchronization 浏览器的选项和量角器的 sleep() 方法使其工作,如下所示:

    //
    // test/e2e/base/registration.js
    //
    'use strict';
    var $p;
    
    describe('E2E Registration', function() {
      beforeEach(function() {
        $p = protractor.getInstance();
        browser.ignoreSynchronization = true;
        browser.driver.manage().window().setSize(1280, 1024);
      });
    
      it('should register a user', function() {
        browser.get('/#/register');
        $p.sleep(3000);
        expect(element(by.css('input.sign-up-button')).isPresent()).toBeTruthy();
        element(by.model('user.email')).sendKeys('foo@bar.it');
        element(by.model('user.password')).sendKeys('bar');
        element(by.model('user.repeatPassword')).sendKeys('bar');
        element(by.cssContainingText('option', 'ITALY')).click();
        element(by.css('ins.iCheck-helper')).click();
        element(by.css('input.sign-up-button')).click();
        $p.sleep(3000);
        expect($p.getCurrentUrl()).toMatch(/dashboard/i);
      });
    });
    

    是的,我不喜欢它,但它有效。

    希望有人能更好地回答这个问题。

    您也可以尝试将 $p.sleep() 替换为 $p.waitForAngular();,如 here 所述。

    【讨论】:

    • 我们决定放弃量角器以获得更稳定的东西。我们现在正在使用 Capybara
    • 几个月后有一天,当所有的测试都奏效时,我开始思考与量角器和 phantomjs 相关的所有错误。
    猜你喜欢
    • 1970-01-01
    • 2015-09-29
    • 1970-01-01
    • 1970-01-01
    • 2015-01-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多