Protractor: how to make the config file more flexible?
I have an idea to make my configurations more flexible. For example, I have 10,000 config files with the same parameters:
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['C:/Users/Lilia.Sapurina/Desktop/Protractor Tests/Scenarios/ps-grid-column-filter-range_spec.js'],
params: {'url_filter': 'http://wks-15103:8010/ps/ng-components/examples/ps-grid-column-filter-range.html'}
And as soon as I want to change the spec path, html, or change the selenium address. Can I do this in a different file for all my configs?
For example, write in my config:
seleniumAddress: '../Variables/seleniumAdress.txt'
Or maybe there are other interesting ways to solve this problem?
+3
source to share
2 answers
You can export your general config rules as node.js module:
// globalProtractor.conf.js
module.exports = {
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['C:/Users/Lilia.Sapurina/Desktop/Protractor Tests/Scenarios/ps-grid-column-filter-range_spec.js'],
params: {
'url_filter': 'http://wks-15103:8010/ps/ng-components/examples/ps-grid-column-filter-range.html'
}
And use in another file
// protractor.conf.js
var globalConf = require('/path/to/globalProtractor.conf.js');
globalConf.specs.push('path/new.spec.js');
exports.config = globalConf;
+10
source to share
With @driver_by's help, I found a good solution for my problem. Now my files are isolated. If I want to change the url or folder path, I only have to change the global config.
// globalProtractor.conf.js
module.exports = {
seleniumAddress: 'http://localhost:4444/wd/hub',
baseUrl: 'http://wks-15103:8010/ps/ng-components/examples/',
specs: [],
path_to_scenario: '../Scenarios/',
path_to_spec: '../Specs/',
path_to_lib: '../Lib/'
}
And one more file:
// protractor.conf.js
var globalConf = require('../Global_configs/globalProtractor_conf.js');
globalConf.specs.push(path_to_spec + 'ps-grid-column-filter-range_spec.js');
globalConf.params = {'url_filter': 'ps-grid-column-filter-range.html',
'column_number_filter': 5,
'req_lib_filter': globalConf.path_to_lib + 'jasmine-expect'}
exports.config = globalConf;
+1
source to share