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.
-
Possible duplicate of Reading Excel file using node.jsAdityaReddy– AdityaReddy2017-03-15 06:55:50 +00:00Commented Mar 15, 2017 at 6:55
-
Also a good way of posting question on SO is to tell what you googled,tried and where you are stuckAdityaReddy– AdityaReddy2017-03-15 06:56:52 +00:00Commented Mar 15, 2017 at 6:56
Add a comment
|
1 Answer
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);
});
});
1 Comment
zishan paya
excel-as-json, doesn't take the relative path of testdata workbook
