protractor icon indicating copy to clipboard operation
protractor copied to clipboard

Sporadic "Angular could not be found" errors with node-webkit

Open avh4 opened this issue 12 years ago • 5 comments

I am working on setting up protractor to work with node-webkit. My sample application is here: https://github.com/avh4-scratch/node-webkit-angular-tdd-sample/tree/protractor ("protractor" branch).

Currently, the setup seems to be working, but I get a lot of occasional failures. Sometimes all the tests succeed, but about 60% of the time, one or more of the protractor tests fail with this error ("Angular could not be found on the page ... angular never provided resumeBootstrap"):

$ ./node_modules/.bin/protractor protractor.js 

------------------------------------
PID: 13933 (capability: chrome #1)
------------------------------------

Starting selenium standalone server...
Selenium standalone server started at http://192.168.2.140:52063/wd/hub
.F.

Failures:

  1) Hello World typing a name says "Hello <name>"
   Message:
     Error: Angular could not be found on the page file:///Users/avh4/Documents/workspace/node-webkit-angular-tdd-sample/index.html# : angular never provided resumeBootstrap
   Stacktrace:
     Error
    at null.<anonymous> (/Users/avh4/Documents/workspace/node-webkit-angular-tdd-sample/acceptance/HelloTest.js:11:9)
    at null.<anonymous> (/Users/avh4/Documents/workspace/node-webkit-angular-tdd-sample/acceptance/HelloTest.js:10:5)
    at Object.<anonymous> (/Users/avh4/Documents/workspace/node-webkit-angular-tdd-sample/acceptance/HelloTest.js:1:63)
At async task:
      Error: Angular could not be found on the page file:///Users/avh4/Documents/workspace/node-webkit-angular-tdd-sample/index.html# : angular never provided resumeBootstrap
    at assertAngularOnPage (/Users/avh4/Documents/workspace/node-webkit-angular-tdd-sample/node_modules/protractor/lib/protractor.js:865:13)
==== async task ====
WebDriver.executeScript()
    at Protractor.get (/Users/avh4/Documents/workspace/node-webkit-angular-tdd-sample/node_modules/protractor/lib/protractor.js:872:15)
    at null.<anonymous> (/Users/avh4/Documents/workspace/node-webkit-angular-tdd-sample/acceptance/HelloTest.js:12:21)
==== async task ====
asynchronous test function

Finished in 14.229 seconds
3 tests, 3 assertions, 1 failure

Shutting down selenium standalone server.
[launcher] Runner Process Exited With Error Code: 1

Some notes about the setup:

  • chromedriver2_server from the node-webkit project is downloaded and placed in ./support/protractor
  • The node-webkit app is built and placed in ./support/protractor, alongside chromedriver2_server
  • protractor.conf.js specifies ./support/protractor/chromedriver2_server as the webdriver
  • protractor.conf.js specifies a hardcoded file:// baseUrl (I haven't found a better way to do this)
  • The standalone selenium provided by webdriver-manager update is used
  • A modified version of protractor is used, changing about:blank to nw:blank to work around a known problem: https://github.com/avh4/protractor/commit/b8bbe4d345d6202fb125395dae5358525d7efd2d apart from that one change, it is the same as the master branch of protractor

How can I go about debugging this problem where sometimes angular is found and sometimes it isn't?

Again, sometimes the tests all pass, but often it fails complaining that angular can't be found on the page.

avh4 avatar Mar 09 '14 02:03 avh4

I don't know a ton about node-webkit, but here's a little background. Angular will only export a resumeBootstrap function if window.name has the correct prefix (DEFER_LABEL in protractor.js). Maybe node-webkit is sometimes not setting the window name?

juliemr avatar Apr 22 '14 19:04 juliemr

Ah, spoke too soon. I'm still getting intermittent failures, like @avh4.

(I previously wrote:)

@juliemr you helped me at least. protractor does:

window.name = DEFER_LABEL + window.name;
window.location.assign(destination)

which doesn't seem to lead to the desired behaviour of loading the new url with the given name.

You can easily work around this by injecting something into the tests that sets the window.name before angular is loaded, but I don't know what the best way to do this without having to modify your source is.

mikaraento avatar Apr 28 '14 06:04 mikaraento

Right, the following works reliably (at least with angular 1.2):

  1. use manual bootstrapping (remove ng-app)
  2. bootstrap with (something like):
      angular.element(window.document).ready(function() {
          window.name='NG_DEFER_BOOTSTRAP! Hello World!';
          window.document.body.setAttribute('ng-app', '');
          angular.bootstrap(window.document.body, []);
      });

It's important to delay the bootstrap until ready(), otherwise you may get angular continuing to bootstrap on its own (from it's own ready() callback).

mikaraento avatar Apr 28 '14 06:04 mikaraento

Can this issue be closed?

hankduan avatar Jun 23 '14 23:06 hankduan

I'm cleaning up the issues by closing old ones that haven't had responses in a while. Please open a new issue if you feel there is still a problem, or ask on Stack Overflow if your issue is actually a question.

juliemr avatar Sep 04 '14 20:09 juliemr