0

I am capturing some values in runtime and would like to write them back into an existing excel file. Request your help in this aspect.

thank you

AdityaReddy
  • 3,625
  • 12
  • 25
suneel
  • 11
  • 1
  • 6

1 Answers1

1

You can use npm package - xlsx. There are lot of alternative options too. I have provided a simple example below to write the currentUrl() to an existing sheet which already contains a url

You can improvise on this to suit your needs

XLSX = require('xlsx');
describe('sample test', function(){
    var workbook;
    var worksheet;
    beforeAll(function _setupStart() {
        //Initialize workbook to read the existing excel assuming it has a sheet named 'urls'
        workbook = XLSX.readFile('test.xlsx');
        worksheet = workbook.Sheets['urls'];
    });
    it('Sample Check', function(){
        browser.get("http://www.protractortest.org/#/");
        browser.sleep(5000);
        browser.getCurrentUrl().then(function(valueUrl){
            //set the value here
            worksheet['A1'].v = valueUrl
        })
    });
    afterAll(function _finish() {
        //Write the changes back
        XLSX.writeFile(workbook, 'test.xlsx');
    });
});
AdityaReddy
  • 3,625
  • 12
  • 25