维护GlobalProtractorConf和多个配置文件

时间:2017-03-29 18:51:50

标签: javascript protractor

在我的项目中,我创建了一个protractor.config.js文件并用grunt驱动它。我希望有一个globalProtractor.conf和多个config.js并将它们维护成一个子conf,用于执行不同的测试套件并跳过常见的事情,例如On prepare prepare函数或多个容量或所有conf中的全局变量。

在我的globalprotractor.conf中,我有

seleniumAddress: {
         selenium: 'http:......'
     },

我需要在子conf中覆盖它。有没有具体的方法来做到这一点?

1 个答案:

答案 0 :(得分:1)

这是一个很好的问题,我想这对于大型测试项目来说是一个非常合理的要求。我提出了以下方法。如果有效,请告诉我!!

在一个地方进行全局配置 - globalConf.js

//Declare all your global configuration here which is common across all suites

var globalConf = {
    seleniumAddress: 'http://localhost:4444/wd/hub',
    localSeleniumStandaloneOpts: {
        jvmArgs: ["-Dwebdriver.ie.driver=C://IEDriverServer_x64_2.53.1.exe"] 
    },
    framework: 'jasmine',
    jasmineNodeOpts: {
        showColors: true,
        defaultTimeoutInterval: 120000,
        includeStackTrace: true,
        isVerbose: true,
    },
    capabilities: {
        browserName: 'chrome',
    },
    onPrepare: function () {
        browser.getProcessedConfig().then(function(data){
            console.log(data);
        });
    },
    allScriptsTimeout: 120000,
    getPageTimeout: 120000,
    afterLaunch: function (exitCode) {
    }
}   

//Export the global configuration to be called in local config files
module.exports = globalConf;

然后有多个conf文件将导入globalConf并具有特定于套件的更改

<强> conf1.js

//Import Global Configuration file
var globalConf = require('./globalConf.js');

//Clone the global configuration object. You can follow any cloning mechanism
var localConf = JSON.parse(JSON.stringify(globalConf));

//Make custom changes to suit your suite. May be add Suites or anything thats at suite level
localConf['specs'] = 'test.js';

// Set the value of exports.config based on
exports.config = localConf;

<强> conf2.js

//Import Global Configuration file
var globalConf = require('./globalConf.js');

//Clone the global configuration object. You can follow any cloning mechanism
var localConf = JSON.parse(JSON.stringify(globalConf));

//Make custom changes to suit your suite. May be add Suites or anything thats at suite level
localConf['specs'] = 'test2.js';

// Set the value of exports.config based on
exports.config = localConf;