As a newcomer to using Protractor for automating AngularJS applications, I am encountering difficulties in selecting an element from a list due to issues with error handling caused by promises.
In the given code snippet, when providing an invalid categoryName, instead of displaying the error message it proceeds to the verification part and fails.
I have tried implementing callback functions without success, as well as utilizing try-catch blocks with no luck either. Any guidance on understanding and resolving this issue would be greatly appreciated. Thank you.
this.elements = element.all(by.css('.xyz'));
this.selectCategory = function (categoryName) {
this.elements.each(function (category) {
category.getText().then(function (text) {
if (text === categoryName) {
log.info("Selecting Category");
category.click();
}
}, function (err) {
log.error('error finding category ' + err);
throw err;
});
})
};