我写了Protractor自动化测试并面临一个问题.
Wait command实际上并没有等待其中一个数组元素.请参阅下面的示例:我尝试在导航到网页后等待第一个元素.
原文链接:https://www.f2er.com/angularjs/141186.htmlvar 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); }); });
但是测试失败并出现以下错误:失败:索引超出范围.尝试访问index:0处的元素,但只有0个元素匹配locator by.repeater(“listCtrl.categories中的类别”).
错误不依赖于定位器类型,因为两者都出现:“by.repeater”和“by.css”.
选择器没问题,添加’sleep’命令后测试通过:
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() { browser.get('http://www.deep.mg/'); browser.sleep(15000); browser.wait(EC.visibilityOf(category.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); }); }); });
此外,超时参数没有帮助,它只是忽略它并立即失败.
所以问题是如何等待数组的某个元素?我错过了什么吗?谢谢.