本文介绍了如何在量角器/硒中实现间隔的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一系列自动化测试并遇到间歇性超时/同步错误.我在网上看了,被告知使用间隔可以解决这个问题

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

我想知道如何将 interval.js 文件与其他文件合并?我是在 protractor-config.js 中添加一行,还是将其链接到其他地方.如果是这样,我如何链接它?

I was wondering how do I incorporate the interval.js file with the rest of the files? Do I add a line to protractor-config.js, or do I link it elsewhere. If so, how do I link it?

推荐答案

$interval 服务与 Angular 捆绑在一起;您无需下载任何新文件或与 Protractor 集成任何内容.您的 Protractor 测试很可能按照它们的方式进行.

The $interval service comes bundled with Angular; you don't need to download any new files or integrate anything with Protractor. Your Protractor tests are most likely just fine the way they are.

当他们告诉您使用 $interval 时,每个人的意思是您(或您公司的开发人员)需要查看您应用的源代码以了解 $timeout或重复发生的 $http 请求(在递归函数、循环或两个错误地相互调用的函数中),或者可能是失败的 $http 请求(这会在 Chrome 开发者控制台的网络"标签下以鲜红色显示).

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).

循环 $timeout s(以及失败的 $http 请求)不好的原因是量角器,按照设计,将等待 每个 $timeout 回调和 $http 请求在它做任何事情之前完全完成.但是,它不会等待 $interval 回调完成.$interval 的语法与 $timeout 几乎完全相同,因此从一种变为另一种并不困难——唯一的区别是 $timeout 执行一次,并且 $interval 在一个连续循环中执行.官方文档如下:

The reason why looping $timeouts (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. However, it will not wait for $interval callbacks to complete. $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. Official docs are below:

$timeout

$interval

在我发布的另一个答案中列出了更多的可能性,以及 Protractor 可能发生的原因的官方列表的链接:超时等待量角器在 50001ms 后与页面同步

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

我 90% 的保证是这些问题之一,但如果您提供有关您的情况的更多信息,我可以提供一些更具体的提示.

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.

这篇关于如何在量角器/硒中实现间隔的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 22:05