2017-07-05 70 views
0

我有端到端測試使用茉莉和行爲驅動的測試編寫使用chai和黃瓜編寫的測試。我有兩個配置文件來運行這些測試。我如何使用單量角器配置文件來運行茉莉花和黃瓜的規格?量角器配置文件使用茉莉和黃瓜規格

//cucumber.conf.js 
exports.config = { 
    framework: 'custom', 
    frameworkPath: require.resolve('protractor-cucumber-framework'), 
    seleniumAddress: 'http://localhost:4444/wd/hub', 
    specs: ['test/e2e/cucumber/*.feature'], 
    capabilities: { 
    'browserName': 'firefox', 

}, 
baseUrl: '', 

    cucumberOpts: { 
    require: ['test/e2e/cucumber/*.steps.js'], 
    tags: [],      
    strict: true,     
    format: ["pretty"],    
    dryRun: false,     
    compiler: []     
    } 

    //e2e.conf.js 
    exports.config = { 
     framework: 'jasmine2',  
    seleniumAddress: 'http://localhost:4444/wd/hub', 

     specs: ['test/e2e/e2e-spec.js'], 
     capabilities: { 
     'browserName': 'firefox', 
    }, 
    baseUrl: '', 
     jasmineNodeOpts: { 
     showColors: true, 
    } 

回答

1

在你可以因爲你不需要提供例如框架,你不能有1 默認配置文件2個框架基本建立。

你可以做的是使用一個命令行參數和一個cli工具,如yargs,並做這樣的事情。如果通過例如npm script運行量角器,你可以做這樣的事情

npm run e2e -- --bdd

// the commmand line tool 
 
const argv = require('yargs').argv; 
 

 
// place you default config here, that should hold all the configs that are used with 
 
// Jsasmine and CucumberJS 
 
const config = { 
 
    baseUrl: '', 
 
    capabilities: { 
 
    'browserName': 'firefox', 
 

 
    }, 
 
    seleniumAddress: 'http://localhost:4444/wd/hub' 
 
}; 
 

 
// If you pass --bdd to your commandline it will use cucumberjs, default is jasmine 2 
 
if (argv.bdd) { 
 
    config.framework = 'custom'; 
 
    config.frameworkPath = require.resolve('protractor-cucumber-framework'); 
 
    config.specs = ['test/e2e/cucumber/*.feature']; 
 
    config.cucumberOpts = { 
 
    require: ['test/e2e/cucumber/*.steps.js'], 
 
    tags: [], 
 
    strict: true, 
 
    format: ["pretty"], 
 
    dryRun: false, 
 
    compiler: [] 
 
    }; 
 
} else { 
 
    config.framework = 'jasmine2'; 
 
    config.specs = ['test/e2e/e2e-spec.js']; 
 
    config.jasmineNodeOpts = { 
 
    showColors: true, 
 
    }; 
 
} 
 

 
exports.config = config;

+0

好感謝了很多。我會嘗試這個解決方案。 – Mythri