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

Commit

Permalink
fix(hybrid): add flag specifying that an app is an ng1/ng2 hybrid (#3403
Browse files Browse the repository at this point in the history
)

Needed for angular2 after rc2
  • Loading branch information
sjelin authored and cnishina committed Jul 25, 2016
1 parent 2a3a0dc commit 71532f0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
15 changes: 13 additions & 2 deletions lib/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,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 comment has been minimized.

Copy link
@juliemr

juliemr Aug 3, 2016

Member

We should also allow changing this via the config file.


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

Expand Down Expand Up @@ -277,6 +286,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 @@ -419,7 +429,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 @@ -759,7 +770,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;

This comment has been minimized.

Copy link
@juliemr

juliemr Aug 3, 2016

Member

How is this working with this? Inside a Jasmine test, that's the test context object - shouldn't we be changing the setting on browser?

browser.get('/hybrid');
});

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

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

0 comments on commit 71532f0

Please sign in to comment.