我有一个使用meta标记的测试套件,我正在尝试运行特定的测试。
我尝试使用以下方法:
.filter((fixturePath, fixtureName, testMeta) => {
return testMeta.smoke == 'true';
})
runner.ts
const createTestCafe = require('testcafe');
let testcafe = null;
createTestCafe('localhost', 1337, 1338)
.then((tc) => {
testcafe = tc;
const runner = testcafe.createRunner();
return runner
.src(['tests/specs/**/*.spec.ts'])
.filter((fixturePath, fixtureName, testMeta) => {
return testMeta.smoke == 'true';
})
.browsers(['chrome'])
.reporter([
'list'
])
.run();
})
.then((failedCount) => {
console.log('Tests failed: ' + failedCount);
testcafe.close();
});
示例测试
test('Login with correct credentials', async (t) => {
await LoginPage.login(data.users.userPrivate.username, data.users.userPrivate.password);
await t.expect(Helper.getLocation()).contains(endpoints.personalAreaOverview);
}).meta('regression', 'true').meta('smoke', 'true');
预期:仅使用('smoke','true')
运行测试实际:Error: No tests to run. Either the test files contain no tests or the filter function is too restrictive.
答案 0 :(得分:2)
filter方法具有另一个参数顺序。您需要按以下步骤更改代码:
runner.ts
.filter((testName, fixtureName, fixturePath, testMeta, fixtureMeta) => {
return testMeta.smoke === 'true';
})