Nightwatch tests to click download link and verify contents of csv

1,753 views
Skip to first unread message

Sunil Samuels

unread,
Dec 27, 2016, 2:16:39 PM12/27/16
to NightwatchJs

I have a download link on a webpage which downloads a csv file. This csv file contains 100+ columns with data (numeric, text, decimal etc). The values in csv are actually taken from the webpage entered by users, when user clicks save and clicks download link these values are downloaded to csv.

How do i write a nightwatch test which can validate all of these values from web page are downloaded to csv correctly? 

I have mapped all the values (that go into csv) from webpage into UI properties (such as cityName:'input[elementId]', stateName:'input[elementId]' ..so on).

I am looking for a way to perform below steps in my nightwatch tests:

Step1> Get all the values from the UI for ex: browser.getValue(cityName,function(textBoxValue){ var city=textBoxValue})

Step2> Trigger Click download link

Step3> Read the downloaded file from CSV and compare the value in csv with that of the value in UI - pass if the csv value and UI value match.


Any help would be of great use. Thanks in advance.

Sunil Samuels

unread,
Jan 6, 2017, 3:08:08 AM1/6/17
to NightwatchJs
Finally figured out the way to read a file from csv and compare the values in UI
used below:
const papa = require('papaparse');
const fs = require('fs');

..
..
fs.stat(localFilePath, function(err, stats){
if (!err) {
var fileContents = fs.readFileSync(localFilePath, 'utf8');
papa.parse(fileContents,{
complete:function(results){
city = results.data[1][1];
state = results.data[1][2];
done()
}
});
}
Reply all
Reply to author
Forward
0 new messages