Reputation: 173
In my application I want to select specific notification by using it's name AND owner name. How can I do that in protractor? I have added screenshot and I want to select notification "Test Auction1 by Sonal Dalal" from the list. Second screenshot shows the page code for notification "Test Auction1 by Sonal Dalal"
I have tried below code in spec file:
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.');
});
});
}
});
});
});
And PO file is as below:
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));
but above code returns me count = 4, as there are other objects on page which has same property of "NotificationTitle" but it's not a part of notification list. Can anybody suggest me another way to handle this using expect function?
Upvotes: 1
Views: 621
Reputation: 4832
You can use filter()
method to filter list of elements based on conditions.Try the below locator,
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();
Upvotes: 3