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

Commit eb9d567

Browse files
elgalujuliemr
authored andcommitted
feat(frameworks): add support for custom frameworks
Usage: ```js exports.config = { framework: 'custom', frameworkPath: '/path/to/your/framework/index.js' } ```
1 parent 3880b27 commit eb9d567

File tree

9 files changed

+82
-2
lines changed

9 files changed

+82
-2
lines changed

docs/referenceConf.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,15 @@ exports.config = {
244244
// ----- The test framework --------------------------------------------------
245245
// ---------------------------------------------------------------------------
246246

247-
// Test framework to use. This may be jasmine, jasmine2, cucumber, or mocha.
247+
// Test framework to use. This may be one of:
248+
// jasmine, jasmine2, cucumber, mocha or custom.
249+
//
250+
// When the framework is set to "custom" you'll need to additionally
251+
// set frameworkPath with the path relative to the config file or absolute
252+
// framework: 'custom',
253+
// frameworkPath: './frameworks/my_custom_jasmine.js',
254+
// See github.com/angular/protractor/blob/master/lib/frameworks/README.md
255+
// to comply with the interface details of your custom implementation.
248256
//
249257
// Jasmine is fully supported as a test and assertion framework.
250258
// Mocha and Cucumber have limited beta support. You will need to include your

lib/configParser.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ ConfigParser.getSpecs = function(config) {
146146
ConfigParser.prototype.addConfig_ = function(additionalConfig, relativeTo) {
147147
// All filepaths should be kept relative to the current config location.
148148
// This will not affect absolute paths.
149-
['seleniumServerJar', 'chromeDriver', 'onPrepare', 'firefoxPath'].
149+
['seleniumServerJar', 'chromeDriver', 'onPrepare', 'firefoxPath',
150+
'frameworkPath'].
150151
forEach(function(name) {
151152
if (additionalConfig[name] &&
152153
typeof additionalConfig[name] === 'string') {

lib/frameworks/README.md

+21
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,24 @@ Requirements
3636
duration: integer
3737
}]
3838
```
39+
40+
Custom Frameworks
41+
-----------------
42+
43+
If you have created/adapted a custom framework and want it added to
44+
Protractor core please send a PR so it can evaluated for addition as an
45+
official supported framework. In the meantime you can instruct Protractor
46+
to use your own framework via the config file:
47+
48+
```js
49+
exports.config = {
50+
// set to "custom" instead of jasmine/jasmine2/mocha/cucumber.
51+
framework: 'custom',
52+
// path relative to the current config file
53+
frameworkPath: './frameworks/my_custom_jasmine.js',
54+
};
55+
```
56+
57+
More on this at [referenceConf](../../docs/referenceConf.js) "The test framework" section.
58+
59+
**Disclaimer**: current framework interface can change without a major version bump.

lib/runner.js

+6
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,12 @@ Runner.prototype.run = function() {
286286
} else if (self.config_.framework === 'explorer') {
287287
// Private framework. Do not use.
288288
frameworkPath = './frameworks/explorer.js';
289+
} else if (self.config_.framework === 'custom') {
290+
if (!self.config_.frameworkPath) {
291+
throw new Error('When config.framework is custom, ' +
292+
'config.frameworkPath is required.');
293+
}
294+
frameworkPath = self.config_.frameworkPath;
289295
} else {
290296
throw new Error('config.framework (' + self.config_.framework +
291297
') is not a valid framework.');

scripts/test.js

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ var passingTests = [
2727
'node lib/cli.js spec/restartBrowserBetweenTestsConf.js',
2828
'node lib/cli.js spec/getCapabilitiesConf.js',
2929
'node lib/cli.js spec/controlLockConf.js',
30+
'node lib/cli.js spec/customFramework.js',
3031
'node node_modules/.bin/jasmine JASMINE_CONFIG_PATH=scripts/unit_test.json'
3132
];
3233

spec/custom/framework.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* Jasmine framework dummy alias to prove Protractor supports
3+
* external custom frameworks.
4+
*
5+
* @param {Runner} runner The current Protractor Runner.
6+
* @param {Array} specs Array of Directory Path Strings.
7+
* @return {q.Promise} Promise resolved with the test results
8+
*/
9+
exports.run = require('../../lib/frameworks/jasmine.js').run;

spec/custom/smoke_spec.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
describe('smoke jasmine tests', function() {
2+
it('should do some dummy test', function() {
3+
expect(1).toBe(1);
4+
});
5+
});

spec/customFramework.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
var env = require('./environment.js');
2+
3+
exports.config = {
4+
seleniumAddress: env.seleniumAddress,
5+
6+
framework: 'custom',
7+
frameworkPath: './custom/framework.js',
8+
9+
specs: [
10+
'custom/smoke_spec.js'
11+
],
12+
13+
capabilities: env.capabilities,
14+
15+
baseUrl: env.baseUrl,
16+
};

spec/unit/runner_test.js

+13
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,17 @@ describe('the Protractor runner', function() {
4646
runner.run();
4747
}).toThrow();
4848
});
49+
50+
it('should fail when no custom framework is defined', function(done) {
51+
var config = {
52+
mockSelenium: true,
53+
specs: ['*.js'],
54+
framework: 'custom'
55+
};
56+
57+
var runner = new Runner(config);
58+
runner.run().then(function() {
59+
done.fail('expected error when no custom framework is defined');
60+
}, done);
61+
});
4962
});

0 commit comments

Comments
 (0)