Using filter to find element within an element in Protractor

One of the challenges of test automation is minimising dependencies on test data. For most tests, you don’t care which specific data you use, it’s usually based on criteria. For example, take this list of users.


User List
I am going to use Gherkin format to outline requirement, as in this context I am using CucumberJS/Protractor framework:

Scenario: Manage zero jobs users
Given I am on user list page
And I select to next user with zero jobs assigned

The test code:

// Returns the next user from the list who has zero jobs assigned
this.Then(/^I click the next employee with no status$/, function () {
element.all(by.repeater('users in ctrl.uisers')).filter(function (elem) {
// Get value from the 5th column (number of jobs)
return elem.all(by.css('td')).get(4).getText().then(function (jobs) {
// Stop filtering once code hits jobs value 0
return jobs === '0';
});
// Click this first filtered row
}).first().click();
});



No Comments


You can leave the first : )