简体   繁体   English

量角器:如何使配置文件更灵活?

[英]Protractor: how to make the configuration file more flexible?

I have an idea to make my configs more flexible. 我有一个想法让我的配置更灵活。 For example I have 10000 config files with same parameters: 例如,我有10000个具有相同参数的配置文件:

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. 一旦我想改变规格,html或更改selenium地址的路径。 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? 或者可能存在另一种有趣的方法来解决这个问题?

You can export your common config rules as node.js module: 您可以将常用配置规则导出为node.js模块:

// 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;

With @driver_by help I found nice solution for my problem. 有了@driver_by帮助,我找到了解决问题的好方法。 Now my files isolated. 现在我的文件被隔离。 If I want to change url or path to folder I should change only global config. 如果我想更改url或路径到文件夹,我应该只更改全局配置。

// 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;  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM