I am working on an e2e test using protractor. I have a search field that I would like to test. I would like to make sure that every time I search for a keyword that is being shown in the table, the search will filter out everything else.
To achieve this I am using two for loops: the first loop, loops through the items that are being displayed. It grabs the items and types it in the search field. The table display dynamically updates. The second loop, loops through the updated display table to ensure the value of the field matches what we have put in the search box.
My problem is that the second for loop ( inside a second promise) uses the result from the first promise: "testingSuit". "testingSuit" is a fixed value by the time the second promise is executed, as it is not in a nested loop.
How can I use the result of one promise in another nested promise?
describe('Test Suit Search', function () {
it('Testing Hearts suits', function () {
return element.all(by.className('view')).count().then(function(rowCount) {
//for every suit that we have in the view do:
for (i=0 ; i< rowCount; i++)
{
// first clear the suit search field and
element.all(by.className('suitSearch')).get(0).clear();
//get the suit value
var testingSuit = element(by.exactRepeater("card in cards").row(i).column("card.suit")).getText();
// then insert the value in the search field
element.all(by.className('suitSearch')).get(0).sendKeys(testingSuit);
//loop through the results:
element.all(by.binding('card.suit')).count().then(function(resultRowCount ){
for ( j=0; j<resultRowCount; j++)
{
expect(testingSuit).toEqual(element.all(by.binding('card.suit')).get(j).getText());
}
return;
})
}
return;
})
});
});
Here is the HTML code:
<select ng-model="orderProp">
<option class="option" value="suit">Suit</option>
<option class="option" value="numOrd">Number</option>
</select>
Number search: <input type="text" ng-model="searchTerm.card.number">
search: <input class="suitSearch" type="text" ng-model="searchTerm.card.suit">
<table>
<tr><th><th><th>Number</th><th>Suit</th></tr>
<tr ng-repeat="card in cards | orderBy:orderProp | filter:searchTerm.card ">
<td><a class="view" href="#/home/number/{{card.number}}/suit/{{card.suit}}">View</a></td>
<td><a class="delete" href="#/delete/number/{{card.number}}/suit/{{card.suit}}">Delete</a></td>
<td>{{card.number}}</td>
<td class="blah" >{{card.suit}}</td>
</tr>