In this article I would like to share knowledge regarding Data driven testing.
When using a Data driven automation test framework, we do not need to hard code the test data. Instead it enables to access the test data from a separate data file and use them in the automated test cases.
First, let's take a look at a simple Protractor script without Data Driven framework
describe('Angular home page', function () {
it('should add the String in todo list ', function () {
browser.get('https://angularjs.org/');
element.all(by.css("[placeholder='add new todo here']")).sendKeys("Add POM");
element(by.css('input.btn-primary')).click();
var getText = element.all(by.css('label.checkbox'));
getText.get(2).getText().then(function (results) {
expect(results).toEqual("Add POM");
});
});
});
Now let's create a JSON file to store the user inputs dataInput.json as the first step of moving in to the data driven approach.it('should add the String in todo list ', function () {
browser.get('https://angularjs.org/');
element.all(by.css("[placeholder='add new todo here']")).sendKeys("Add POM");
element(by.css('input.btn-primary')).click();
var getText = element.all(by.css('label.checkbox'));
getText.get(2).getText().then(function (results) {
expect(results).toEqual("Add POM");
});
});
});
dataInput.json
{
"url":"https://angularjs.org/",
"sampleString": "Add POM"
}
Now we can use the above created JSON file simply via the require function by importing it in to the test script."url":"https://angularjs.org/",
"sampleString": "Add POM"
}
describe('Angular home page', function () {
var data = require(protractor.basePath + '/e2e-tests/blog/dataInput.json');
it('should add the String in todo list ', function () {
browser.get(data.url);
element.all(by.css("[placeholder='add new todo here']")).sendKeys(data.sampleString);
element(by.css('input.btn-primary')).click();
var getText = element.all(by.css('label.checkbox'));
getText.get(2).getText().then(function (results) {
expect(results).toEqual(data.sampleString);
});
});
});
The script can access the input values using parameters data.url and data.simpleString
var data = require(protractor.basePath + '/e2e-tests/blog/dataInput.json');
it('should add the String in todo list ', function () {
browser.get(data.url);
element.all(by.css("[placeholder='add new todo here']")).sendKeys(data.sampleString);
element(by.css('input.btn-primary')).click();
var getText = element.all(by.css('label.checkbox'));
getText.get(2).getText().then(function (results) {
expect(results).toEqual(data.sampleString);
});
});
});
Comments
Post a Comment