我可以像这样使用 filter
来计算visible 项目:
it('should have correct number of visible columns', function () {
expect(tableHeaders.filter(function (header) {
return header.isDisplayed()
}).count()).toBe(6);
});
但是我怎样才能更好地计算不可见的呢?
这一个不起作用,因为 header.isDisplayed()
返回一个 Promise,而不仅仅是一个 bool 值:
it('should have correct number of visible columns', function () {
expect(tableHeaders.filter(function (header) {
return !header.isDisplayed()
}).count()).toBe(6);
});
那么,我应该如何以最 Protractor 的方式计算不可见的项目?
最佳答案
我已经知道如何使用 .reduce()
为此目的:
expect(tableHeaders.reduce(function (acc, header) {
return header.isDisplayed()
.then(function (isDisplayed) {
return acc += !isDisplayed ? 1 : 0;
})
}, 0)).toBe(7);
如果项目未显示,我将累加器变量增加 1
,然后返回它并与正确的值进行比较。
关于javascript - 如何用 Protractor 计算不可见的项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34434736/