angularjs - Properly clear and send input inside each loop in Protractor -


so i'm running issue i'm trying loop through of input fields on page, clear input them, , update them value. here's essential code:

element.all(by.model('part.quantity')).each(function(part_q){     part_q.clear().then(function(){         part_q.sendkeys("1");     }); }).then(function(){     ... } 

this issue varies in scope (i don't mean angular kind), have 7 <input ng-model='part.quantity'> 's on page i'm testing. when run test code above goes through each input , clears of them , updates them value 1, except first 2 input fields. in first 2 fields clears value, adds 1 twice. have these values before running test:

<input ng-model='part.quantity' value="4"> <input ng-model='part.quantity' value="4"> <input ng-model='part.quantity' value="4"> <input ng-model='part.quantity' value="4"> <input ng-model='part.quantity' value="4"> <input ng-model='part.quantity' value="4"> <input ng-model='part.quantity' value="4"> 

afterwards values become

<input ng-model='part.quantity' value="11"> <input ng-model='part.quantity' value="11"> <input ng-model='part.quantity' value="1"> <input ng-model='part.quantity' value="1"> <input ng-model='part.quantity' value="1"> <input ng-model='part.quantity' value="1"> <input ng-model='part.quantity' value="1"> 

but expected result of values 1. changes if have 5 elements. if have 5 doesn't work first input field, works next 4. i've tried various solutions (different locators (e.g. by.css), or running through recursive while loop such as:

$$('.part-quantity').count().then(function(num_parts){     var idx = 0;     function alterquantity() {         while (idx < num_parts){             $$('.part-quantity').get(idx).then(function(part_q){                 part_q.clear().then(function(){                     var rand_num = utils.randomintfrominterval(2, 10).tostring();                     part_quantities.push(rand_num);                     part_q.sendkeys(rand_num).then(function(){                         idx++;                         alterquantity();                     });                 });             });         }     } }); 

or running using filter() instead of each():

$$('.part-quantity').filter(function(part_q, idx){     return part_q.clear().then(function(){         var rand_num = utils.randomintfrominterval(2, 10).tostring()         part_quantities.push(rand_num)         return part_q.sendkeys(rand_num);         browser.sleep(2000);     }); }).then(function(quantity){     console.log(part_quantities); }); 

but filter() used , each() functions function identically. recursive thing doesn't work (i didn't spend time on since didn't see promise in working better). seems webdriver thing i've hit wall @ point , don't know do. don't know if need utilizing promises better? appreciated. thanks.


Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -