Skip to content
This repository was archived by the owner on Jul 29, 2024. It is now read-only.

fix(hybrid): add flag specifying that an app is an ng1/ng2 hybrid #3403

Merged
merged 1 commit into from
Jul 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions lib/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,15 @@ export class Browser extends Webdriver {

debuggerValidated_: boolean;


/**
* If true, Protractor will interpret any angular apps it comes across as
* hybrid angular1/angular2 apps.
*
* @type {boolean}
*/
ng12Hybrid: boolean;

// This index type allows looking up methods by name so we can do mixins.
[key: string]: any;

Expand Down Expand Up @@ -276,6 +285,7 @@ export class Browser extends Webdriver {
this.ready = null;
this.plugins_ = new Plugins({});
this.resetUrl = DEFAULT_RESET_URL;
this.ng12Hybrid = false;

this.driver.getCapabilities().then((caps: webdriver.Capabilities) => {
// Internet Explorer does not accept data URLs, which are the default
Expand Down Expand Up @@ -418,7 +428,8 @@ export class Browser extends Webdriver {
} else if (this.rootEl) {
return this.executeAsyncScript_(
clientSideScripts.waitForAngular,
'Protractor.waitForAngular()' + description, this.rootEl);
'Protractor.waitForAngular()' + description, this.rootEl,
this.ng12Hybrid);
} else {
return this.executeAsyncScript_(
clientSideScripts.waitForAllAngular2,
Expand Down Expand Up @@ -758,7 +769,7 @@ export class Browser extends Webdriver {
// Make sure the page is an Angular page.
this.executeAsyncScript_(
clientSideScripts.testForAngular, msg('test for angular'),
Math.floor(timeout / 1000))
Math.floor(timeout / 1000), this.ng12Hybrid)
.then(
(angularTestResult: {ver: string, message: string}) => {
let angularVersion = angularTestResult.ver;
Expand Down
10 changes: 6 additions & 4 deletions lib/clientsidescripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,15 @@ function wrapWithHelpers(fun) {
* Asynchronous.
*
* @param {string} rootSelector The selector housing an ng-app
* @param {boolean} ng12Hybrid Flag set if app is a hybrid of angular 1 and 2
* @param {function(string)} callback callback. If a failure occurs, it will
* be passed as a parameter.
*/
functions.waitForAngular = function(rootSelector, callback) {
functions.waitForAngular = function(rootSelector, ng12Hybrid, callback) {
var el = document.querySelector(rootSelector);

try {
if (window.getAngularTestability) {
if (!ng12Hybrid && window.getAngularTestability) {
window.getAngularTestability(el).whenStable(callback);
return;
}
Expand Down Expand Up @@ -588,18 +589,19 @@ functions.findByCssContainingText = function(cssSelector, searchText, using) {
* Asynchronous.
*
* @param {number} attempts Number of times to retry.
* @param {boolean} ng12Hybrid Flag set if app is a hybrid of angular 1 and 2
* @param {function({version: ?number, message: ?string})} asyncCallback callback
*
*/
functions.testForAngular = function(attempts, asyncCallback) {
functions.testForAngular = function(attempts, ng12Hybrid, asyncCallback) {
var callback = function(args) {
setTimeout(function() {
asyncCallback(args);
}, 0);
};
var check = function(n) {
try {
if (window.getAllAngularTestabilities) {
if (!ng12Hybrid && window.getAllAngularTestabilities) {
callback({ver: 2});
} else if (window.angular && window.angular.resumeBootstrap) {
callback({ver: 1});
Expand Down
5 changes: 5 additions & 0 deletions spec/hybrid/async_spec.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
describe('async angular2 application', function() {
beforeEach(function() {
this.ng12Hybrid = true;
browser.get('/hybrid');
});

afterEach(function() {
this.ng12Hybrid = false;
});

it('should propertly load the page', function() {
expect($('h1').getText()).toEqual('My App');
});
Expand Down