【发布时间】:2019-02-12 11:05:01
【问题描述】:
我使用 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
});
});
如果我这样运行它,我会收到“测试未定义”错误。我包装“测试”的方式有什么问题吗?
【问题讨论】:
-
能否告诉我您正在使用的TestCafe 版本?
-
我正在运行最新版本(0.22.0)
-
这个例子适用于我的 TetstCafe v0.22:github.com/MarinaRukavitsyna/TestCafe_Dynamic_Test。请检查一下好吗?
-
我会检查的,谢谢!
-
我发现原因是包装文件中的“await fn()”。我将它添加到示例中。不知道为什么
标签: testing automated-tests e2e-testing web-testing testcafe