量角器 element.click() 抛出异常

Protractor element.click() throwing an exception

我想弄清楚为什么下面的 .click() 会导致量角器崩溃:

  this.clickSecondPanel = function () {      
    element(by.css('div.panels-gs.panel-top-two-gs')).click();
  }      

直到我将行更改为:

 element(by.css('div.panels-gs.panel-top-two-gs')).click;

我的 spec.js 看起来像:

var DataCardPage = require('./pageObjects/dataCard.page.js');
var dataCardPage = new DataCardPage();

describe('Clicking on the 2nd panel', function () {

  dataCardPage.clickSecondPanel();        
    it('Should select the 2nd test panel', function () {                
        expect(dataCardPage.getSecondPanelText()).toBe('TEST123');     
  });

在我的代码的其他地方,我使用 .click()(带括号),所以这让我感到困惑。

错误很严重:

 Started
[17:44:23] E/launcher - Error while waiting for Protractor to sync with    the page
: "window.angular is undefined.  This could be either because this is a  non-angu
lar page or because your test involves client-side navigation, which can     interfe
re with Protractor's bootstrapping.  See http://git.io/v4gXM for details"

感谢任何建议...

鲍勃

尝试在测试开始时使用 browser.ignoreSynchronization=true。可能是您尝试自动化的应用程序不包含 angular。

在上面的评论中解决了这个问题,作为答案发布。

我的建议是尝试将 clickSecondPanel() 移动到 it 块内。从 "best practice" 的角度来看,它本身看起来很可疑,因为我没有任何 jasmine 函数之外的代码,即 itbeforeAllafterAll 等(不要老实说,我什至不知道我是从哪里学来这个习惯的)。

它似乎还影响了控制流和异步执行,因此 click() 事件触发得太早了。这可以部分解释为 this documentation and/or this blog post