I am new to protractor for automating angularJs apps. I am trying to select one element from a list of elements. I am trying to do error handling, but nothing works as I expected because of the promises.
In the following code, if I pass an invalid categoryName it never prints the error instead it goes to the verification part(expect) and fail.
Please help me understand this and how can I resolve this issue. I tried using callback but not luck. I also tried try catch and still no luck. Appreciate any help here. Thanks
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;
});
})
};