如何仅指定具有特定元标记的测试

amp*_*mpc 3 testing automated-tests node.js typescript testcafe

我有一个使用元标记的测试套件,我正在尝试运行特定的测试。

我尝试使用以下方法:

  .filter((fixturePath, fixtureName, testMeta) => {
    return testMeta.smoke == 'true';
  })
Run Code Online (Sandbox Code Playgroud)

跑步者.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.

mlo*_*sev 5

过滤器的方法还有另一个参数顺序。您需要按如下方式更改代码:

跑步者.ts

.filter((testName, fixtureName, fixturePath, testMeta, fixtureMeta) => {
    return testMeta.smoke === 'true';
})
Run Code Online (Sandbox Code Playgroud)