【发布时间】:2018-06-13 22:08:56
【问题描述】:
我是 Protractor 的新手。我正在做自动化测试,在我的功能文件中我有这个要检查:
When('there are at least two ports loaded', function (next) { }
在我的 html 中我有这个:
<div class="port-element ">
<div class="image-loader" style="display: inline;">
<picture> (...) </picture>
我正在尝试做一个循环来检查这个,但也许我真的不明白如何:
let port_element = element.all(by.css('port-element '));
port_element.each(function (item) {
console.log('Port element count: ', item);
});
next();
但我不明白怎么做。
根据建议,我在 stepdefinition 中使用了这个:
let count = await element.all(by.css('.port-element')).count();
for(let i=1;i<=count;i++)
{
let selector = 'div.port-element div.image-loader:nth-child('+i+')');
//selector is the element within each div to now check
}
和
expect(element.all(by.css('div.port-item div.image-loader')).count()).to.be.above(2)
但我现在有这个错误:
AssertionError: expected ManagedPromise::4833 {[[PromiseStatus]]: "pending"} to be a number or a date
现在我尝试这样做:
let img_loader_count = element.all(by.css('div.port-element div.image-loader'));
console.log('img loader count: ', img_loader_count.count());
但我在控制台上有这个: img 加载器计数:0
img loader 有 12 个,所以这是不可能的。为什么在控制台上打印 0? 有人可以帮我吗?
谢谢。
【问题讨论】:
标签: javascript loops protractor cucumber cucumberjs