如何为不同的浏览器和测试套件参数化量角器配置文件 [英] how can Parametrize protractor-config file for different browsers and test suites

查看:42
本文介绍了如何为不同的浏览器和测试套件参数化量角器配置文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从命令 npm run e2e

我想要一种方法,如果我通过 npm run e2e firefox 那么我的测试将在 Firefox 浏览器上执行.

I want a way so that if I pass npm run e2e firefox then my test will get executed on Firefox browser.

或者如果我运行 npm run e2e chrome 那么它应该在 chrome 上运行

Or if I run npm run e2e chrome then it should run on chrome

如果我同时通过 npm run e2e firefox chrome 那么我的测试应该在两个浏览器上并行运行.

if I pass both npm run e2e firefox chrome then my test should run on both the browser in parallel.

是否可以参数化量角器配置文件?

Is it possible to parametrize protractor config file?

同样,如果我可以通过命令传递测试套件名称,并且它应该只在该特定测试套件下执行测试.

Similarly if I can pass test suite name via command and it should execute only tests under that particular test suite.

这是我的配置文件,这是我想要实现的:

Here is my config file and this is what I want to achieve:

`//var HtmlReporter = require('protractor-html-screenshot-reporter');

exports.config = {

allScriptsTimeout: 30000,
//Add parameters for browser names
params:{
  pass: {
      browserName : 'chrome',
      testSuitName : 'e2e/TestSuites/_BVT/*.js',
  }
 },  
suites: {    
//Define here List of Sanity Test Scenarios:
  BVT : testSuitName,   
}, 
// configure multiple browsers to run tests
multiCapabilities: [
 shardTestFiles: true,
 maxInstances: 2   
{'browserName': browserName}
],
baseUrl: 'http://mytestUrl/',
 framework: 'jasmine2',
jasmineNodeOpts: {
 defaultTimeoutInterval: 30000
},  
onPrepare: function() {  
var jasmineReporters = require('jasmine-reporters');
browser.driver.manage().window().maximize();
return browser.getProcessedConfig().then(function(config) {   
  var browserName = config.capabilities.browserName;
  var junitReporter = new jasmineReporters.JUnitXmlReporter({
         consolidateAll: true,
         savePath: 'tests/test-results',            
         filePrefix: browserName + '-xmloutput',
         modifySuiteName: function(generatedSuiteName, suite) {             
             return browserName + '.' + generatedSuiteName;
         }              
     });
     jasmine.getEnv().addReporter(junitReporter);
  });    
}, 
resultJsonOutputFile: 'tests/test-results/output.json'    
};`

希望对此有任何帮助.
提前致谢.

Would appreciate any help on this.
Thanks in advance.

推荐答案

我知道这个帖子现在有点老了,但这个解决方案可能会帮助有类似问题的人.

I know this post is a bit old now, but this solution may help people having a similar problem.

使用多个配置文件,每个浏览器类型一个,设置一个基本配置文件,并将其添加到其他每个配置文件中,然后为每个配置文件创建一个 npm 脚本.不需要参数,一切都很好.

Use multiple config files, one for each browser type, setup a base config file, and require that into each of the other config files, and then create an npm script for each config file. No need for parameters and everything stacks nicely.

所以基本配置(称为protractor_base.js"之类的东西)看起来像:

so the base config (called something like "protractor_base.js")would look something like:

exports.config = {
  seleniumAddress: 'http://localhost:4444/wd/hub',
  rootElement: '[ng-app]',

  allScriptsTimeout: 60000,

  framework: 'jasmine',

  specs: ['example-spec.js']
};

然后你的其他配置(即protractor_chrome.conf.js")看起来像:

And then your other configs (ie "protractor_chrome.conf.js") would look something like:

protractor = require('./protractor_base.js');
var config = protractor.config;

config.capabilities: {
  'browserName': 'chrome'
};


exports.config = config;

然后你可以指定一个多浏览器配置,只是一个 chrome 配置,等等.

You can then specify a multi browser config, just a chrome one, etc.

这篇关于如何为不同的浏览器和测试套件参数化量角器配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆