TestCafe 中使用 JSON 的数据驱动测试能否与每个测试具有多个属性的 JSON 一起工作?
Can Data Driven tests in TestCafe using JSON work with JSON having multiple attributes for each test?
到目前为止,基于此示例,我已经在 testcafe 中编写了大量数据驱动测试。
https://devexpress.github.io/testcafe/documentation/recipes/create-data-driven-tests.html
有没有人尝试过使用 JSON 文件进行 JSON 数据驱动测试 w/testcafe,如下例?
[
{
"testcasename": "Check for Rate Classes -1",
"rateclasses": "{
"classname": "SC",
"classvalue": 1
}
},
]
这是我用来遍历 JSON 文件的代码。现在我的困境是能不能写一个多层次的数据集例程?
dataSet.forEach(userdata => {
test(`Enter '${userdata.testcasename}'`, async t => {
my code here
});
});
会不会像
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
}
});
});
任何指示都会有所帮助。
更新
发现构造需要像这样工作:
[
{
"testcasename": "Check for Rate Classes -1",
"rateclasses": " [
{
"classname": "SC",
"classvalue": 1
}
]
}
]
您需要使用正确的 JSON syntax 进行多级数据测试,正如您在更新部分中提到的那样设置。
您还可以使用 JSON.stringify 方法查看现有对象如何转换为 JSON 格式。
我是这样解决问题的:
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)
}
});
});
到目前为止,基于此示例,我已经在 testcafe 中编写了大量数据驱动测试。
https://devexpress.github.io/testcafe/documentation/recipes/create-data-driven-tests.html
有没有人尝试过使用 JSON 文件进行 JSON 数据驱动测试 w/testcafe,如下例?
[
{
"testcasename": "Check for Rate Classes -1",
"rateclasses": "{
"classname": "SC",
"classvalue": 1
}
},
]
这是我用来遍历 JSON 文件的代码。现在我的困境是能不能写一个多层次的数据集例程?
dataSet.forEach(userdata => {
test(`Enter '${userdata.testcasename}'`, async t => {
my code here
});
});
会不会像
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
}
});
});
任何指示都会有所帮助。
更新
发现构造需要像这样工作:
[
{
"testcasename": "Check for Rate Classes -1",
"rateclasses": " [
{
"classname": "SC",
"classvalue": 1
}
]
}
]
您需要使用正确的 JSON syntax 进行多级数据测试,正如您在更新部分中提到的那样设置。
您还可以使用 JSON.stringify 方法查看现有对象如何转换为 JSON 格式。
我是这样解决问题的:
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)
}
});
});