量角器页面对象计数错误返回

时间:2018-10-22 09:14:26

标签: angular typescript ionic-framework protractor cucumber

我正在尝试使用量角器和黄瓜为Ionic应用程序编写一些e2e测试。我遵循了页面对象模式,但是由于某种原因,尽管我等待元素出现,但对count()的调用返回了0。但是,如果我入睡,它会起作用。这是我的步骤:

Then('my cases should be listed', function (callback) {
  casesPage.isLoaded()
  .then(() => {
    expect(casesPage.numberOfFamilies())
      .to.eventually.equal(20)
      .and.notify(callback);
  })
});

还有我的页面对象

import { browser, $, $$, by, ElementFinder, ElementArrayFinder } from 'protractor';

export class CasesPage {

  listOfFamilies: ElementArrayFinder;

  private initializePromise: Promise<void>;

  async initialize(): Promise<void> {
    if(!this.initializePromise) {
      return this.initializePromise = new Promise<void>(async (resolve) => {
        this.listOfFamilies = $$('ul.families li.family');
        return resolve();
      });
    }
  }

  get() {
    return browser.get('/cases')
  }

  async isLoaded(): Promise<boolean> {
    await this.initialize();
    return this.listOfFamilies.isPresent();
  }

  async numberOfFamilies(): Promise<number> {
    await this.initialize();
    // browser.sleep(3000); Uncommenting this works
    return this.listOfFamilies.count();
  }

}

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

<svg viewBox="0 0 600 600" xmlns:xlink="http://www.w3.org/1999/xlink"> <svg width="400" height="30" y="40"> <rect width="300" height="30" style="fill:rgb(255,0,0);" /> <text x="0" y="15" fill="white">Fatality</text> </svg> <svg width="400" height="30" y="80"> <rect width="300" height="30" style="fill:rgb(255,0,0);" /> <text x="0" y="15" fill="white">Lost Time Incidents</text> </svg> <svg width="400" height="30" y="120"> <rect width="300" height="30" style="fill:rgb(255,128,0);" /> <text x="0" y="15" fill="white">Restricted Work Cases</text> </svg> <svg width="400" height="30" y="160"> <rect width="300" height="30" style="fill:rgb(255,128,0);" /> <text x="0" y="15" fill="white">Medical Treatment Cases</text> </svg> <svg width="400" height="30" y="200"> <rect width="300" height="30" style="fill:rgb(255,128,0);" /> <text x="0" y="15" fill="white">First Aid Cases</text> </svg> <svg width="400" height="30" y="240"> <rect width="300" height="30" style="fill:rgb(255,128,0);" /> <text x="0" y="15" fill="white">RTA Incident</text> </svg> <svg width="400" height="30" y="280"> <rect width="300" height="30" style="fill:rgb(255,128,0);" /> <text x="0" y="15" fill="white">Environment Incident</text> </svg> <svg width="400" height="30" y="320"> <rect width="300" height="30" style="fill:rgb(102,204,0);" /> <text x="0" y="15" fill="white">Near Miss</text> </svg> <svg width="400" height="30" y="360"> <rect width="300" height="30" style="fill:rgb(102,204,0);" /> <text x="0" y="15" fill="white">Unsafe Acts & Conditions</text> </svg> <svg width="400" height="30" y="400"> <rect width="300" height="30" style="fill:rgb(102,178,255);" /> <text x="0" y="15" fill="white">Man Hours</text> </svg> <svg id="polys" height="430" width="430" viewBox="0 0 430 430" x="160" > <polygon points="215,0, 0,430 430,430 215,0" style="fill:white;stroke:red;stroke-width:1" /> </svg> </svg>返回应解决的Promise问题。只需在其前添加this.listOfFamilies.count()

await