量角器在 PhantomJS 上运行测试 [英] Protractor running tests on PhantomJS

查看:24
本文介绍了量角器在 PhantomJS 上运行测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

这与示例中的文件相同,只是 browserName 和 seleniumAddress 端口发生了变化:

//示例配置文件.出口.config = {//正在运行的 selenium 服务器的地址.seleniumAddress: 'http://localhost:9515',//传递给 webdriver 实例的能力.能力:{'浏览器名称':'phantomjs'},//规范模式是相对于当前直接工作的//量角器被调用.规格:['onProtractorRunner.js'],//传递给 Jasmine-node 的选项.茉莉花节点选项:{显示颜色:真实,}};

我收到以下错误消息:

UnknownError:错误信息 =>'检测到页面卸载事件;异步脚本执行不适用于页面加载.

我在 github 上发现了 这个问题,这似乎是相关的.我以为我已经足够了解他们的 brower-setup.md 以将其包含在我的 beforeEach 函数之一中.然后我发现 here ptor 无论如何都只是在包装驱动程序.哇,我知道我是量角器/硒领域的菜鸟,但信噪比非常具有说服力.我真的很想获得使用 PhantomJS 的性能优势,但是在这方面多花几个小时的前景让我很头疼.我使用的是 Windows 7 Enterprise 64 位,以防万一.谢谢!

解决方案

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

https://github.com/pschwartau/protractor/commit/1eeff26f3b7c8152264411f26d4665a07"/p>

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

<小时>

在 protractor/lib/protractor.js 中替换

this.driver.get('about:blank');this.driver.executeScript('window.name = "' + DEFER_LABEL + '" + window.name;'+'window.location.href = "' + 目的地 + '"');

 var driver = this.driver;this.getCapabilities().then(function (capabilities) {如果(capabilities.caps_.browserName === 'phantomjs'){driver.executeScript('window.name = "' + DEFER_LABEL + '" + window.name;');driver.get(目的地);} 别的 {driver.get('关于:空白');driver.executeScript('window.name = "' + DEFER_LABEL + '" + window.name;'+'window.location.href = "' + 目的地 + '"');}//确保页面是 Angular 页面.driver.executeAsyncScript(clientSideScripts.testForAngular, 10).然后(函数(hasAngular){如果(!hasAngular){throw new Error('在页面上找不到Angular' +目的地);}});});

I can't seem to get PhantomJS through a test successfully. I tried to integrate it into my project, but after that failed I tried to just run the basic Angular Docs samples and I'm getting the same issue. My steps so far:

  • npm install -g phantomjs
  • phantomjs --webdriver=9515 // ... GhostDriver - Main - running on port 9515
  • protractor protractorConf.js

This is the same file from the example with only browserName, and seleniumAddress port changed:

// 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,
  }
};

I get the following error message:

UnknownError: Error Message => 'Detected a page unload event; asynchronous script execution does not work across page loads.'

I found this issue on github, which seemed to be related. I thought I had made enough sense of their brower-setup.md to include it in one of my beforeEach functions. Then I found here ptor is just wrapping the driver anyway. Wow, I know I'm a noob here in protractor/selenium land, but the signal to noise ratio is intensively dissuasive. I'd really like to get the performance benefits of using PhantomJS, but the prospect of losing several more hours on this is hurting my head. I'm on Windows 7 Enterprise 64-bit, in case that matters. Thanks!

解决方案

Acutally this fix was solving the same issue for me:

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

As originally described here: https://github.com/angular/protractor/issues/85#issuecomment-26846255 by renanmartins


Inside protractor/lib/protractor.js Replace

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

with

  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);
        }
      });
  });

这篇关于量角器在 PhantomJS 上运行测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆