我可以通过onprepare中的函数传递参数来覆盖量角器配置文件

时间:2019-03-26 00:54:41

标签: javascript angularjs testing jasmine protractor

我试图在onprepare状态下调用一个函数(promise),该函数将返回所有需要运行的测试的specs数组;我需要将其传递给配置文件中的规范

var Excel_Input = require('./Utility/Excel_Input.js');
var HtmlReporter = require('protractor-beautiful-reporter');
var specArray=[''];
exports.config = {
  seleniumAddress: 'http://localhost:4444/wd/hub',
  specs:specArray,
  allScriptsTimeout: 400000,
  getPageTimeout: 400000,
  jasmineNodeOpts: {
      defaultTimeoutInterval: 400000,
  },

      params: {
      },

  onPrepare: async function() {
      var excelData = new Excel_Input();
     await excelData.readFromExcel('dir','sheetName').then(function (result) { 
             specArray.push(result[0].specPath);
             console.log("spec Array: "+specArray); 
        });
       browser.manage().deleteAllCookies();
        jasmine.getEnv().addReporter(new HtmlReporter({
           baseDirectory: './../XO_Protractor_SOM/Reports/screenshots'
        }).getJasmine2Reporter());
     }
};

控制台显示:

spec Array: ,Progression/sampleTest.js

但它不会覆盖配置文件中的实际规格

1 个答案:

答案 0 :(得分:0)

将读取的excel代码块从onPrepare()移动到文件头。

var Excel_Input = require('./Utility/Excel_Input.js');
var HtmlReporter = require('protractor-beautiful-reporter');

var excelData = new Excel_Input();
var execSpecs= await excelData.readFromExcel('dir','sheetName');

var specArray=[''];
specArray.push(execSpecs[0].specPath);
console.log("spec Array: "+specArray); 

exports.config = {
  seleniumAddress: 'http://localhost:4444/wd/hub',
  specs:specArray,
  allScriptsTimeout: 400000,
  getPageTimeout: 400000,
  jasmineNodeOpts: {
      defaultTimeoutInterval: 400000,
  },

  params: {
  },

  onPrepare: function() {    
    browser.manage().deleteAllCookies();
    jasmine.getEnv().addReporter(new HtmlReporter({
       baseDirectory: './../XO_Protractor_SOM/Reports/screenshots'
    }).getJasmine2Reporter());
  }
};