到目前为止,根据此示例,我已经在testcafe中编写了很多数据驱动的测试。
https://devexpress.github.io/testcafe/documentation/recipes/create-data-driven-tests.html
有人尝试使用JSON文件像下面的示例一样通过w / testcafe进行JSON数据驱动的测试吗?
[
{
"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,该数据已在UPDATE部分中进行了设置。
您还可以使用JSON.stringify方法来查看现有对象如何转换为JSON格式。