I'm working with protractor and I'm trying to implement data driven.
I'm using this code that I found searching in google.
This is my test.json
{
"username":"testusername"
}
And i'm calling this json from my spec and trying to print in console:
var fs = require('fs');
var content = fs.readFileSync('test/e2e/tests/test.json');
console.log(content.username);
The test is not failing but in the console is print undefined
I'm missing something? or i'm not implementing well the json? Hope you can help me.
You just need to do require(json_file_path). It will work. Try below code.
var content = require('test/e2e/tests/test.json');
console.log(content.username);