javascript - 维护 GlobalProtractorConf 和多个配置文件

标签 javascript protractor

在我的项目中,我创建了一个 protractor.config.js 文件并使用 grunt 驱动它。我想要一个 globalProtractor.conf 和多个 config.js 并将它们像子conf一样维护,以执行不同的测试套件并跳过诸如 Onprepare 函数之类的常见内容或所有conf中的多个容量或全局变量。

在我的 globalprotractor.conf 中,我有

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

我需要在子conf中覆盖它。有什么具体的方法吗?

最佳答案

这是一个很好的问题,我想这在大型测试项目中是一个相当合理的要求。我想出了以下方法。让我知道这是否有效!!

在一处拥有全局配置 - 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;

关于javascript - 维护 GlobalProtractorConf 和多个配置文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43101820/

相关文章:

javascript - 套件与规范 Protractor

javascript - 用 Protractor 获取伪元素的值

javascript - 在 Gulp AngularJS 应用程序中实现 Google 翻译

javascript - 在javascript中没有对象引用的情况下将对象数组复制到另一个数组(深层复制)

javascript - 单击按钮时如何更新 fullcalendar 5 中的事件?

angular - 防止 Protractor 编译 Angular 代码

angularjs - 如何将变量从浏览器传递到 Protractor

javascript - JS 配对游戏随机化除最后一张牌以外的所有牌

javascript - 如何使用CKeditor允许所有html标签和属性?

selenium - Chrome : fake microphone input for test purpose