我试图在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
但它不会覆盖配置文件中的实际规格
答案 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());
}
};