我试图用for子句循环测试,因为我想简单地从JSON外部文件(具有许多节点和子节点)中获取数据。 我收到“无测试可运行”错误。 我使用TestCafe 1.6.0和TestCafe Studio 1.1.0。
这里有一些示例代码:
import { t } from 'testcafe';
import {Selector} from 'testcafe';
import {Role} from 'testcafe';
import {helperFunc1,helperFunc2} from '../helper.js';
const fs = require('fs');
const path = require("path");
const fetch = require("node-fetch");
const rawdata = fs.readFileSync(path.resolve(__dirname,"../data.json"));
var data = JSON.parse(rawdata);
fixture `Test`
.page `http://www.testpage.com`
.beforeEach(t => t.resizeWindow(1920,1080))
for(var i = 0; i < data.jsonNode[i].length; i++)
{
test(`Test - 1`,async t => {await helperFunc1(data.jsonNode[i]);
test(`Test - 2`,async t => {await helperFunc2(data.jsonNode[i],"All","#HASH"); });
}
data.JSON示例
{
"jsonNode": [
{
"test1": "A","test2": "101","test3": "2","test4": "4"
},{
"test1": "B","test2": "102","test3": "3","test4": "5"
}],"jsonNode1": [
{
"test10": "A","test11": "101","test12": "2","test13": "4"
},{
"test10": "B","test11": "102","test12": "3","test13": "5"
}]
}