Saturday, November 2, 2019

Data Driven Testing With JSON File Using Protractor



Step 1:

Create a JSON file which holds the data like below


[{
    "data":"Test Data 1"
},
{
    "data":"Test Data 2"
}]


Step 2:



import the json file in our script using the below code


var data = require('../Data/testdata.json')

Complete code example is given below:


var data = require('../Data/testdata.json')
describe("Test Suite",function(){
    
      let googlePage = require('../pages/google_home.js');
    
    beforeEach(function(){
        browser.ignoreSynchronization = true;
        browser.get(browser.baseUrl)
        
    })
    data.forEach(singleData => {
        it("Test1"function(){
            googlePage.enterSearch(singleData.data)
            console.log(singleData.data)
            browser.sleep(5000)
            expect(googlePage.getSearchTxt()).toEqual("fdfdhsdfhsadjhsdgfhdsgf")
        })
    });
    
});


No comments:

Post a Comment