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

Commit 9def5e0

Browse files
crrobinson14juliemr
authored andcommitted
feat(runner): add browser.getProcessedConfig method
Now, instances of the `browser` object have a `getProcessedConfig` method which returns a promise that resolves to the current Protractor configuration object for the current runner instance. This means that if multiCapabilities are being used or tests are sharded, `getProcessedConfig` will return an object with the `capabilities` and `specs` property specific to the current instance. Closes #1724
1 parent 3f28110 commit 9def5e0

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

docs/referenceConf.js

+8
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,14 @@ exports.config = {
193193
// are using Jasmine, you can add a reporter with:
194194
// jasmine.getEnv().addReporter(new jasmine.JUnitXmlReporter(
195195
// 'outputdir/', true, true));
196+
//
197+
// If you need access back to the current configuration object,
198+
// use a pattern like the following:
199+
// browser.getProcessedConfig().then(function(config) {
200+
// // config.capabilities is the CURRENT capability being run, if
201+
// // you are using multiCapabilities.
202+
// console.log('Executing capability', config.capabilities);
203+
// });
196204
},
197205

198206
// A callback function called once tests are finished.

lib/runner.js

+11
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,17 @@ Runner.prototype.createBrowser = function() {
187187
}
188188
var self = this;
189189

190+
/**
191+
* Get the processed configuration object that is currently being run. This
192+
* will contain the specs and capabilities properties of the current runner
193+
* instance.
194+
*
195+
* @return {q.Promise} A promise which resolves to the capabilities object.
196+
*/
197+
browser_.getProcessedConfig = function() {
198+
return webdriver.promise.fulfilled(config);
199+
};
200+
190201
/**
191202
* Fork another instance of protractor for use in interactive tests.
192203
*

spec/basic/lib_spec.js

+20
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,26 @@ describe('protractor library', function() {
4444
expect(browser.driver.getCurrentUrl()).toMatch('#/form');
4545
});
4646

47+
it('should have access to the processed config block', function() {
48+
function containsMatching(arr, string) {
49+
var contains = false;
50+
for (var i = 0; i < arr.length; ++i) {
51+
if (arr[i].indexOf(string) !== -1) {
52+
contains = true;
53+
}
54+
}
55+
return contains;
56+
}
57+
58+
browser.getProcessedConfig().then(function(config) {
59+
expect(config.params.login).toBeDefined();
60+
expect(config.params.login.user).toEqual('Jane');
61+
expect(config.params.login.password).toEqual('1234');
62+
expect(containsMatching(config.specs, 'lib_spec.js')).toBe(true);
63+
expect(config.capabilities).toBeDefined();
64+
});
65+
});
66+
4767
it('should allow adding custom locators', function() {
4868
var findMenuItem = function() {
4969
var itemName = arguments[0];

0 commit comments

Comments
 (0)