I'm having an issue with using IT block inside a loop. The loop basically comes from the returned Promise, an exceljs module that reads data from an excel file.
Here' is the promise function.
var excelJs = require('exceljs');
var Excel = browser.params.Excel;
this.createProfile = function() {
var arr = [];
return new Promise(function(fulfill, reject){
var workbook = new excelJs.Workbook();
workbook.xlsx.readFile(Excel.filePath).then(function(){
worksheet = workbook.getWorksheet(1);
worksheet.eachRow({includeEmpty: true}, function(row, rowNumber)
try {
if (rowNumber != 1) {
arr.push(row.values);
fulfill(arr);
}
} catch(ex){reject(ex);}
}, reject);
});
});
};
And here is how I did to call inside a spec file.
describe('Bulk Purchase', function(){
var cp = createProfile();
cp.then(function(data){
for (var i in data){
it('Automate School Supplies Purchase', function(done){
console.log('Ballpen: ' + data[i][1]);
console.log('Notebook: ' + data[i][2]); //etc
done();
});
}
})
});
The spec will display the expected values if I removed the IT block from the code. Can somebody enlighten me on why would a simple IT block inside a promise would not work? Any help will be appreciated thank you :)
I have a workaround on this, if I converted the Excel to JSON, and require the json file and do the forEach, then I can easily do the data-driven automated test. But I would prefer not to move from other source file to fulfill my original approach.
// where I used xlsx-to-json npm to convert my excel to json
var jsonData = require('path to converted excel to json file');
jsonData.forEach(function(data){
it('Automate School Supplies Purchase', function(){
console.log(data.Ballpen);
console.log(data.Notebook); //etc
})
});