我使用TestCafe为当前项目创建了一些e2e健全性测试。这些测试是标准的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
});
});
如果我像这样运行它,则会收到“未定义测试”错误。我包装“测试”的方式有问题吗?
答案 0 :(得分:2)
使用version 0.23.1的TestCafe,即使您提供的测试文件不包含任何测试,也可以运行从外部库导入的测试或动态生成的测试。
您可以在此处了解更多信息:Run Dynamically Loaded Tests