Reputation: 1
I am writing test cases using protractor for AngularJS Application. I want to stop an if loop once it finds the value. Is there any equivalent function available that I can use to stop executing the loop further in Protractor, like we have break in C.
Upvotes: 0
Views: 2347
Reputation: 131
This is my code and i want break after if statement because text has been match i dont want to again go to else block
for (i = 0; i <row.length; i++)
{
var obj_dn_ocnele=obj_dn_ocndrpdown_elements.get(i).getText().then(function(text) {
var test_var1 = text.trim();
console.log(test_var1);
outer:{
if (test_var1 == var_ocn_id)
{
log.info(var_ocn_id +"ocn exist");
break outer;
}
else
{
log.error(var_ocn_id +"ocn not exist");
break outer;
}
}
});
}
Upvotes: 0
Reputation: 29520
break
is a javascript instruction:
function testBreak(x) {
var i = 0;
while (i < 6) {
if (i == 3) {
break;
}
i += 1;
}
return i * x;
}
A complete reference of the language is available on the mozilla developer network with a list of all the statements.
Brendan Eich wrote:
JavaScript borrows most of its syntax from Java, but also inherits from Awk and Perl, with some indirect influence from Self in its object prototype system.
NB: This question is neither specific to protractor, nor angular.js nor to automation.
Upvotes: 2
Reputation: 1278
There is break/continue in javascript:
http://www.w3schools.com/js/js_break.asp
Upvotes: 0