Sporadic "Angular could not be found" errors with node-webkit
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_serverfrom the node-webkit project is downloaded and placed in./support/protractor- The node-webkit app is built and placed in
./support/protractor, alongsidechromedriver2_server protractor.conf.jsspecifies./support/protractor/chromedriver2_serveras the webdriverprotractor.conf.jsspecifies a hardcodedfile://baseUrl (I haven't found a better way to do this)- The standalone selenium provided by
webdriver-manager updateis used - A modified version of protractor is used, changing
about:blanktonw:blankto 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.
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?
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.
Right, the following works reliably (at least with angular 1.2):
- use manual bootstrapping (remove ng-app)
- 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).
Can this issue be closed?
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.