Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$browser.notifyWhenNoOutstandingRequests doesn't take controller function into account

We are testing angular webapp with phantomjs.

Controller code looks like this:

angular.module('module' ['dependency']).
    controller('controller',function ($scope, Model) {
        // blah-blah-blah
        Model.list() // calls $http.get
            .then(); // yadda-yadda-yadda
    });

Backend is in java, so in order to test the whole app, we're using Selenium Webdriver and PhantomJS. I use this snippet to check if angular has finished processing it's directives (got it from protractor source code).

var app = angular.element(document.querySelector('#ng-app'));
var $browser = app.injector().get('$browser');
$browser.notifyWhenNoOutstandingRequests(function () {
    // callback
});

It works fine - in most of cases it really can detect angular processing requests.

The problem is that sometimes my callback seems to fire even before controller gets executed. In all cases where i've noticed that behavior, it's a route change. I've tried inserting alert(''); into different parts of controller to find that out.

So, the question is - how can i execute my waiting snippet only after controller function was executed?

like image 546
ilj Avatar asked Nov 02 '22 11:11

ilj


1 Answers

Per the GitHub discussion, the issue you mention is specific to PhantomJS. Other environments seem fine.

Caveat: I don't use Phantom, and this talk is 1 year old (as of Dec 2014) — so it's possible that this is no longer an issue.

like image 173
New Alexandria Avatar answered Nov 11 '22 21:11

New Alexandria