0

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.

2
  • Possible duplicate of Reading Excel file using node.js Commented 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 stuck Commented Mar 15, 2017 at 6:56

1 Answer 1

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

enter image description here

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);
       });
 });
Sign up to request clarification or add additional context in comments.

1 Comment

excel-as-json, doesn't take the relative path of testdata workbook

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.