【问题标题】:Protractor : Error while waiting for Protractor to sync with the page: {}量角器:等待量角器与页面同步时出错:{}
【发布时间】:2014-05-16 15:51:12
【问题描述】:

好的,我有一个 Angular 应用程序,其中有指令和其他一些普通的 html 元素。 这个指令很有趣,因为它使用 RaphaelJs 来创建自定义图形。该指令还使用 require js 来加载依赖项(如 raphel.js)。一切正常:)

现在是困难的部分。我想写一些端到端的测试用例。我想选择指令创建的 svg 元素并检查一些属性值。

所以在浏览器 (Chrome) 控制台中,我键入 $('tspan'),我看到简单的 css 选择器返回了许多 tspans 元素。

样本时间跨度

<tspan dy="7" style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0);">Somevalue</tspan>

当我在 E2E 工作表中编写相同的查询时

 var svgElement = $('tspan')[0];
 console.log(svgElement);

它记录以下内容:

{ click: [Function],
  sendKeys: [Function],
  getTagName: [Function],
  getCssValue: [Function],
  getAttribute: [Function],
  getText: [Function],
  getSize: [Function],
  getLocation: [Function],
  isEnabled: [Function],
  isSelected: [Function],
  submit: [Function],
  clear: [Function],
  isDisplayed: [Function],
  getOuterHtml: [Function],
  getInnerHtml: [Function],
  findElements: [Function],
  isElementPresent: [Function],
  evaluate: [Function],
  '$$': [Function],
  findElement: [Function],
  '$': [Function],
  find: [Function],
  isPresent: [Function] }

当我尝试访问同一元素上的 getText 方法时,我得到了

 var svgElement = $('tspan');
    console.log(svgElement.getText());

C:\Users\abc\AppData\Roaming\npm\node_modules\protractor\node_modules\seleniu
m-webdriver\lib\webdriver\promise.js:1549
      throw error;
            ^
Error while waiting for Protractor to sync with the page: {}

无法理解根本原因。有人可以帮忙吗?

【问题讨论】:

  • 尝试添加“browser.ignoreSynchronization = true;” (或“ptor.ignoreSynchronization = true;”)在运行您的第一个测试之前。

标签: angularjs protractor


【解决方案1】:

如果这是问题所在,我认为您会收到不同的错误,但我认为您可能需要格式化 getText() 如下所示,因为它使用了 Promise。

var svgElement = $('tspan');
svgElement.getText().then(function (text){
   console.log(text);
}

您的任何测试都在运行吗?我只有“等待量角器与页面同步时出错:{}”,因为 ng-app 不在 body 标签上,请参阅this 以获取解决方案。

【讨论】:

    【解决方案2】:

    我刚刚学会了量角器和角度版本紧密耦合的艰难方式。

    使用 angular 1.2.16 和 Protractor 0.23.1 会导致您遇到的错误 - 似乎内部 angular API 已更改。 (量角器中的测试正在尝试执行:

      angular.element(el).injector().get('$browser').notifyWhenNoOutstandingRequests(callback);
    

    并且 injector() 在 1.2.16 中的元素上不存在。因此我失败了)

    在我的情况下,我正在测试更新到 angular 1.3-beta.10,这似乎会导致一个更加复杂的世界(至少与量角器 0.23.1 有关系)

    【讨论】:

      猜你喜欢
      • 2018-12-07
      • 2019-08-16
      • 2019-10-03
      • 2016-04-26
      • 2015-10-05
      • 2023-03-12
      • 1970-01-01
      • 2015-05-06
      • 2019-06-12
      相关资源
      最近更新 更多