'How to access AngularJS Controller in a E2E test using Protractor

I have an AngularJS application on which I'm performing E2E tests. I want to access my web page's scope object's properties but I can't do so.

I tried doing this in two ways but both the times I got the error 'angular is not defined'

The first way I did was -

browser.executeAsyncScript(function (callback) {
  var scopes = angular.element(document.querySelectorAll('[ng-app]')).scope();
  callback(scope);
  //var scopes = angular.element(document.getElementById('nextbtn')).scope();
}).then(function (output) {
  console.log(output);
});

The second option I tried -

browser.executeScript("angular.element(document.getElementById('nextbtn')).scope().setCurrentStep({ name: 'DepProfile', inst: 0, owner: 'tp' })");

Both times the same error - 'angular not defined'. Can anyone help, what am I missing on? Why can't I access the angular modal?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source