I want to use the $ q service for angular in my e2e tests. (I want to get texts from several elements via getText (), which returns a promise. After all promises are resolved, I want to check the list. Therefore, I want to use $ q.all (), etc.).
angular.injector(['myApp']).get('$q'); result: "ReferenceError: angular not defined"
Installing angular through node, and then var angular = require("angularjs");leading to the error "Error: cannot find the module" angular "
Also, inserting browser.waitForAngular()there does not help.
Using syntax inject(function($q) {})has the same problem.
How can I use such angular functions in the protractor?
edit:
Here is the most naive version of what I want to achieve
var collectEntries = function(containers) {
var entries = {};
containers.each(function (container) {
var title = container.element(by.tagName('h2'));
title.getText().then(function (text) {
var key = getSomeKey();
var entry = processEntry(text);
entries[key] = entry;
});
});
return entries;
};
, - . . , , , , getText promises .
.
var deferred = $q.defer();
$q.all(getTextPromises).then(function () {
deferred.resolve(entries);
});
return deferred.promise;