Nightwatch.js: window is undefined
From Nighwatch.js (and selenium-webdriver, more specifically) you cannot directly access to the DOM of the client.You must use the execute() function to inject your script :
this.demoTest = function (browser) { browser.execute(function(data) { var canUseDOM = !!( typeof window !== 'undefined' && window.document && window.document.createElement ); alert('canUseDOM ?' + canUseDOM); return true; }, [], null); };
More info in the API : http://nightwatchjs.org/api#execute
It turns out I was loading application code in my test without noticing, my nightwatch configuration wasn't quite right. So this is where the error was being raised, because Nightwatch was trying to access window
in the test code.