Reputation: 139
I had a submenu with list passing from the database.I'm using ng-repeat to show the list which will not be in the same sequence every time. How can i test it using the protractor, right now i'm testing as:
element(by.cssContainingText('.menu li:nth-child(8)',Pizza')).click();
But it is failing when the nth-child is not in the 8th list or if "pizza" element is not found in the list. I want to write the tests for the element that is not in the list as well, Suppose Pizza is not passing from the database, it should skip that test.
My question here is how can i test this scenario i dont have any id here as well ? IS there any way i can click the element if it matches the text and skip the test if that element is not found in submenu?
Upvotes: 0
Views: 571
Reputation: 15070
It could be something like that :
var foundElement = element.all(by.repeater('data in collection')).filter(function(data) {
return data.getText().then(function(text) {
return text === 'Pizza';
});
});
foundElement(0).element(by.css('.menu li')).click();
Upvotes: 1