Search code examples
classprotractorrepeater

Search for a value by class or repeater in protractor?


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.


Solution

  • 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;