【发布时间】:2019-07-07 16:52:02
【问题描述】:
由于某种原因,我无法让 testcafe 的 RequestLogger 记录我正在进行的任何 API 调用。我已经阅读了几乎所有关于 RequestLogger 的文章和问题,并且所有内容都指向与以下代码相同的内容。不知道我做错了什么,任何帮助都会很棒。
参考资料:
Cannot intercept outgoing AJAX request from page using Testcafe
How to log Google Analytics calls in Testcafe?
我在本地运行并访问了一个也在本地运行的 API,前端在端口 3000 上,后端在端口 8080 上,API 位于:8080/api/admin。我可以看到记录器被注入到测试中,但没有任何更新,它只是一个带有初始道具的平淡对象,并且会在 t.expect 语句之后出错。
我想知道 beforeEach 是否破坏了某些东西,但我需要它来触发任何 API 调用,因为需要对用户进行身份验证。我可以看到调试时调用的 API 请求,我试图拦截,但没有运气
testcafe 版本:1.0.0 || 0.23.3
测试代码
// have tried several urls, from exact to generic to ports.
const logger = RequestLogger("/api/", {
logRequestHeaders: true,
logRequestBody: true
});
const url = 'localhost:3000/reports';
fixture `Report`
.page(url)
.requestHooks(logger)
.beforeEach(async (t: TestController) => {
await loginAndNavToReports({ t });
});
test("Reports", async (t: TestController) => {
// this fires an api call through the /api/ path
await t.click(".test-reportLaborSummary");
// have tried several comparisons here, all fail or expect falsey to be truthy errors
await t.expect(logger.count(() => true)).ok();
}
【问题讨论】:
标签: javascript typescript automated-tests e2e-testing testcafe