javascript - looping through key/value pair of promises in protractor -
i using protractor test series of webpages (actually 1 webpage of angular design, others well). have created series of page objects handle this. minimize code maintenance have created object key value pairs so:
var object = { pagelogo: element(by.id('logo')), searchbar: element.all(by.classname('searchthing')), ... };
the assumption being need add object make usable everywhere in page object file. of course, file has functions (assuming not familiar page object pattern) such:
var pagenamepageobject = function () { var object = {...}; //list of elements this.get = function() { brower.get('#/somewebtag'); } this.getelementtext = function(somename){ if (typeof somename == 'number') ... (convert or handle exception, whatever) return object[name].gettext(); } ...
*note these examples , these promises can handled in variety of ways in page object or main tests
the issue comes attempting "cycle" through object. given particular test attempting verify, among other things, elements on particular web page attempting loop through these objects using "ispresent()" function. have made many attempts, , brevities sake not list them here, include creating wrapper promise (using "q", must admit have no idea how works) , attempting run function in 'expect' hoping jasmine core wait looping promises resolve , read output (it more of last ditch effort really).
you should loop did before on of elements, if want in particular order, create recursive function calls next element in json.
now, handle jasmine specs finishing before , stuff. function needs added protractor's flow control wait continue, read more here. , also, dont use q in protractor, use protractor's implementation of webdriverjs promises.
also, consider using isdisplayed instead, assuming want dispalayed on page.
so basically, code skeleton this:
it(.....{ var flow = webdriver.promise.controlflow(); return webdriver.execute(function () {//your checks on page here, //if need extract external function described in first paragraph
well think should provide enough info on how handle waiting promises in protractor, hope helped.
Comments
Post a Comment