TestCafe 'dynamic' 个测试用例

TestCafe 'dynamic' tests cases

我使用 TestCafe 为我当前的项目创建了一些端到端完整性测试。这些测试是标准的 TestCafe 测试:

fixture(`Basic checkout flow`)

test('Main Flow', async (t) => {

});

我想对多个站点区域设置和多个渠道执行此测试。即我需要此测试 运行 nl_nl、nl_be、en_gb.. 以及 b2c、b2b 等渠道...

最简单的方法是在测试本身中创建一个循环来遍历语言环境和频道,但我想 运行 同时进行这些测试。

我试图创建一个函数来动态生成这些测试,但 TestCafe 似乎无法检测到这些测试。

dynamicTest('Main Flow', async (t) => {

});

function dynamicTest(testName, testFn) => {
  const channels = ['b2c']

  channels.forEach((channel) => {
    test(`[Channel] ${channel}] ${testName}`, testFn);
  });
};

有更好的方法吗?我看到的唯一解决方案是 运行从 Jenkins 多次连接测试脚本以实现并发。

更详细的代码:

import HomePage from '../../page/HomePage/HomePage';
import EnvUtil from '../../util/EnvUtil';

const wrapper = (config, testFn) => {
  config.locales.forEach(async locale =>
    config.channels.forEach(async channel => {
      const tstConfig = {
        locale,
        channel
      };

      tstConfig.env = EnvUtil.parse(tstConfig, config.args.env);
      testConfig.foo = await EnvUtil.get() // If I remove this line it works!

      testFn(config, locale, channel)
    })
  );
};

fixture(`[Feature] Feature 1`)
  .beforeEach(async t => {
    t.ctx.pages = {
      home: new HomePage(),
      ... more pages here
    };
  });

wrapper(global.config, (testConfig, locale, channel) => {
  test
    .before(async (t) => {
      t.ctx.config = testConfig;
    })
    .page(`foo.bar.com`)
    (`[Feature] [Locale: ${locale.key}] [Channel: ${channel.key}] Feature 1`, async (t) => {
      await t.ctx.pages.home.header.search(t, '3301');

      .. more test code here
    });
});

如果我 运行 这样,我会收到 "test is undefined" 错误。我包装的方式有问题吗"test"?

使用 version 0.23.1 的 TestCafe,您可以 运行 从外部库导入或动态生成的测试,即使您提供的测试文件不包含任何测试。

您可以在此处了解更多信息:Run Dynamically Loaded Tests