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

Commit

Permalink
feat(config): no globals option
Browse files Browse the repository at this point in the history
  • Loading branch information
cnishina committed Mar 2, 2016
1 parent a79fd29 commit 1cbbe4f
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 8 deletions.
8 changes: 8 additions & 0 deletions docs/referenceConf.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ exports.config = {
// ----- What tests to run ---------------------------------------------------
// ---------------------------------------------------------------------------

// Use default globals: 'protractor', 'brower', '$', '$$', 'element', 'by'.
// These also exist as properties of the protractor namespace:
// 'protractor.browser', 'protractor.$', 'protractor.$$', 'protractor.element',
// 'protractor.by', and 'protractor.By'.
// When no globals is set to true, the only available global variable will be
// 'protractor'.
noGlobals: false,

// Spec patterns are relative to the location of this config.
specs: [
'spec/*_spec.js'
Expand Down
2 changes: 2 additions & 0 deletions lib/configParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export interface Config {
mochaOpts: {ui: string; reporter: string;};
chromeDriver?: string;
configDir: string;
noGlobals: boolean;
plugins: Array<any>;
skipSourceMapSupport: boolean;
suite?: string;
Expand All @@ -56,6 +57,7 @@ export default class ConfigParser {
seleniumArgs: [],
mochaOpts: {ui: 'bdd', reporter: 'list'},
configDir: './',
noGlobals: false,
plugins: [],
skipSourceMapSupport: false,
};
Expand Down
25 changes: 19 additions & 6 deletions lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,26 @@ Runner.prototype.controlFlow = function() {
* @private
*/
Runner.prototype.setupGlobals_ = function(browser_) {
// Export protractor to the global namespace to be used in tests.

// Keep $, $$, element, and by/By under the global protractor namespace
protractor.browser = browser_;
protractor.$ = browser_.$;
protractor.$$ = browser_.$$;
protractor.element = browser_.element;
protractor.by = protractor.By = protractor.By;

if (!this.config_.noGlobals) {
// Export protractor to the global namespace to be used in tests.
global.browser = browser_;
global.$ = browser_.$;
global.$$ = browser_.$$;
global.element = browser_.element;
global.by = global.By = protractor.By;
}

global.protractor = protractor;
global.browser = browser_;
global.$ = browser_.$;
global.$$ = browser_.$$;
global.element = browser_.element;
global.by = global.By = protractor.By;



if (!this.config_.skipSourceMapSupport) {
// Enable sourcemap support for stack traces.
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@
"gulp": "^3.9.1",
"gulp-clang-format": "^1.0.23",
"jshint": "2.9.1",
"lodash": "^2.4.1",
"lodash": "^4.5.1",
"marked": "^0.3.3",
"mocha": "2.3.4",
"rimraf": "~2.5.0",
"run-sequence": "^1.1.5",
"typescript": "~1.8.0",
"typescript": "1.8.2",
"typings": "~0.6.6"
},
"repository": {
Expand Down
1 change: 1 addition & 0 deletions scripts/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ var passingTests = [
'node built/cli.js spec/getCapabilitiesConf.js',
'node built/cli.js spec/controlLockConf.js',
'node built/cli.js spec/customFramework.js',
'node built/cli.js spec/noGlobalsConf.js',
'node built/cli.js spec/angular2Conf.js',
'node scripts/attachSession.js',
'node scripts/interactive_tests/interactive_test.js',
Expand Down
30 changes: 30 additions & 0 deletions spec/noGlobals/noGlobals_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
describe('configuration with no globals', function() {
var URL = '/ng2/#/async';

it('should have objects belonging to protractor namespace', function() {
expect(typeof protractor).toEqual('object');
expect(typeof protractor.browser).toEqual('object');
expect(typeof protractor.$).toEqual('function');
expect(typeof protractor.$$).toEqual('function');
expect(typeof protractor.element).toEqual('function');
expect(typeof protractor.by).toEqual('object');
expect(typeof protractor.By).toEqual('object');
});

it('should not have other globals', function() {
expect(typeof browser).toEqual('undefined');
expect(typeof $).toEqual('undefined');
expect(typeof $$).toEqual('undefined');
expect(typeof element).toEqual('undefined');
expect(typeof by).toEqual('undefined');
expect(typeof By).toEqual('undefined');
});

it('should be able to use methods under the protractor namespace', function() {
protractor.browser.get(URL);
var increment = protractor.$('#increment');
expect(typeof increment).toEqual('object');
increment.$('.action').click();
expect(increment.$('.val').getText()).toEqual('1');
});
});
21 changes: 21 additions & 0 deletions spec/noGlobalsConf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
var env = require('./environment');

// This is the configuration for a smoke test for an Angular2 application.
exports.config = {

seleniumAddress: env.seleniumAddress,

framework: 'jasmine',

specs: [
'noGlobals/noGlobals_spec.js'
],

noGlobals: true,

capabilities: env.capabilities,

baseUrl: env.baseUrl,

useAllAngular2AppRoots: true
};

0 comments on commit 1cbbe4f

Please sign in to comment.