我编写量角器自动化测试并面临一个问题。 Wait command实际上并不等待其中一个数组元素。看下面的例子:我尝试等待导航到网页后的第一个元素。量角器:'等待'不适用于“element.all”
var category = element.all(by.repeater('category in listCtrl.categories'));
var category2 = $$('.category-name.custom-tooltip-link.ng-binding');
var EC = protractor.ExpectedConditions;
describe('wait for the first category', function() {
it('wait', function() {
browser.get('http://www.deep.mg/');
browser.wait(EC.visibilityOf(category.get(0)), 20000);
browser.wait(EC.visibilityOf(category2.get(0)), 20000);
});
});
但测试失败,出现以下错误:Failed: Index out of bound. Trying to access element at index: 0, but there are only 0 elements that match locator by.repeater("category in listCtrl.categories")
。
错误不依赖于定位器类型,因为两者都出现:“by.repeater”和“by.css”。 的选择都OK,测试将“休眠”命令后经过:
var category = element.all(by.repeater('category in listCtrl.categories'));
var category2 = $$('.category-name.custom-tooltip-link.ng-binding');
var EC = protractor.ExpectedConditions;
describe('wait for the first category', function() {
it('wait', function() {
browser.get('http://www.deep.mg/');
browser.sleep(15000);
browser.wait(EC.visibilityOf(category.get(0)), 20000);
browser.wait(EC.visibilityOf(category2.get(0)), 20000);
category.count().then(function(count1) {
console.log(count1); //count returns 5, which means there are actually elements in array
});
category2.count().then(function(count2) {
console.log(count2);
});
});
});
而且超时参数没有帮助,它只是忽略了它,并立即失败。
所以问题是如何等待数组的某个元素?我错过了什么吗?谢谢。
答案有帮助吗?谢谢。 – alecxe
@alecxe是的,它有。谢谢! –