Microsoft Excel ( Please don’t hate! Excel is one of the most suitable tools for the person who isn’t a programmer to write the specification! And they like that very much. )
Now, I’ll explain by entries of the following series.
How to generate data structure from Microsoft Excel.
Basis of WebdriverIO
How to make a End-to-End Testing by WebdriverIO and Microsoft Excel.
Can I execute multiple scenarios which make by multiple sheets of Excel? Yes we can!
Let’s try BDD!
So, in this entry, I’ll explain “How to generate data structure from Microsoft Excel”.
xlxs package is a very useful and strong for the purpose.
Parser and writer for various spreadsheet formats. Pure-JS cleanroom implementation from official specifications, related documents, and test files. Emphasis on parsing and writing robustness, cross-format feature compatibility with a unified JS representation, and ES3/ES5 browser compatibility back to IE6.
A one of the reason which I choose Node.js is that it can use xlsx.
install xlsx package
$ npm install xlsx
read xlsx file and convert to JSON
It’s very simple.
const xlsx = require('xlsx');
const utils = xlsx.utils;
const specification_xlsx_path = './specification.xlsx';
let workbook = xlsx.readFile(specification_xlsx_path);
let worksheet = workbook.Sheets['data'];
let json = utils.sheet_to_json(worksheet);