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

Commit 1cbbe4f

Browse files
committed
feat(config): no globals option
1 parent a79fd29 commit 1cbbe4f

File tree

7 files changed

+83
-8
lines changed

7 files changed

+83
-8
lines changed

docs/referenceConf.js

+8
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,14 @@ exports.config = {
9797
// ----- What tests to run ---------------------------------------------------
9898
// ---------------------------------------------------------------------------
9999

100+
// Use default globals: 'protractor', 'brower', '$', '$$', 'element', 'by'.
101+
// These also exist as properties of the protractor namespace:
102+
// 'protractor.browser', 'protractor.$', 'protractor.$$', 'protractor.element',
103+
// 'protractor.by', and 'protractor.By'.
104+
// When no globals is set to true, the only available global variable will be
105+
// 'protractor'.
106+
noGlobals: false,
107+
100108
// Spec patterns are relative to the location of this config.
101109
specs: [
102110
'spec/*_spec.js'

lib/configParser.ts

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export interface Config {
3131
mochaOpts: {ui: string; reporter: string;};
3232
chromeDriver?: string;
3333
configDir: string;
34+
noGlobals: boolean;
3435
plugins: Array<any>;
3536
skipSourceMapSupport: boolean;
3637
suite?: string;
@@ -56,6 +57,7 @@ export default class ConfigParser {
5657
seleniumArgs: [],
5758
mochaOpts: {ui: 'bdd', reporter: 'list'},
5859
configDir: './',
60+
noGlobals: false,
5961
plugins: [],
6062
skipSourceMapSupport: false,
6163
};

lib/runner.js

+19-6
Original file line numberDiff line numberDiff line change
@@ -156,13 +156,26 @@ Runner.prototype.controlFlow = function() {
156156
* @private
157157
*/
158158
Runner.prototype.setupGlobals_ = function(browser_) {
159-
// Export protractor to the global namespace to be used in tests.
159+
160+
// Keep $, $$, element, and by/By under the global protractor namespace
161+
protractor.browser = browser_;
162+
protractor.$ = browser_.$;
163+
protractor.$$ = browser_.$$;
164+
protractor.element = browser_.element;
165+
protractor.by = protractor.By = protractor.By;
166+
167+
if (!this.config_.noGlobals) {
168+
// Export protractor to the global namespace to be used in tests.
169+
global.browser = browser_;
170+
global.$ = browser_.$;
171+
global.$$ = browser_.$$;
172+
global.element = browser_.element;
173+
global.by = global.By = protractor.By;
174+
}
175+
160176
global.protractor = protractor;
161-
global.browser = browser_;
162-
global.$ = browser_.$;
163-
global.$$ = browser_.$$;
164-
global.element = browser_.element;
165-
global.by = global.By = protractor.By;
177+
178+
166179

167180
if (!this.config_.skipSourceMapSupport) {
168181
// Enable sourcemap support for stack traces.

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@
3333
"gulp": "^3.9.1",
3434
"gulp-clang-format": "^1.0.23",
3535
"jshint": "2.9.1",
36-
"lodash": "^2.4.1",
36+
"lodash": "^4.5.1",
3737
"marked": "^0.3.3",
3838
"mocha": "2.3.4",
3939
"rimraf": "~2.5.0",
4040
"run-sequence": "^1.1.5",
41-
"typescript": "~1.8.0",
41+
"typescript": "1.8.2",
4242
"typings": "~0.6.6"
4343
},
4444
"repository": {

scripts/test.js

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ var passingTests = [
3131
'node built/cli.js spec/getCapabilitiesConf.js',
3232
'node built/cli.js spec/controlLockConf.js',
3333
'node built/cli.js spec/customFramework.js',
34+
'node built/cli.js spec/noGlobalsConf.js',
3435
'node built/cli.js spec/angular2Conf.js',
3536
'node scripts/attachSession.js',
3637
'node scripts/interactive_tests/interactive_test.js',

spec/noGlobals/noGlobals_spec.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
describe('configuration with no globals', function() {
2+
var URL = '/ng2/#/async';
3+
4+
it('should have objects belonging to protractor namespace', function() {
5+
expect(typeof protractor).toEqual('object');
6+
expect(typeof protractor.browser).toEqual('object');
7+
expect(typeof protractor.$).toEqual('function');
8+
expect(typeof protractor.$$).toEqual('function');
9+
expect(typeof protractor.element).toEqual('function');
10+
expect(typeof protractor.by).toEqual('object');
11+
expect(typeof protractor.By).toEqual('object');
12+
});
13+
14+
it('should not have other globals', function() {
15+
expect(typeof browser).toEqual('undefined');
16+
expect(typeof $).toEqual('undefined');
17+
expect(typeof $$).toEqual('undefined');
18+
expect(typeof element).toEqual('undefined');
19+
expect(typeof by).toEqual('undefined');
20+
expect(typeof By).toEqual('undefined');
21+
});
22+
23+
it('should be able to use methods under the protractor namespace', function() {
24+
protractor.browser.get(URL);
25+
var increment = protractor.$('#increment');
26+
expect(typeof increment).toEqual('object');
27+
increment.$('.action').click();
28+
expect(increment.$('.val').getText()).toEqual('1');
29+
});
30+
});

spec/noGlobalsConf.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
var env = require('./environment');
2+
3+
// This is the configuration for a smoke test for an Angular2 application.
4+
exports.config = {
5+
6+
seleniumAddress: env.seleniumAddress,
7+
8+
framework: 'jasmine',
9+
10+
specs: [
11+
'noGlobals/noGlobals_spec.js'
12+
],
13+
14+
noGlobals: true,
15+
16+
capabilities: env.capabilities,
17+
18+
baseUrl: env.baseUrl,
19+
20+
useAllAngular2AppRoots: true
21+
};

0 commit comments

Comments
 (0)