javascript - How to loop a promise in for loop and break if condition met -


i new using promise , breaking head solve this. want run script until condition met in protractor below code it's not working. how fix this?

let counter = 30; (let = 0; < counter; i++) {    browser.executescript(somescript).then((value) => {     //console.log(value);     if (value > 0)        //do stuff     }     else {       return; //exit loop --not working        //or       i=counter;// exit if , counter value same     }   })  } 

i have limitedretry code appear need

limitedretry = (cont, fn) => fn().catch(err => cont > 0 ? limitedretry(cont - 1, fn) : promise.reject(err)); 

your use be

limitedretry(30, function() {     browser.executescript(somescript).then((value) => {         if (value > 0) {             // stuff             return 'this resolved value of promise';         } else {             return promise.reject('try again');         }     }); }) .then(v => console.log(v)) .catch(err => console.log(err)); 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -