如何用量角器检查元素是否存在?

mas*_*ner 4 protractor angular

我为Angular2应用程序编写了以下量角器测试:

describe('Puppet container', () => {

  beforeEach(() => {
    browser.get('/#/puppet');
  });

  it('should display puppet summary', () => {
    browser.wait($('puppet-summary').isPresent, 1000);

    const subject = $('puppet-summary').isDisplayed();
    const result = true;

    expect(subject).toEqual(result);
  });

});
Run Code Online (Sandbox Code Playgroud)

它一直失败,原因如下: Failed: Cannot read property 'parentElementArrayFinder' of undefined

谁能告诉我为什么我会收到这个错误?我有一个页面,只显示<puppet-summary>加载后端数据时的元素.这就是为什么我要检查它是否存在(它只在半秒左右后出现).要仅在有数据显示时显示,我使用以下HTML代码:

<div *ngIf="puppetMasters.length">
    <puppet-summary></puppet-summary>
</div>
Run Code Online (Sandbox Code Playgroud)

puppetMasters 是一个数组,一旦加载来自后端的数据就会被填充.

ale*_*cxe 5

browser.wait($('puppet-summary').isPresent, 1000);

"等待元素存在"应该通过内置的 presenceOf预期条件完成:

var EC = protractor.ExpectedConditions;
var elm = $('puppet-summary');
browser.wait(EC.presenceOf(elm), 1000);
Run Code Online (Sandbox Code Playgroud)