-1

We're running an angular app and need to wait until angular is done on the page before we try and run our automation.

Our automation is separate from the application, so we need to be able to run a javascript function against the browser to know if the DOM is finished loading and the events are all attached.

Matt Westlake
  • 3,499
  • 7
  • 39
  • 80
  • angularjs allows you to run code when it's finished – Popnoodles Sep 15 '15 at 18:48
  • could be duplicate of this question [AngularJs event to call after content is loaded](http://stackoverflow.com/a/21721060/822711) – Popnoodles Sep 15 '15 at 18:51
  • Are you saying you can't edit the angular app (not don't want to, can't)? – Popnoodles Sep 15 '15 at 20:03
  • @Popnoodles correct, I do not have access to the angular source code (It's being worked on by another team). I hate it and I fought it, but I lost the corporate war on that front, so I need to be able to take the existing ruby/cucumber test suite and have it fire javascript against the browser to determine when everything is done. – Matt Westlake Sep 15 '15 at 20:23
  • So have the other team add a viewContentLoaded function (as in the link I gave) in the app, which will either call a function of your own that executes the automation, or load another script that has all the automation, either way keeping the two separate. – Popnoodles Sep 15 '15 at 20:25
  • ...Or use `setTimeout()` – Popnoodles Sep 15 '15 at 20:26
  • @Popnoodles The function loading the automation won't work (cucumber is an executable on the machine) but how would the setTimeout work? – Matt Westlake Sep 15 '15 at 20:48

1 Answers1

0

jQuery.active is actually tracking the number of active AJAX requests, not the active amount of jquery functions running.

If what you're aiming for is something that fires after all ajax calls are done, do something like this:

var counter = 1;
ajaxCallComplete = function() {
  counter++;
  if(counter >= ajaxCalls) {
    //Do automation
  }
};

Have that declared somewhere, and have your ajax call count declared as well. Have each AJAX call invoke this when it finishes. Don't know if this answers your question fully, but it should get you in the right direction.

Orpheus
  • 727
  • 1
  • 7
  • 22
  • `ajaxCallComplete` is not a jQuery function. Did you mean `$(document).ajaxComplete()`? – Popnoodles Sep 15 '15 at 18:48
  • It's a concept. A complete answer isn't really possible without having the OP's actual code so that we know how he's sending ajax requests. – Kevin B Sep 15 '15 at 18:51
  • I think the first half of the question isn't the actual question, and this bit is *" we need to wait until angular is done on the page before we try and run our automation."* – Popnoodles Sep 15 '15 at 18:53
  • The issue here is that i'm writing automation scripts for an application that I cannot modify. How we were doing this before was doing a "wait" until element was visible && jQuery.active == 0. I need to be able to run a snipit of javascript to ensure the DOM is finished rendering and all events are attached. – Matt Westlake Sep 15 '15 at 18:55
  • You'll have to hook into whatever is sending the ajax requests. This was easy with jQuery because jQuery provides an interface that supports it. If all your existing code is using is xhr directly, there's nothing you can do. – Kevin B Sep 15 '15 at 19:24