gpt4 book ai didi

testing - TestCafe 'dynamic' 测试用例

转载 作者:行者123 更新时间:2023-11-28 19:53:28 26 4
gpt4 key购买 nike

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

fixture(`Basic checkout flow`)

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

});

我想对多个站点区域设置和多个 channel 执行此测试。即我需要这个测试来运行 nl_nl, nl_be, en_gb, .. 以及像 b2c, b2b, ...

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

我试图创建一个函数来动态生成这些测试,但 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
});
});

如果我这样运行它,我会得到一个“测试未定义”的错误。我包装“测试”的方式有问题吗?

最佳答案

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

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

关于testing - TestCafe 'dynamic' 测试用例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52216685/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com