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

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

问题描述

我对 Angular 中的 $q 库如何工作有一个不错的了解,但我不确定量角器或 web-driver-js 是如何使用它们的.(特别是因为我认为量角器/网络驱动程序/角度之间的利用率略有不同)

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)

例如,我在量角器教程中看到的示例代码似乎是逐行编写的,并假定前一个在下一个之前完成.(例如 browser.get(url) 后跟 browser.getTitle() )是否存在某种隐含的承诺?(我不必手动推迟解决/履行)

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)

我已通读 https://github.com/angular/protractor/blob/master/docs/getting-started.md并浏览了指向 webdriver 文档和量角器 api 的链接,但我的理解仍然有点模糊.一些函数似乎返回值,而一些返回承诺就像是同步和异步代码的奇怪组合.

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?

https://github.com/angular/protractor/blob/master/docs/control-flow.md ,看起来答案是是的,通过使用一个承诺队列,称为控制流.因此,扩展您的示例:

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');

上面的每一行都添加到队列中.变量 title 实际上是一个 promise,它在控制流中的适当位置,expect 解包.

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天全站免登陆