My journey of learning protractor has been quite an adventure, especially since I am relatively new to JavaScript. I have discovered that protractor queues all promises and they can be executed using then(). However, I am currently facing an issue with using a filter() on an ElementArrayFinder as it does not seem to execute properly. Only when I prepend it with the return keyword does the filter get executed, but then I exit my function which is not my intention. Can anyone help me understand this better?
Here is the code I am working with:
it('Select service', function() {
servicePage.services.filter(function(elem, index) {
return elem.getAttribute('class').then(function(attribute) {
console.log('*****' + attribute);
return attribute === 'service passive';
});
});
servicePage.services.get(0).element(by.tagName('input')).click();
});
When running the above code, the console log is not displayed indicating that the filter function may not be executing. When I modify the code as shown below, the filter is executed but the click() function is not performed.
it('Select service', function() {
return servicePage.services.filter(function(elem, index) {
return elem.getAttribute('class').then(function(attribute) {
console.log('*****' + attribute);
return attribute === 'service passive';
});
});
servicePage.services.get(0).element(by.tagName('input')).click();
});
Another Example:
it('Select service', function() {
servicePage.services.filter(function(elem, index) {
return elem.getAttribute('class').then(function(attribute) {
console.log('*****' + attribute);
return attribute === 'service passive';
});
}).first().element(by.tagName('input')).click();
});
Thank you in advance for your assistance! Best regards