简体   繁体   English

如何在量角器/硒中实现间隔

[英]How to implement intervals in protractor/selenium

I'm writing a series of automated tests and get intermittent timeout/synchronization errors. 我正在编写一系列自动化测试,并遇到间歇性超时/同步错误。 I looked online and was told that using intervals would solve this problem 我在网上查看时,被告知使用间隔可以解决此问题

https://github.com/angular/angular.js/blob/master/src/ng/interval.js https://github.com/angular/angular.js/blob/master/src/ng/interval.js

I was wondering how do I incorporate the interval.js file with the rest of the files? 我想知道如何将interval.js文件与其余文件合并? Do I add a line to protractor-config.js, or do I link it elsewhere. 我要在protractor-config.js中添加一行,还是在其他地方链接它。 If so, how do I link it? 如果是这样,我该如何链接?

The $interval service comes bundled with Angular; $interval服务与Angular捆绑在一起; you don't need to download any new files or integrate anything with Protractor. 您无需下载任何新文件或与Protractor集成任何内容。 Your Protractor tests are most likely just fine the way they are. 您的量角器测试很可能是按原样进行的。

What everyone means when they tell you to use $interval is that you (or your company's developers) need to look through the source code of your app for $timeout or $http requests that are happening repeatedly (in a recursive function, a loop, or two functions that mistakenly call each other), or possibly an $http request that is failing (this would show up in bright red in Chrome's developer console, under the Network tab). 每个人告诉您使用$interval是,您(或您公司的开发人员)需要查看应用程序的源代码,以发现重复发生的$timeout$http请求(在递归函数,循环,或两个函数相互调用错误),或可能失败的$http请求(该请求将在Chrome开发人员控制台的“网络”标签下以亮红色显示)。

The reason why looping $timeout s (and failing $http requests) are bad is that Protractor, by design, will wait for every $timeout callback and $http request to finish completely before it will do anything. 循环$timeout (和失败的$http请求)之所以不好是因为,按设计,量角器将等待每个 $timeout回调和$http请求完全完成,然后再执行任何操作。 However, it will not wait for $interval callbacks to complete. 但是,它不会等待$interval回调完成。 $interval has almost exactly the same syntax as $timeout , so it's not difficult to change from one to the other--the only difference is that $timeout executes once, and $interval executes on a continuous loop. $interval具有与$timeout几乎完全相同的语法,因此将一个语法更改为另一个语法并不困难-唯一的区别是$timeout执行一次,并且$interval在连续循环中执行。 Official docs are below: 官方文档如下:

$timeout $超时

$interval $间隔

A few more possibilities are listed at another answer I posted, along with a link to Protractor's official list of reasons why this might happen: Timed out waiting for Protractor to synchronize with the page after 50001ms 我发布的另一个答案中还列出了其他几种可能性,以及指向量角器可能发生这种情况的原因的正式列表的链接: 等待50001ms后,量角器与页面同步

I give you my 90% guarantee that it is one of these issues, but if you provide more information about your situation, I can give some more specific tips. 我给您90%的保证,这是其中一个问题,但是,如果您提供有关您情况的更多信息,我可以提供一些更具体的提示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM