Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Protractor: How do promises work?

I have a decent idea of how the $q library in angular works but I'm not sure how protractor or web-driver-js uses them. (especially since the utilizations are slightly different between protractor/web-driver/angular I think)

For example, the sample code I've seen in protractor tutorials seem to be written line by line and assumes the previous one completes before the next. (e.g. browser.get(url) followed by browser.getTitle() ) Is there some sort of implicit promising going on? (I don't have to manually defer resolve/fulfill)

I've read through https://github.com/angular/protractor/blob/master/docs/getting-started.md and skimmed the links to the webdriver documentation and protractor api but my understanding is still a bit fuzzy. Some functions seem to return values and some return promises like a weird mix of synchronous and asynchronous code.

like image 558
user2483724 Avatar asked Mar 21 '14 22:03

user2483724


1 Answers

Is there some sort of implicit promising going on?

Looking at https://github.com/angular/protractor/blob/master/docs/control-flow.md , it looks like the answer is yes, there is, by using a queue of promises, called the control flow. So to expand on your example:

browser.get(url);
var title = browser.getTitle();
expect(title).toEqual('My Title');

Each of the lines above adds to the queue. The variable title is actually a promise, which, at the appropriate point in the control flow, expect unwraps.

like image 119
Michal Charemza Avatar answered Oct 12 '22 16:10

Michal Charemza