Within my index.html file, I explicitly define the following:
window.myAppInstance = new MyApp.myAppConstructor();
In the todo-spec.js file, I set up the following structure:
describe('verifying my web page', function() {
it('should confirm the existence of "myAppInstance" object on the window', function() {
browser.get('https://my.web.page.com');
function checkMyTest() {
return Object.keys(window.myAppInstance).sort();
};
var p = browser.driver.executeScript(checkMyTest);
p.then(function(result) {
console.log("success");
console.log(result);
}, function() {
console.log("error occurred");
console.log(arguments);
});
});
});
However, when using Protractor, my application is not detected. It returns either null or undefined:
Error
{ '0':
{ [WebDriverError: unknown error: Cannot convert undefined or null to object
(Session info: chrome=50.0.2661.102)
... and various other irrelevant information
Yet, when inspecting Chrome's console, I am able to execute
window.myAppInstance
without any issues, displaying the object correctly.
How can I retrieve this window object during my Protractor test?
Note 1: Clarification provided regarding the constructors.
Note 2: My application uses manual bootstrapping in AngularJS. Upon further examination, I include this line in my test:
<snip>
browser.get('https://my.web.page.com');
**browser.pause()**
<snip>
Current steps: 1) Press F12 to bring up Chrome developer tools 2) Check the console for errors indicating a crashed app 3) Manually refresh the browser 4) Observe the successful reload of the app. Confusion sets in as to why programmatically launching the page with
browser.get('https://my.web.page.com');
differs enough from manually entering the URL in the browser to cause issues.
I now ponder, What factor in running the tests via Protractor would lead to the failure of my app?