量角器:如何承诺的工作? [英] Protractor: How do promises work?

查看:158
本文介绍了量角器:如何承诺的工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何角作品$ Q库体面的想法,但我不知道量角器或网络驱动器 - JS如何使用它们。 (特别是因为利用率是量角器/网络驱动程序之间略有不同/角度我认为)

例如,样品code我在量角器教程看到似乎被行写入线,并假定$ P $先下一pvious一个操作完成。 (例如browser.get(后跟browser.getTitle URL)())是否有某种隐含的前途怎么回事? (我没有手动推迟决心/完成)

我已经通过<读href=\"https://github.com/angular/protractor/blob/master/docs/getting-started.md\">https://github.com/angular/protractor/blob/master/docs/getting-started.md
和脱脂的链接,webdriver的文档和量角器API,但我的理解仍然是一个有点模糊。有些功能似乎返回值,有些回报的诺言就像同步和异步code的一个奇怪的组合。


解决方案

  

是否有某种隐含的前途怎么回事?


看着<一个href=\"https://github.com/angular/protractor/blob/master/docs/control-flow.md\">https://github.com/angular/protractor/blob/master/docs/control-flow.md ,它看起来像答案是的的,有通过使用承诺的队列,称为控制流。因此,在您的例子展开:

  browser.get(URL);
VAR标题= browser.getTitle();
期待(职称).toEqual(我的标题);

每个线条的上述添加到队列。变量标题其实是一种承诺,它在控制流中的相应位置,期望解开。

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.

解决方案

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.

这篇关于量角器:如何承诺的工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆