我将 Testcafe 与具有数据库驱动后端(没有 API,但 MVC)的应用程序一起使用。
我想在运行测试之前设置和拆除数据库中的设置。这可以通过在我的应用程序上调用 URL 来关闭(例如https://myapp.local/setup?foo=bar或https://myapp.local/teardown?foo=bar)
在运行测试之前,我想从 Testcafe 中调用这些 URL。我查看了模块testcafe-once-hook
(https://github.com/DevExpress/testcafe-once-hook)和随附的示例(https://github.com/AlexKamaev/testcafe-once-hook-example)
import { oncePerFixture } from 'testcafe-once-hook';
const setupDb = oncePerFixture(async t => {
await t.navigateTo('https://myapp.local/setup?foo=bar');
});
fixture `Setup db`
.before(() => {
setupDb;
})
test('Test1', async t => {
/* Test 1 Code */
});
但是从我的 Apache 日志文件中可以看出,setupDb 中的 URL 从未被调用过。
我还查看了https://github.com/DevExpress/testcafe/issues/1345#issuecomment-338796731,但从我的 Apache 日志文件中可以看到,这里也从未调用过 URL。
fixture `Setup db`
.before(async ctx => {
ctx.hasSetup = false;
// Server-side actions
})
.beforeEach( async t => {
if (!t.fixtureCtx.hasSetup) {
await t.navigateTo('https://myapp.local/setup?foo=bar');
t.fixtureCtx.hasSetup = true;
}
else {
return t;
}
})
我怎样才能实现预先调用https://myapp.local/setup?foo=bar?