i have had asynchronous calls on place in protractor , javascript in general. used take 2 lines of code takes 10. here's example:
i writing protractor utility method check dom properties on group of related divs , input text boxes. validation framework working on. idea pass protractor element method , based on element's id check dom properties on related divs , input text boxes. how got work:
/** * checks error in nuaf field * @param {string or element} field . * @param {string} errortext expected validation error text appear in tooltip */ exports.checkforerror = function (field, errortext) { var innercheck = function(fieldid) { expect(fieldid).not.tobe(undefined); var elmntd = element(by.id('divinput.'+fieldid)); expect(elmntd).not.tobe(null); expect(elmntd.getattribute('tooltip')).tocontain(errortext); expect(exports.hasclass(element(by.id('prnt.'+fieldid)), 'has-error')).tobe(true); }; // unbelievably complex block of code gets id of // field argument. if string passed, fieldid . if (typeof field === 'string') { innercheck(field); } else { //what used field.id needs 6 lines of code? field.getattribute('id').then( function(idattribute) { console.log( "*********: "+idattribute ); innercheck(idattribute); } ); } };
question is: there better, less verbose way write field.getattribute('id').then
block of code. it's shame write id of element.
this not verbose asynchronous code... if take account can directly pass function innercheck
promise:
// unbelievably complex block of code gets id of // field argument. if string passed, fieldid . if (typeof field === 'string') { innercheck(field); } else { field.getattribute('id').then(innercheck); }
should easy
Comments
Post a Comment