protractor
Advanced tools
Comparing version 2.4.0 to 2.5.0
@@ -41,3 +41,4 @@ /** | ||
* Wait until Angular has finished rendering and has | ||
* no outstanding $http calls before continuing. | ||
* no outstanding $http calls before continuing. The specific Angular app | ||
* is determined by the rootSelector. | ||
* | ||
@@ -54,2 +55,6 @@ * Asynchronous. | ||
try { | ||
if (window.getAngularTestability) { | ||
window.getAngularTestability(el).whenStable(callback); | ||
return; | ||
} | ||
if (!window.angular) { | ||
@@ -74,2 +79,28 @@ throw new Error('angular could not be found on the window'); | ||
/** | ||
* Wait until all Angular2 applications on the page have become stable. | ||
* | ||
* Asynchronous. | ||
* | ||
* @param {function(string)} callback callback. If a failure occurs, it will | ||
* be passed as a parameter. | ||
*/ | ||
functions.waitForAllAngular2 = function(callback) { | ||
try { | ||
var testabilities = window.getAllAngularTestabilities(); | ||
var count = testabilities.length; | ||
var decrement = function() { | ||
count--; | ||
if (count === 0) { | ||
callback(); | ||
} | ||
}; | ||
testabilities.forEach(function(testability) { | ||
testability.whenStable(decrement); | ||
}); | ||
} catch (err) { | ||
callback(err.message); | ||
} | ||
}; | ||
/** | ||
* Find a list of elements in the page by their angular binding. | ||
@@ -560,3 +591,4 @@ * | ||
* @param {number} attempts Number of times to retry. | ||
* @param {function} asyncCallback callback | ||
* @param {function({version: ?number, message: ?string})} asyncCallback callback | ||
* | ||
*/ | ||
@@ -571,9 +603,11 @@ functions.testForAngular = function(attempts, asyncCallback) { | ||
try { | ||
if (window.angular && window.angular.resumeBootstrap) { | ||
callback([true, null]); | ||
if (window.getAllAngularTestabilities) { | ||
callback({ver: 2}); | ||
} else if (window.angular && window.angular.resumeBootstrap) { | ||
callback({ver: 1}); | ||
} else if (n < 1) { | ||
if (window.angular) { | ||
callback([false, 'angular never provided resumeBootstrap']); | ||
callback({message: 'angular never provided resumeBootstrap'}); | ||
} else { | ||
callback([false, 'retries looking for angular exceeded']); | ||
callback({message: 'retries looking for angular exceeded'}); | ||
} | ||
@@ -584,3 +618,3 @@ } else { | ||
} catch (e) { | ||
callback([false, e]); | ||
callback({message: e}); | ||
} | ||
@@ -587,0 +621,0 @@ }; |
@@ -101,6 +101,12 @@ var path = require('path'), | ||
// https://github.com/angular/protractor/issues/2413 | ||
var fileName = patterns[i].split(':')[0], | ||
lineNumber = patterns[i].split(':')[1], | ||
matches = glob.sync(fileName, {cwd: cwd}); | ||
var lineNumber = ''; | ||
var parsedPath = path.parse(patterns[i]); | ||
parsedPath.base = parsedPath.base.replace(/:\d+/, function (match) { | ||
lineNumber = match; | ||
return ''; | ||
}); | ||
var filePath = path.format(parsedPath); | ||
var matches = glob.sync(filePath, {cwd: cwd}); | ||
if (!matches.length && !opt_omitWarnings) { | ||
@@ -111,4 +117,4 @@ log.warn('pattern ' + patterns[i] + ' did not match any files.'); | ||
var resolvedPath = path.resolve(cwd, matches[j]); | ||
if(lineNumber) { | ||
resolvedPath += ':' + lineNumber; | ||
if (lineNumber) { | ||
resolvedPath += lineNumber; | ||
} | ||
@@ -115,0 +121,0 @@ resolvedFiles.push(resolvedPath); |
@@ -260,3 +260,15 @@ var util = require('util'); | ||
/** | ||
* Instead of using a single root element, search through all angular apps | ||
* available on the page when finding elements or waiting for stability. | ||
* Only compatible with Angular2. | ||
*/ | ||
Protractor.prototype.useAllAngular2AppRoots = function() { | ||
// The empty string is an invalid css selector, so we use it to easily | ||
// signal to scripts to not find a root element. | ||
this.rootEl = ''; | ||
}; | ||
/** | ||
* The same as {@code webdriver.WebDriver.prototype.executeScript}, | ||
@@ -329,6 +341,16 @@ * but with a customized description for debugging. | ||
return this.executeAsyncScript_( | ||
clientSideScripts.waitForAngular, | ||
'Protractor.waitForAngular()' + description, | ||
this.rootEl). | ||
function runWaitForAngularScript() { | ||
if (self.rootEl) { | ||
return self.executeAsyncScript_( | ||
clientSideScripts.waitForAngular, | ||
'Protractor.waitForAngular()' + description, | ||
self.rootEl); | ||
} else { | ||
return self.executeAsyncScript_( | ||
clientSideScripts.waitForAllAngular2, | ||
'Protractor.waitForAngular()' + description); | ||
} | ||
} | ||
return runWaitForAngularScript(). | ||
then(function(browserErr) { | ||
@@ -626,36 +648,48 @@ if (browserErr) { | ||
then(function(angularTestResult) { | ||
var hasAngular = angularTestResult[0]; | ||
if (!hasAngular) { | ||
var message = angularTestResult[1]; | ||
var angularVersion = angularTestResult.ver; | ||
if (!angularVersion) { | ||
var message = angularTestResult.message; | ||
throw new Error('Angular could not be found on the page ' + | ||
destination + ' : ' + message); | ||
} | ||
return angularVersion; | ||
}, function(err) { | ||
throw 'Error while running testForAngular: ' + err.message; | ||
}) | ||
.then(null, deferred.reject); | ||
.then(loadMocks, deferred.reject); | ||
// At this point, Angular will pause for us until angular.resumeBootstrap | ||
// is called. | ||
var moduleNames = []; | ||
for (var i = 0; i < this.mockModules_.length; ++i) { | ||
var mockModule = this.mockModules_[i]; | ||
var name = mockModule.name; | ||
moduleNames.push(name); | ||
var executeScriptArgs = [mockModule.script, msg('add mock module ' + name)]. | ||
concat(mockModule.args); | ||
this.executeScript_.apply(this, executeScriptArgs). | ||
then(null, function(err) { | ||
throw 'Error while running module script ' + name + | ||
': ' + err.message; | ||
}) | ||
.then(null, deferred.reject); | ||
function loadMocks(angularVersion) { | ||
if (angularVersion === 1) { | ||
// At this point, Angular will pause for us until angular.resumeBootstrap | ||
// is called. | ||
var moduleNames = []; | ||
for (var i = 0; i < self.mockModules_.length; ++i) { | ||
var mockModule = self.mockModules_[i]; | ||
var name = mockModule.name; | ||
moduleNames.push(name); | ||
var executeScriptArgs = [mockModule.script, msg('add mock module ' + name)]. | ||
concat(mockModule.args); | ||
self.executeScript_.apply(self, executeScriptArgs). | ||
then(null, function(err) { | ||
throw 'Error while running module script ' + name + | ||
': ' + err.message; | ||
}) | ||
.then(null, deferred.reject); | ||
} | ||
self.executeScript_( | ||
'angular.resumeBootstrap(arguments[0]);', | ||
msg('resume bootstrap'), | ||
moduleNames) | ||
.then(null, deferred.reject); | ||
} else { | ||
// TODO: support mock modules in Angular2. For now, error if someone | ||
// has tried to use one. | ||
if (self.mockModules_.length > 1) { | ||
deferred.reject('Trying to load mock modules on an Angular2 app ' + | ||
'is not yet supported.'); | ||
} | ||
} | ||
} | ||
this.executeScript_( | ||
'angular.resumeBootstrap(arguments[0]);', | ||
msg('resume bootstrap'), | ||
moduleNames) | ||
.then(null, deferred.reject); | ||
this.driver.controlFlow().execute(function() { | ||
@@ -662,0 +696,0 @@ return self.plugins_.onPageStable().then(function() { |
@@ -175,2 +175,4 @@ var protractor = require('./protractor'), | ||
* | ||
* @param {?Plugin} The plugin functions | ||
* | ||
* @return {Protractor} a protractor instance. | ||
@@ -187,3 +189,5 @@ * @public | ||
browser_.params = config.params; | ||
browser_.plugins_ = plugins; | ||
if (plugins) { | ||
browser_.plugins_ = plugins; | ||
} | ||
if (config.getPageTimeout) { | ||
@@ -198,2 +202,5 @@ browser_.getPageTimeout = config.getPageTimeout; | ||
} | ||
if (config.useAllAngular2AppRoots) { | ||
browser_.useAllAngular2AppRoots(); | ||
} | ||
var self = this; | ||
@@ -200,0 +207,0 @@ |
@@ -56,3 +56,3 @@ { | ||
"license": "MIT", | ||
"version": "2.4.0" | ||
"version": "2.5.0" | ||
} |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1864616
11987