javascript - Protractor - Returning pending promise when functioned out -


i trying create function comb through array of elements , return first instance of 1 meets criteria.

this have inside test does work:

element.all(by.css('_cssselector_')).filter(function(elms, index) {         return elms.getattribute('height').then(function(height) {             return parseint(height) > 0;         });     }).then(function(validelms) {          browser.actions().mousemove(validelms[0]).perform();     } 

...but if function out, does not work:

getvalidelm = function() {     var validelm = element.all(by.css('_cssselector_')).filter(function (elms, index) {         return elms.getattribute('height').then(function (height) {             return parseint(height) > 0;         });     }).then(function (validelms) {         return validelms[0];         });      return validelm; } 

if run:

var validelmfrompage = getvalidelm(); console.log(validelmfrompage); 

i get: promise::2046 {[[promisestatus]]: "pending"}

which points issue of inside function not resolving before var outside function being used. after reading (extensively) through posts here, , wonderful blog post (http://spin.atomicobject.com/2014/12/17/asynchronous-testing-protractor-angular/), still can't figure out deal is. know it's simple, controlflow related?

thanks help.

let function return promise. since filter() returns elementarrayfinder, should able use first():

getvalidelm = function() {     return element.all(by.css('_cssselector_')).filter(function (elms, index) {         return elms.getattribute('height').then(function (height) {             return parseint(height) > 0;         });     }).first(); } 

first() return elementfinder can pass mousemove():

var elm = getvalidelm(); browser.actions().mousemove(elm).perform(); 

Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -