我正在尝试使用量角器的by.repeater
来查找集合中枚举的所有元素。这里使用的是ngRepeat指令的(key, value) in expression
枚举和UI Bootstrap accordion directive。
HTML是:
<accordion id="automobile-types" close-others="true">
<accordion-group heading="{{ autoType }}"
ng-repeat="(autoType, details) in automobiles">
<div>Color of automobile:</div>
<ul>
<li ng-repeat="color in details.color">
{{ color }}
</li>
</ul>
</accordion-group>
</accordion>
哪里
automobiles = {
'Car': {'color': 'black', 'name': 'Knight Rider' },
'Truck': {'color': 'green', 'name': 'Biggins'}
}
使用protractor example in the angular docs for ngRepeat,这是我的量角器代码:
var EC = protractor.ExpectedConditions;
var cars = element.all(by.repeater('(autoType, details) in automobiles'));
it('should have two automobiles listed', function() {
var visibleList = EC.visibilityOf(cars);
browser.wait(visibleList, 5000);
expect(cars.count()).toEqual(2);
});
返回此失败:
Failed: Cannot call method 'bind' of undefined
如果我删除.all
,测试将继续,因为它只找到ng-repeat中的第一个元素。这些测试通过:
var car = element(by.repeater('(autoType, details) in automobiles'));
expect(car.getText()).toEqual('Car');
var accordion = element(element(by.id('automobile-types')));
expect(accordion.getText()).toEqual('Car\nTruck');
我试图通过使用ng-repeat-start和ng-repeat-end来解决这个问题,但是没有解决它,它继续只返回集合中的第一个元素。
关于如何为每辆汽车返回html块的任何建议都将不胜感激。
答案 0 :(得分:1)
首先,您应该调用rbenv global 2.3.0
内的element.all()
。并且在您定义it()
的行的末尾有一个缺少的逗号。修正版:
cars
如果仍然无效,请尝试使用by.exactRepeater()
:
it('should have two automobiles listed', function() {
var cars = element.all(by.repeater('(autoType, details) in automobiles'));
expect(cars.count()).toEqual(2);
});
或者,切换到替代定位技术:
var cars = element.all(by.exactRepeater('(autoType, details) in automobiles'));
此处var cars = $$('[ng-repeat="(autoType, details) in automobiles"]');
是$$
的快捷方式。
答案 1 :(得分:1)
看来Cannot call method 'bind' of undefined
的失败是对Expected Condition visibiltyOf
的回应,而不是最初假设的by.repeater
。
在传递元素列表时,visibiltyOf
方法看起来仅采用单个元素。这些测试现在通过了:
var EC = protractor.ExpectedConditions;
var cars = element.all(by.repeater('(autoType, details) in automobiles'));
var carTypes = element(by.id('automobile-types));
it('should have two automobiles listed', function() {
var visibleList = EC.visibilityOf(carTypes);
browser.wait(visibleList, 5000);
expect(cars.count()).toEqual(2);
});