From 70834269ac375f2be5a6cadf8ec9169cf19abff6 Mon Sep 17 00:00:00 2001 From: Sammy Jelin Date: Wed, 26 Oct 2016 11:33:26 -0700 Subject: [PATCH] feat(hybrid): set ng12hybrid flag in the config (#3452) --- lib/browser.ts | 6 ++++-- lib/config.ts | 9 +++++++++ lib/configParser.ts | 1 + lib/runner.ts | 3 +++ spec/hybrid/async_spec.js | 16 ++++++++-------- spec/hybridConf.js | 4 +++- 6 files changed, 28 insertions(+), 11 deletions(-) diff --git a/lib/browser.ts b/lib/browser.ts index 4736fd91a..11ae6fb3d 100644 --- a/lib/browser.ts +++ b/lib/browser.ts @@ -1005,8 +1005,10 @@ export class ProtractorBrowser extends Webdriver { * Create a new instance of Browser by wrapping a webdriver instance. * * @param {webdriver.WebDriver} webdriver The configured webdriver instance. - * @param {string=} opt_baseUrl A URL to prepend to relative gets. - * @param {boolean=} opt_untrackOutstandingTimeouts Whether Browser should + * @param {string=} baseUrl A URL to prepend to relative gets. + * @param {string=} rootElement The css selector for the element which is the + * root of the Angular app. + * @param {boolean=} untrackOutstandingTimeouts Whether Browser should * stop tracking outstanding $timeouts. * @returns {Browser} a new Browser instance */ diff --git a/lib/config.ts b/lib/config.ts index 02d58001c..eb217cde0 100644 --- a/lib/config.ts +++ b/lib/config.ts @@ -567,6 +567,15 @@ export interface Config { */ disableEnvironmentOverrides?: boolean; + /** + * Tells Protractor to interpret any angular apps it comes across as hybrid + * angular1/angular2 apps (i.e. apps using ngUpgrade) + * Defaults to `false` + * + * @type {boolean} + */ + ng12Hybrid?: boolean; + seleniumArgs?: Array; configDir?: string; troubleshoot?: boolean; diff --git a/lib/configParser.ts b/lib/configParser.ts index 3dc36a45d..9f20f4c14 100644 --- a/lib/configParser.ts +++ b/lib/configParser.ts @@ -41,6 +41,7 @@ export class ConfigParser { noGlobals: false, plugins: [], skipSourceMapSupport: false, + ng12Hybrid: false }; } diff --git a/lib/runner.ts b/lib/runner.ts index 4b7fe8bec..0c2a535df 100644 --- a/lib/runner.ts +++ b/lib/runner.ts @@ -231,6 +231,9 @@ export class Runner extends EventEmitter { if (config.useAllAngular2AppRoots) { browser_.useAllAngular2AppRoots(); } + if (config.ng12Hybrid) { + browser_.ng12Hybrid = config.ng12Hybrid; + } browser_.ready = driver.manage().timeouts().setScriptTimeout(config.allScriptsTimeout); diff --git a/spec/hybrid/async_spec.js b/spec/hybrid/async_spec.js index 70b434721..90cd37a09 100644 --- a/spec/hybrid/async_spec.js +++ b/spec/hybrid/async_spec.js @@ -1,16 +1,10 @@ describe('async angular1/2 hybrid using ngUpgrade application', function() { beforeEach(function() { - browser.ng12Hybrid = true; - browser.get('/hybrid'); }); - afterEach(function() { - browser.ng12Hybrid = false; - }); - - it('should propertly load the page', function() { - expect($('h1').getText()).toEqual('My App'); + it('should set browser flag via config', function() { + expect(browser.ng12Hybrid).toBe(true); }); it('should be able to click buttons and wait for $timeout', function() { @@ -29,4 +23,10 @@ describe('async angular1/2 hybrid using ngUpgrade application', function() { ng1Btn.click(); expect(ng1Btn.getText()).toEqual('Click Count: 1'); }); + + it('should use the flag on the browser object', function() { + browser.ng12Hybrid = false; + browser.get('/ng2'); // will time out if Protractor expects hybrid + browser.ng12Hybrid = true; + }); }); diff --git a/spec/hybridConf.js b/spec/hybridConf.js index 848702f63..cdfb32a3f 100644 --- a/spec/hybridConf.js +++ b/spec/hybridConf.js @@ -14,5 +14,7 @@ exports.config = { baseUrl: env.baseUrl, - rootElement: 'body' + rootElement: 'body', + + ng12Hybrid: true };