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

Commit c869449

Browse files
committed
feat(hybrid): set ng12hybrid flag in the config
1 parent ffe96ee commit c869449

File tree

6 files changed

+36
-15
lines changed

6 files changed

+36
-15
lines changed

lib/browser.ts

+14-7
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,8 @@ export class ProtractorBrowser extends Webdriver {
252252

253253
constructor(
254254
webdriverInstance: webdriver.WebDriver, opt_baseUrl?: string,
255-
opt_rootElement?: string, opt_untrackOutstandingTimeouts?: boolean) {
255+
opt_rootElement?: string, opt_untrackOutstandingTimeouts?: boolean,
256+
opt_ng12Hybrid?: boolean) {
256257
super();
257258
// These functions should delegate to the webdriver instance, but should
258259
// wait for Angular to sync up before performing the action. This does not
@@ -286,7 +287,7 @@ export class ProtractorBrowser extends Webdriver {
286287
this.ready = null;
287288
this.plugins_ = new Plugins({});
288289
this.resetUrl = DEFAULT_RESET_URL;
289-
this.ng12Hybrid = false;
290+
this.ng12Hybrid = opt_ng12Hybrid;
290291

291292
this.driver.getCapabilities().then((caps: webdriver.Capabilities) => {
292293
// Internet Explorer does not accept data URLs, which are the default
@@ -901,7 +902,8 @@ export class ProtractorBrowser extends Webdriver {
901902
* browser.get('http://angular.github.io/protractor/#/api');
902903
* expect(browser.getLocationAbsUrl())
903904
* .toBe('http://angular.github.io/protractor/#/api');
904-
* @returns {webdriver.promise.Promise<string>} The current absolute url from AngularJS.
905+
* @returns {webdriver.promise.Promise<string>} The current absolute url from
906+
* AngularJS.
905907
*/
906908
getLocationAbsUrl(): webdriver.promise.Promise<any> {
907909
this.waitForAngular();
@@ -1236,15 +1238,20 @@ export class ProtractorBrowser extends Webdriver {
12361238
* Create a new instance of Browser by wrapping a webdriver instance.
12371239
*
12381240
* @param {webdriver.WebDriver} webdriver The configured webdriver instance.
1239-
* @param {string=} opt_baseUrl A URL to prepend to relative gets.
1240-
* @param {boolean=} opt_untrackOutstandingTimeouts Whether Browser should
1241+
* @param {string=} baseUrl A URL to prepend to relative gets.
1242+
* @param {string=} rootElement The
1243+
* @param {boolean=} untrackOutstandingTimeouts Whether Browser should
12411244
* stop tracking outstanding $timeouts.
1245+
* @param {boolean=} ng12Hybrid Whether Browser should interpret any apps it
1246+
* comes across as hybrid angular1/angular2 apps
12421247
* @returns {Browser} a new Browser instance
12431248
*/
12441249
static wrapDriver(
12451250
webdriver: webdriver.WebDriver, baseUrl?: string, rootElement?: string,
1246-
untrackOutstandingTimeouts?: boolean): ProtractorBrowser {
1251+
untrackOutstandingTimeouts?: boolean,
1252+
ng12Hybrid?: boolean): ProtractorBrowser {
12471253
return new ProtractorBrowser(
1248-
webdriver, baseUrl, rootElement, untrackOutstandingTimeouts);
1254+
webdriver, baseUrl, rootElement, untrackOutstandingTimeouts,
1255+
ng12Hybrid);
12491256
}
12501257
}

lib/config.ts

+9
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,15 @@ export interface Config {
552552
*/
553553
disableEnvironmentOverrides?: boolean;
554554

555+
/**
556+
* Tells Protractor to interpret any angular apps it comes across as hybrid
557+
* angular1/angular2 apps (i.e. apps using ngUpgrade)
558+
* Defaults to `false`
559+
*
560+
* @type {boolean}
561+
*/
562+
ng12Hybrid?: boolean;
563+
555564
seleniumArgs?: Array<any>;
556565
configDir?: string;
557566
troubleshoot?: boolean;

lib/configParser.ts

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export class ConfigParser {
4040
noGlobals: false,
4141
plugins: [],
4242
skipSourceMapSupport: false,
43+
ng12Hybrid: false
4344
};
4445
}
4546

lib/runner.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ export class Runner extends EventEmitter {
199199

200200
var browser_ = ProtractorBrowser.wrapDriver(
201201
driver, config.baseUrl, config.rootElement,
202-
config.untrackOutstandingTimeouts);
202+
config.untrackOutstandingTimeouts, config.ng12Hybrid);
203203

204204
browser_.params = config.params;
205205
if (plugins) {

spec/hybrid/async_spec.js

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
describe('async angular2 application', function() {
22
beforeEach(function() {
3-
this.ng12Hybrid = true;
43
browser.get('/hybrid');
54
});
65

7-
afterEach(function() {
8-
this.ng12Hybrid = false;
9-
});
10-
11-
it('should propertly load the page', function() {
6+
it('should set browser flag via config', function() {
7+
expect(browser.ng12Hybrid).toBe(true);
128
expect($('h1').getText()).toEqual('My App');
139
});
1410

@@ -28,4 +24,10 @@ describe('async angular2 application', function() {
2824
ng1Btn.click();
2925
expect(ng1Btn.getText()).toEqual('Click Count: 1');
3026
});
27+
28+
it('should use the flag on the browser object', function() {
29+
browser.ng12Hybrid = false;
30+
browser.get('/ng2'); // will time out if Protractor expects hybrid
31+
browser.ng12Hybrid = true;
32+
});
3133
});

spec/hybridConf.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,7 @@ exports.config = {
1414

1515
baseUrl: env.baseUrl,
1616

17-
rootElement: 'body'
17+
rootElement: 'body',
18+
19+
ng12Hybrid: true
1820
};

0 commit comments

Comments
 (0)