If you find yourself needing to work with JSON data, consider the following scenario:
Imagine your JSON data for a login page includes fields for username and password, structured like this:
Here is an example of the JSON data:
[
{
"username": "kishan",
"password": "patel"
}
]
To incorporate this JSON data into your code and access it, follow these steps:
describe ('Login Page Data Driven' , function() {
browser.ignoreSynchronization = true;
beforeEach(function(){
browser.get('your url');
browser.driver.manage().window().maximize();
});
it('To verify Login, using Data Driven Technique from Json file', function()
{
var testData = require('D:/json path'); //this is the path where your json is stored
var user= element(by.id("username"));
var password = element(by.id("password"));
user.sendKeys(testData[0].username);
password.sendKeys(testData[0].password);
});
This example illustrates how to implement data-driven testing with JSON files. Feel free to try it out on your own and let me know if you have any questions.