Protractor: how to make the configuration file more flexible?

痞子三分冷 提交于 2019-12-19 03:51:10

问题


I have an idea to make my configs more flexible. For example I have 10000 config files with 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 once I want to change path to specs, html or change selenium address. Can I do this in another file for all my configs?

For example write in my config:

seleniumAddress: '../Variables/seleniumAdress.txt'

Or maybe exist another interesting ways to solve this problem?


回答1:


You can export your common 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;



回答2:


With @driver_by help I found nice solution for my problem. Now my files isolated. If I want to change url or path to folder I should change only 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 another 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;  


来源:https://stackoverflow.com/questions/31532276/protractor-how-to-make-the-configuration-file-more-flexible

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!