Reputation: 649
I have a table with multiple columns and multiple rows, the rows are in repeater and each row has the same class. Basically I am automating a search functionality test in protractor and I want to see if the searched value is present in the results that are given. So basically I need to go inside each class or repeater visible and check for a value? If the value is present or contained in any of the elements the test passes, if not the test fails.
Upvotes: 0
Views: 379
Reputation: 3645
Assuming your search string is "SearchKey" and results are displayed in a list of elements like below
<li class="file" ng-repeat="result in results" ng-class="{blahblah}">
<li class="file" ng-repeat="result in results" ng-class="{blahblah}">
<li class="file" ng-repeat="result in results" ng-class="{blahblah}">
Your test case should have assertion something like below
var xpathExp = "//li[contains(.,'" + SearchKey + "')]"
expect(element(by.xpath(xpathExp).isDisplayed()).to.eventually.be.true;
Upvotes: 0
Reputation: 474281
If you are asking what locator to choose - "by repeater" or a "by class", generally speaking, the choice would depend on how distinct and readable of a repeater and class you have available.
For instance, if you have item in items
repeater and product
class, it would be preferred to use the product
class since item in items
is too generic of a repeater and might not be distinct on the page at the moment or in the future (this might come as a surprise some day and might lead to some hair loss during debugging).
Or the opposite example, if you have product in products
repeater and col-md-1
class, then the "by repeater" locator would be preferred since col-md-1
class is a UI- and layout- oriented class and does not contain or bring any "data"-specific information; and it is more likely to be changed in the future.
Another point is that the "by repeater" locator would make your tests even more tied to AngularJS, but the "by class" approach is a little bit more generic and is agnostic of what the application is built on.
Upvotes: 1