1
我正在使用量角器編寫一些e2e測試。頁面鏈接可能會更改鏈接的名稱和數量。我想讓頁面告訴我鏈接名稱和鏈接數量,然後遍歷每個鏈接並單擊它。如何返回頁面上的鏈接並點擊它們
的HTML如下:
<div class="ng-scope" ng-repeat="Transition in DirectTransitions">
<p class="ng-binding" ng-click="selectTransition(Transition)">Draft</p>
</div>
<div class="ng-scope" ng-repeat="Transition in DirectTransitions">
<p class="ng-binding" ng-click="selectTransition(Transition)">Approved</p>
</div>
<div class="ng-scope" ng-repeat="Transition in DirectTransitions">
<p class="ng-binding" ng-click="selectTransition(Transition)">Posted</p>
</div>
我可以在每個點擊個別這樣的:
it('should select Draft', function() {
element.all(by.repeater('Transition in DirectTransitions'));.filter(function(elem) {
return elem.getText().then(function(text) {
return text === 'Draft';
});
}).click();
});
我目前做的,但如果文本更改或其他鏈接被添加/移除到頁面。我必須回去再次重構,以添加/刪除鏈接或更改我正在嘗試避免的文本。
我能夠得到這樣的鏈接名稱。
it('should get link names', function() {
element.all(by.repeater('<locator>')).map(function(item) {
return item.getText();
}).then(function(labels) {
expect(labels).toEqual(['one', 'two', 'three']);
});
});
但一直未能弄清楚如何迭代每個鏈接並點擊每個鏈接。
謝謝,我會給這個嘗試:) –
這沒有點擊第一個元素,我帶我到下一頁,如我所料。然後,我不得不導航回到頁面的初始鏈接它,但沒有選擇下一個鏈接,我得到一個錯誤「失敗:陳舊元素引用:元素沒有附加到頁面文檔」 –
@ DennisFerguson啊,這個意味着頁面在第一次點擊後發生變化。這裏是一個相關的線程:http://stackoverflow.com/q/29823757/771848。另外,你可以跟蹤一個鏈接樣本的當前索引(不在js /量角器中):http://stackoverflow.com/questions/13448091/how-to-fetch-all-links-and-click-those -links-一個接一個使用硒-的webdriver。希望有所幫助。 – alecxe