量角器在PhantomJS上运行测试

bod*_*ine 14 selenium node.js phantomjs angularjs protractor

我似乎无法通过测试成功获得PhantomJS.我试图将它集成到我的项目中,但在那之后我尝试运行基本的Angular Docs示例,我遇到了同样的问题.我到目前为止的步骤:

  • npm install -g phantomjs
  • phantomjs --webdriver=9515 // ... GhostDriver - Main - 在端口9515上运行
  • protractor protractorConf.js

这是仅包含browserName的示例中的同一文件,并且seleniumAddress端口已更改:

// An example configuration file.
exports.config = {
  // The address of a running selenium server.
  seleniumAddress: 'http://localhost:9515',

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

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

  // Options to be passed to Jasmine-node.
  jasmineNodeOpts: {
    showColors: true,
  }
};
Run Code Online (Sandbox Code Playgroud)

我收到以下错误消息:

UnknownError: Error Message => 'Detected a page unload event; asynchronous script execution does not work across page loads.'
Run Code Online (Sandbox Code Playgroud)

在github上发现了这个问题,这似乎是相关的.我以为我已经对他们的brower-setup.md有了足够的认识,将它包含在我的一个beforeEach函数中.然后我发现这里 ptor只是包装驱动程序.哇,我知道我在量角器/硒土地上是一个菜鸟,但信噪比具有强烈的劝阻性.我真的很想获得使用PhantomJS的性能优势,但是在这方面失去几个小时的前景让我头疼.我使用的是Windows 7 Enterprise 64位,以防万一.谢谢!

Mic*_*ael 3

实际上这个修复为我解决了同样的问题:

https://github.com/pschwartau/protractor/commit/1eeff8b1b2e3e8f3b7c8152264411f26d4665a07

正如此处最初所述:https://github.com/angular/protractor/issues/85#issuecomment-26846255 by renanmartins


里面protractor/lib/protractor.js替换

this.driver.get('about:blank');
this.driver.executeScript(
    'window.name = "' + DEFER_LABEL + '" + window.name;' +
    'window.location.href = "' + destination + '"');
Run Code Online (Sandbox Code Playgroud)

  var driver = this.driver;
  this.getCapabilities().then(function (capabilities) {
    if (capabilities.caps_.browserName === 'phantomjs') {
      driver.executeScript('window.name = "' + DEFER_LABEL + '" + window.name;');
      driver.get(destination);
    } else {
      driver.get('about:blank');
      driver.executeScript(
          'window.name = "' + DEFER_LABEL + '" + window.name;' +
          'window.location.href = "' + destination + '"');
    }

    // Make sure the page is an Angular page.
    driver.executeAsyncScript(clientSideScripts.testForAngular, 10).
      then(function(hasAngular) {
        if (!hasAngular) {
          throw new Error('Angular could not be found on the page ' +
              destination);
        }
      });
  });
Run Code Online (Sandbox Code Playgroud)

  • 几个小时前,Protractor Master 中已修复此问题,在 Protractor > 0.16.1 中应该不是问题 (4认同)