npm protractor xlsx file wait and retry

I am trying to run protractor with multi capabilities (around 30 browsers with diff versions) The data sheet is xlsx and is one sheet, which will be consumed. After each run the xlsx row will be updated that it has been 'USED'

I use exceljs to write the flag. But it throws error if its already been used/opened by another process. I handled the exception, but instead of failing , i would like the muti processes to wait and retry accessing the file.

Please suggest how to read/write one xlsx at same time by multiple processes - where the processed has to wait for any previous process to complete its access.

Write Function:

updateRunnerXLS: function(fileName) {
    var Excel = require('exceljs'); //Require the exceljs package
    var workbook = new Excel.Workbook(); //create a workbook reader
    .then(function(workbook) {
        var rowValues = []; //initialize empty array
        var worksheet = workbook.getWorksheet('sheet2');
        var nameCol = worksheet.getColumn('M');
        nameCol.eachCell(function(cell, rowNumber) { //Loop through the cells
            if (cell.value == 'Y') { //get all rows with Y
                rowValues.push(rowNumber); //Fill the array with row number
         var row = worksheet.getRow(rowValues[0]); //Get the first row from the array
        row.getCell('M').value = 'X'; //update the first row that has a  Y to X
        row.commit(); //Commit the row change
        workbook.xlsx.writeFile(fileName).then(function() {
        }).catch(function (err) {
            console.log('Handled the error - ' + err);

Read Function: (simpler that reading using exceljs)

var Parser = require('parse-xlsx');
sheet = new Parser(testDataFolder + 'dataSheet.xlsx', 'sheet2');



Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.