量角器超时 [英] Protractor timeouts

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

问题描述

我一直在开发中量角器相当长的一段时间,像许多你自动测试,我碰到它只能与 browser.sleep() -bridge。我不是硬编码的东西,如该风扇,但如果它是一个必要我会的。

I've been developing automated tests in Protractor for quite some time and like many of you, I've run into gaps which can only be crossed with the browser.sleep()-bridge. I'm not a fan of hard coding things such as this but if it's a necessity I will.

我已经开发的测试已经给我带来了一个点,每个 browser.sleep(1000)对我的运行产生重大影响。目前测试正在测试权限的不同账户(128完全相同),这包括登录和注销,同时检查是每个帐户,并没有收到访问。

The tests I've developed have brought me to a point where every browser.sleep(1000) has a major impact on my runtime. The tests are currently testing permissions for different accounts (128 exactly) and this involves logging in and out whilst checking what every account has and has not received access to.

该网站,我测试的是一个纯粹的AngularJS应用当中,在我眼里,应该让 browser.sleep() pcated方法去$ P $既然有准确等到页面相比,满载browser.sleep()A browser.waitForAngular()这等待一组的时间,如果你的网站是不是那个时候(它发生)中加载,你就会有不一致的测试(没有人喜欢不一致)。

The website I'm testing is a pure AngularJS application which, in my eyes, should make browser.sleep() a deprecated method since there is a browser.waitForAngular() method that accurately waits until the page is fully loaded compared to browser.sleep() which waits a set amount of time and if your website isn't loaded within that time (it happens), you'll have an inconsistent test (nobody likes inconsistency).

研究使我相信, browser.waitForAngular(),因为他们还没有相关AngularJS并没有考虑到动画以及相关耗时的功能,这是在我们的网站上未实现。此外 waitForAngular()基本上等待 $消化 $ HTTP $超时

Research has led me to believe that browser.waitForAngular() does not take into account animations and related time-consuming features since they're not AngularJS related yet this is not implemented in our website. Also waitForAngular() basically waits for $digest, $http, and $timeout.

什么我问的是阉这是后话这被看作是因为量角器可以接受的损失一般是很大的,还是有我俯瞰的东西在这里?

What I'm asking is wether this is something which is regarded as an acceptable loss since Protractor is great in general or is there something I'm overlooking here?

TL; DR:
是否有解决方案在那里,让我们不要满足于 browser.sleep()

来源:量角器超时文档
<一href=\"https://github.com/angular/protractor/blob/3d60689b423749686973227f4b26cbb494f60b66/debugging/timeout_spec.js\"相对=nofollow>超时 - spec.js(量角器文档),
Issue909 ,的 Issue279 Issue92 ,<一个href=\"http://stackoverflow.com/questions/27240744/why-must-i-use-browser-sleep-while-writing-protractor-tests\">StackQuestion1

推荐答案

如果你能想出一些测试,以确定是否在等待完成什么,你可以使用<一个href=\"http://angular.github.io/protractor/#/api?view=webdriver.WebDriver.prototype.wait\"><$c$c>browser.wait.以从思想从 http://docsplendid.com/archives/209 ,则可以通过返回解析为一个承诺的函数真正,比如一个使用<一个href=\"http://angular.github.io/protractor/#/api?view=ElementFinder.prototype.is$p$psent\"><$c$c>is$p$psent

If you can devise some sort of test to determine if whatever you're waiting for has completed, you can use browser.wait. Taking ideas from from http://docsplendid.com/archives/209, you can pass a function that returns a promise that resolves to true or false, such as one that uses isPresent

browser.wait(function() {
  return element(by.id('some-element')).isPresent();
}, 1000);

或者如果你有一些更复杂的情况,你可以使用承诺链接:

or if you have some more complicated condition you can use promise chaining:

browser.wait(function() {
  return element(by.id('some-element')).isPresent().then(function(isPresent) {
    return !isPresent;
  });
}, 1000);

和命令流会等待,一边喊传递给功能等待,直到它返回的承诺解析真正

and the command flow will wait, repeatedly calling the function passed to wait, until the promise it returns resolves to true.

这篇关于量角器超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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