Protractor为硒网络驱动程序测试提供了一个很好的API包装,但它实现这一点的方法之一是使用Angular提供的钩子来表示所有出色的异步/轮询操作的完成。这包括http调用、间隔等。
我是Ember的新手,但我怀疑类似的人需要了解路由更改、http调用以及运行循环的一个或多个方面。我已经确认,这样的挂钩可能会打开将Protractor与Ember应用程序结合使用的大门,这最终是我的目标。
那么,有没有办法检测Ember何时进入这种"安静"状态?
以下是Ember的操作方法(仅在测试模式下,测试在Ember命名空间中可用)
function wait(app, value) {
return Test.promise(function(resolve) {
// If this is the first async promise, kick off the async test
if (++countAsync === 1) {
Test.adapter.asyncStart();
}
// Every 10ms, poll for the async thing to have finished
var watcher = setInterval(function() {
// 1. If the router is loading, keep polling
var routerIsLoading = !!app.__container__.lookup('router:main').router.activeTransition;
if (routerIsLoading) { return; }
// 2. If there are pending Ajax requests, keep polling
if (Test.pendingAjaxRequests) { return; }
// 3. If there are scheduled timers or we are inside of a run loop, keep polling
if (run.hasScheduledTimers() || run.currentRunLoop) { return; }
if (Test.waiters && Test.waiters.any(function(waiter) {
var context = waiter[0];
var callback = waiter[1];
return !callback.call(context);
})) { return; }
// Stop polling
clearInterval(watcher);
// If this is the last async promise, end the async test
if (--countAsync === 0) {
Test.adapter.asyncEnd();
}
// Synchronously resolve the promise
run(null, resolve, value);
}, 10);
});
}