q 中“jQuery.active"的等效行为 [英] Equivalent behaviour of 'jQuery.active' in q
问题描述
在我的 c# selenium webdriver 测试中,我偶尔不得不使用:
In my c# selenium webdriver tests I occasionally have to make use of:
public void WaitForJQuery(TimeSpan timeout)
{
var wait = new WebDriverWait(driver, timeout);
wait.Until(d => (bool)(d as IJavaScriptExecutor).ExecuteScript("return jQuery.active == 0"));
}
这会一直等到指定的 'timeout' jQuery 调用完成.我想知道是否有可以用于 q.js 库的等效项?
This waits up until the specified 'timeout' for jQuery calls to finish. I was wondering if there was an equivalent I could use for the q.js library?
我是一名测试人员而不是网页设计师,对 q 库的经验很少,浏览它的文档时我看不到任何可能包含我想要的信息的相关静态属性.
I'm a tester not a webdesigner and have very little experience with the q library, browsing through the documentation for it I can't see any relevant static properties that might contain the information I desire.
推荐答案
不,Q 独立跟踪每个承诺,因此它维护的唯一记录是未处理的拒绝(用于错误报告目的)构建不会太难不过有些事:
No, Q keeps track of each promise independantly so the only record it maintains is unhandled rejections (for error reporting purposes) It wouldn't be too hard to build something though:
var pending = 0;
function register(operation) {
pending++
return Q(operation)
.finally(function() { pending--; });
}
如果你每次创建一个promise都调用register(promise)
,你会得到你想要的结果,只要测试pending === 0
If you call register(promise)
every time you create a promise, you'll get the result you're after by just testing whether pending === 0
这个 register
方法也可以用来检查挂起的 jQuery 承诺(或任何其他类型的承诺,具有有效的 then
方法)自 Q
会吸收它们.
This register
method can also be used to check for pending jQuery promises (or any other type of promise that has a working then
method) since Q
will assimilate them.
这篇关于q 中“jQuery.active"的等效行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!