I have a web test code and I don't want to iterate over the rest after i found the item. This code iterate to all item and the finally return. How to resolve this problem, because in the each I don't break!
isItemPresent: function (name) {
var def = Q.defer();
Trace.add("Checking the " + name + " inside the menu");
var count = 0, total = 0, stop = false;
var listObj = element(by.id(this.MENU_ID)).all(by.tagName("div"));
listObj.count().then(function (nr) {
total = nr;
listObj.each(func);
});
var _this = this;
var func = function (element) {
element.getAttribute('class').then(function (classes) {
count++;
if (classes.indexOf(name) !== -1 && !stop) {
stop = true;
element.getAttribute('id').then(function (value) {
_this._isItemVisible('', value).then(function (opt) {
value = value.match(/(\d+)/g);
if (opt.success) {
// console.log('------- BREAK --------');
def.resolve({success: true, msg: {index: value[0]}});
Trace.add("Menu item: " + name + " was found in the main menu.");
} else {
def.resolve({success: false, msg: {index: value[0]}});
Trace.add("Menu item: " + name + " was not found in the main menu.");
}
});
});
} else if (count === total && stop === true) {
def.resolve({success: false, msg: {index: 0}});
Trace.add("Menu item: " + name + " was not found in the main menu.");
stop = true;
}
});
};
return def.promise;
};