如何使用量角器 a table 和来自 API 的数据进行测试

How to test with protractor a table with data got from API

在 Angular8 项目中,我想用量角器 a table 测试来自 API

的数据

在我的 HTML 页面中:

      <tr *ngFor="let pop of popList" class="pops-list">
        <td>{{pop.name}}</td>
        <td class="pop-description">{{pop.description}}</td>
        <td>{{pop.id}}</td>
        <td>{{pop.area}}</td>
        <td>{{pop.timeZone}}</td>
      </tr>

我的量角器配置

const { SpecReporter } = require('jasmine-spec-reporter');

exports.config = {
  allScriptsTimeout: 11000,
  specs: [
    './src/**/*.e2e-spec.ts'
  ],
  capabilities: {
    'browserName': 'chrome'
  },
  directConnect: true,
  baseUrl: 'http://localhost:4200/',
  framework: 'jasmine',
  SELENIUM_PROMISE_MANAGER: false,
  jasmineNodeOpts: {
    showColors: true,
    defaultTimeoutInterval: 30000,
    print: function() {}
  },
  onPrepare() {
    require('ts-node').register({
      project: require('path').join(__dirname, './tsconfig.e2e.json')
    });
    jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
  }
};

在我的测试中,我正在尝试:

await element.all(by.repeater('pop in popList')).count().then(count => console.log(count));

count.toEqual(3) 给出错误: 属性 'toEqual' 在类型 'number' 上不存在。

你能帮忙解决一下吗?

所以使用 async 和 await 效果很好,不确定这是否是最好的方法, 在我的规范文件中:

  it('should be populated with list data', async () => {
    await page.navigateToAdministration();
    let popList = await element.all(by.css('table .pops-list'));
    expect(popList.length).toBe(41);
  });

  it('should display correct POP names', async () => {
    await page.navigateToAdministration();
    const popItems = await element.all(by.css('.pops-list')).all(by.css('.pop-name'));
    expect(popItems[0].getText()).toEqual('AMI');
    expect(popItems[1].getText()).toEqual('ANN');
    expect(popItems[2].getText()).toEqual('AUB');
  });

我在 html.

中添加了一些 css 类 到 select