mat-selection-list 复选框的量角器 e2e 打字稿 - select 全部

protractor e2e typescript for mat-selection-list checkboxes - select all

如何使用量角器选中此页面中的所有复选框?

我尝试以这种方式访问​​元素,但似乎不起作用。

select = element(by.cssContainingText('mat-card-title', 'Classifications'))
    .all(by.css('mat-pseudo-checkbox'));

您的方法无效,因为 mat-card-title 没有任何子元素。链接 element() 调用时,它始终只搜索子元素。

为了选择正确的元素,我们必须使用父元素 mat-card 并通过 by.cssContainingText() 对其进行过滤。

过滤后,我们必须找到 mat-pseudo-checkbox 元素并将点击发送到这些底层元素。

可以这样实现:

// select correct element group
let wrapper = element.all(by.tagName('mat-card'))
  .filter(el => el.element(by.tagName('mat-card-title'))
  .getText()
  .then(text => {
    console.log('looking if\'', text, '\'contains Classifications');
    return text.indexOf('Classifications') > -1;
  }));

   wrapper.all(by.css('mat-card-content mat-selection-list mat-list-option .mat-list-item-content .mat-list-text'))
  .each(async el => await el.click());

资源

量角器备忘单:

量角器通用样式指南 => https://github.com/CarmenPopoviciu/protractor-styleguide

作弊-sheet => https://gist.github.com/javierarques/0c4c817d6c77b0877fda

随着测试套件的增长,您应该考虑使用 Page Object Model 模式进行测试。我们将它用于我们的测试,它是一个很好的分离测试逻辑的模式。 => https://www.thoughtworks.com/insights/blog/using-page-objects-overcome-protractors-shortcomings