2016-11-18 27 views
1

條件在我的應用我想通過使用它的名字所有者名稱來選擇特定的通知。我如何在量角器中做到這一點? 我增加了截圖,我想從列表中選擇通知「由SONAL達拉爾測試Auction1」。 第二個屏幕顯示的通知 「測試Auction1由SONAL達拉爾」 我曾嘗試下面的規範文件中的代碼頁代碼如何識別特定的元素與兩個期望量角器

enter image description here

enter image description here

Auction.AuctionNotiNewInv.isDisplayed().then(function(){ 
     Auction.NotificationTitle.get(0).isDisplayed().then(function(){ 
      Auction.NotificationTitle.count().then(function(Count){ 
       console.log(Count); 
       var NotifTitleCount = Count; 
       for(var i=0; i < NotifTitleCount; i++) { 
        Auction.NotificationTitle.get(i).isDisplayed().then(function(){ 
         Auction.NotifAuctioneer.isDisplayed().then(function(IsDisplayed){ 
         if(IsDisplayed) 
          Auction.NotificationTitle.get(i).click(); 
         else 
          console.log('New Auction invitation is not displayed.'); 

         }); 
        }); 
       } 
      }); 
     }); 
    }); 

和PO文件如下圖所示:

this.AuctionNotiNewInv = element(by.cssContainingText('.md-subheader-inner','NEW INVITATIONS')); 
this.NotificationTitle = element.all(by.cssContainingText('.title.ng-binding',data.AuctionName)); 
this.NotifAuctioneer = element(by.cssContainingText('.subtitle.ng-binding',data.NewFirstName + ' ' + data.NewLastName)); 

但上面的代碼返回我數= 4,因爲有它有「NotificationTitle」的同一屬性頁面上的其他對象,但它不是通知列表的一部分。 有人建議我另一種方式來處理這個問題用期待的功能?

回答

3

您可以使用filter()方法來篩選基於conditions.Try以下定位的元素列表,

var expectedTitle= 'TestAuction1'; 
var expectedOwner = 'Sonal Dalal'; 
var notificationElement = element.all(by.repeater("notif in notifSubList")).filter(function(notification){ 
    var title = notification.element(by.css("span.title")).getText(); 
    var owner = notification.element(by.css("span.subtitle")).getText(); 
    return protractor.promise.all([title,owner]).then(function(result){ 
    return result[0].trim() == expectedTitle && result[1].trim() == expectedOwner; 
    }) 
}).first(); 
+0

非常感謝,它爲我工作。 –