vendredi 3 juin 2016

automated testing of browser generated data export to csv file

A few years ago I asked SO about exporting javascript data to a csv file from the browser without server interaction and was rewarded by helpful answers from @adeneo and @Manu Sharma. These became the basis for a download feature in a library called html5csv.

Now I have split off this file generation functionality into a smaller npm module called csv-file-creator, and included nodejs capability along with IE/Firefox/Chrome.

A simple example is included in the csv-file-creator package that simulates 10000 random 6-sided-die rolls times and exports a table of results as a csv file. Testing is directed at verifying proper behavior of this example, i.e. that the file exists, has 10001 entries, etc.

I have a mocha unit test in nodejs, which after verifying the module example runs properly in nodejs, and will build with browserify, tries to run firefox on a mostly boilerplate index.html for a bundle created by browserify from the example and module code in the github repository, and looks like this:

/* browserify bundle file exists in example subdir when this runs */ describe('running example in firefox ', function(){ var error=0, mystderr=0; after(function(){ try { fs.unlinkSync(bundleFileName); } catch(e) {} }); before(function(done){ var firefox; try { fs.unlinkSync("./dicerolls.csv"); } catch(e){} var forceQuit = function(){ firefox.kill(); setTimeout(done, 5000); }; setTimeout(forceQuit, 10000); firefox = exec('cd ./example && firefox index.html', function(e, stdout, stderr){ error=e; mystderr=stderr; }); }); after(function(){ try { fs.unlinkSync("./dicerolls.csv"); } catch(e) {}; }); it('should run firefox without error', function(){ assert(!error, error+" "+mystderr); }); it('should create the file dicerolls.csv', function(){ fs.accessSync("./dicerolls.csv", fs.F_OK); }); });

On travis-ci I know firefox runs but does not make or find the file.

Travis CI Build #15 for csv-file-creator

Running "npm test" instead on a laptop, firefox runs, opens the example's index.html file and gets stuck on the file action modal dialogue box, whether to save the csv file or hand it over to an application.

How can I configure firefox to avoid this file action modal dialogue box for the purpose of automated testing, or, lacking that, use some other travis-ci facility to conduct a browser test of generating a specific .csv file?

Aucun commentaire:

Enregistrer un commentaire