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

Commit 71532f0

Browse files
sjelincnishina
authored andcommitted
fix(hybrid): add flag specifying that an app is an ng1/ng2 hybrid (#3403)
Needed for angular2 after rc2
1 parent 2a3a0dc commit 71532f0

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

lib/browser.ts

+13-2
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,15 @@ export class Browser extends Webdriver {
238238

239239
debuggerValidated_: boolean;
240240

241+
242+
/**
243+
* If true, Protractor will interpret any angular apps it comes across as
244+
* hybrid angular1/angular2 apps.
245+
*
246+
* @type {boolean}
247+
*/
248+
ng12Hybrid: boolean;
249+
241250
// This index type allows looking up methods by name so we can do mixins.
242251
[key: string]: any;
243252

@@ -277,6 +286,7 @@ export class Browser extends Webdriver {
277286
this.ready = null;
278287
this.plugins_ = new Plugins({});
279288
this.resetUrl = DEFAULT_RESET_URL;
289+
this.ng12Hybrid = false;
280290

281291
this.driver.getCapabilities().then((caps: webdriver.Capabilities) => {
282292
// Internet Explorer does not accept data URLs, which are the default
@@ -419,7 +429,8 @@ export class Browser extends Webdriver {
419429
} else if (this.rootEl) {
420430
return this.executeAsyncScript_(
421431
clientSideScripts.waitForAngular,
422-
'Protractor.waitForAngular()' + description, this.rootEl);
432+
'Protractor.waitForAngular()' + description, this.rootEl,
433+
this.ng12Hybrid);
423434
} else {
424435
return this.executeAsyncScript_(
425436
clientSideScripts.waitForAllAngular2,
@@ -759,7 +770,7 @@ export class Browser extends Webdriver {
759770
// Make sure the page is an Angular page.
760771
this.executeAsyncScript_(
761772
clientSideScripts.testForAngular, msg('test for angular'),
762-
Math.floor(timeout / 1000))
773+
Math.floor(timeout / 1000), this.ng12Hybrid)
763774
.then(
764775
(angularTestResult: {ver: string, message: string}) => {
765776
let angularVersion = angularTestResult.ver;

lib/clientsidescripts.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,15 @@ function wrapWithHelpers(fun) {
4444
* Asynchronous.
4545
*
4646
* @param {string} rootSelector The selector housing an ng-app
47+
* @param {boolean} ng12Hybrid Flag set if app is a hybrid of angular 1 and 2
4748
* @param {function(string)} callback callback. If a failure occurs, it will
4849
* be passed as a parameter.
4950
*/
50-
functions.waitForAngular = function(rootSelector, callback) {
51+
functions.waitForAngular = function(rootSelector, ng12Hybrid, callback) {
5152
var el = document.querySelector(rootSelector);
5253

5354
try {
54-
if (window.getAngularTestability) {
55+
if (!ng12Hybrid && window.getAngularTestability) {
5556
window.getAngularTestability(el).whenStable(callback);
5657
return;
5758
}
@@ -588,18 +589,19 @@ functions.findByCssContainingText = function(cssSelector, searchText, using) {
588589
* Asynchronous.
589590
*
590591
* @param {number} attempts Number of times to retry.
592+
* @param {boolean} ng12Hybrid Flag set if app is a hybrid of angular 1 and 2
591593
* @param {function({version: ?number, message: ?string})} asyncCallback callback
592594
*
593595
*/
594-
functions.testForAngular = function(attempts, asyncCallback) {
596+
functions.testForAngular = function(attempts, ng12Hybrid, asyncCallback) {
595597
var callback = function(args) {
596598
setTimeout(function() {
597599
asyncCallback(args);
598600
}, 0);
599601
};
600602
var check = function(n) {
601603
try {
602-
if (window.getAllAngularTestabilities) {
604+
if (!ng12Hybrid && window.getAllAngularTestabilities) {
603605
callback({ver: 2});
604606
} else if (window.angular && window.angular.resumeBootstrap) {
605607
callback({ver: 1});

spec/hybrid/async_spec.js

+5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
describe('async angular2 application', function() {
22
beforeEach(function() {
3+
this.ng12Hybrid = true;
34
browser.get('/hybrid');
45
});
56

7+
afterEach(function() {
8+
this.ng12Hybrid = false;
9+
});
10+
611
it('should propertly load the page', function() {
712
expect($('h1').getText()).toEqual('My App');
813
});

0 commit comments

Comments
 (0)