我想用量角器的by.repeater
來查找集合中枚舉的所有元素。這裏使用的是ngRepeat指令的(key, value) in expression
枚舉和UI Bootstrap accordion directive。量角器by.repeater和visibilityOf只返回集合中的第一項
的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重複中的第一個元素。這些測試都通過了:
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-重複啓動和NG-重複的高端解決這個問題,但沒有解決它,它仍然只返回集合中的第一個元素。
任何有關如何返回每個汽車的html塊的建議,將不勝感激。
感謝alecxe的幫助和語法建議。我實現了關於使用'$$'的建議,我沒有想到這一點,但我仍然提出了同樣的失敗。我遇到的問題是元素選擇器不會返回列表的「.all」。它只返回重複集合中的第一個項目,同時仍然呈現HTML中的每個項目。我在想也許這是與bootstrap的accordion衍生物或ngRepeat的'key,pair'語法的衝突,但我無法找到有關這兩件事情的信息。 – JessG
@JessG是的,好點,我想我以前多次看到這個錯誤,我懷疑這是一種通用錯誤。讓我們調試它。你可以發佈你的配置,完整的測試和追溯?謝謝,我們會解決它。 – alecxe
@JessG也許嘗試打開''''''之前得到所有的元素。 。'''$( '#汽車類型')點擊(); ';''''''''''''''''''''我在那裏得到了完全相同的錯誤輸出,我記得我做了一些這樣的調整條件,以確保在JS完成所有正在進行的任務之前,Protractor'''element.all()'''不會被觸發。 –