I want to add data to my protractor test from an excel\csv file. I can not find any simple\easy way to do that. my data is a list of first name and last name in excel which i need to create some user account.
Asked
Active
Viewed 5,208 times
0
-
Possible duplicate of [Reading Excel file using node.js](http://stackoverflow.com/questions/28860728/reading-excel-file-using-node-js) – AdityaReddy Mar 15 '17 at 06:55
-
Also a good way of posting question on SO is to tell what you googled,tried and where you are stuck – AdityaReddy Mar 15 '17 at 06:56
1 Answers
3
You need to use excel to json convertor. So make sure you write code for json
only as below.
So whether it is excel
or json
or input data will always be json
.
Reach back to me for any query.
test.json
file
[
{
"username": "user",
"passwordField": "pass12345"
}
]
book1.xlsx
file
Suppose your json
is stored under D:/node_modules/test.json
and excel
is at D:/node_modules/book1.xlsx
import {protractor,element,browser,$,$$, By,by,wrapDriver,ExpectedConditions} from 'protractor';
var convertExcel = require('excel-as-json').processFile;
convertExcel('D:/node_modules/book1.xlsx', 'D:/node_modules/book1.json');
describe ('Login Page Data Driven' , function() {
browser.ignoreSynchronization = true;
beforeEach(function(){
browser.ignoreSynchronization=true;
browser.get('url');
browser.driver.manage().window().maximize();
});
it('To verify Login, using Data Driven Technique from Json file', function(){
var testData = require('D:/node_modules/test.json');
var a = element(by.id("username"));
var b = element(by.id("password"));
a.sendKeys(testData[1].username);
b.sendKeys(testData[1].passwordField);
browser.sleep(1000);
});
it('To verify Login, using Data Driven Technique from Excel file', function(){
var testData1 = require('D:/node_modules/book1.json');
var a = element(by.id("username"));
var b = element(by.id("password"));
a.sendKeys(testData1[0].username);
b.sendKeys(testData1[0].passwordField);
browser.sleep(1000);
});
});

Kishan Patel
- 1,385
- 3
- 13
- 24
-
excel-as-json, doesn't take the relative path of testdata workbook – zishan paya Dec 07 '17 at 07:35