I have plenty of data-driven tests already written in testcafe until now based on this example.
https://devexpress.github.io/testcafe/documentation/recipes/create-data-driven-tests.html
Has anyone attempted to do a JSON data-driven test w/testcafe with a JSON file like the sample below?
[
{
"testcasename": "Check for Rate Classes -1",
"rateclasses": "{
"classname": "SC",
"classvalue": 1
}
},
]
This is the code I use to iterate through the JSON file. Now my dilemma is can there be a multi-level data set routine written?
dataSet.forEach(userdata => {
test(`Enter '${userdata.testcasename}'`, async t => {
my code here
});
});
Would it look like
dataSet.forEach(userdata => {
test(`Enter '${userdata.testcasename}'`, async t => {
some code here for the 1st level attributes
dataSet.forEach(userdatasubattributes => {
some code here for the repeating attributes for each test case
}
});
});
Any pointers would be helpful.
UPDATE
found that the construct needs to work like this:
[
{
"testcasename": "Check for Rate Classes -1",
"rateclasses": " [
{
"classname": "SC",
"classvalue": 1
}
]
}
]
This is how I solved the problem:
dataSet.forEach(userdata => {
test(`Enter '${userdata.testcasename}'`, async t => {
for(let i = 0, l = userdata.rateclasses.length; i < l; i++) {
console.log ("Class Name", userdata.rateclasses[i].classname)
console.log ("Class Value", userdata.rateclasses[i].classvalue)
}
});
});