我正在测试的 Web 应用程序的一部分是单击一个按钮,该按钮通常会在新选项卡中打开 PDF。这使用户能够在应用程序中继续前进。 PDF 可以忽略。
目前,我的策略是单击按钮,然后使用 ClientFunction 导航回来。 TestCafe 在点击按钮时成功打开 PDF,但在同一个选项卡中打开,然后测试卡住了。向后导航会更改 URL,但仍会显示 PDF。
const goBack = ClientFunction(() => window.history.back())
await this.t.click(this.button)
await this.t.wait(10000)
await goBack()
TestCafe 目前是否能够绕过这个问题,因为我实际上不需要对 PDF 做任何事情?
最佳答案
TestCafe 允许测试 html 页面,但不能测试 PDF 文件。因此,您可以检查生成的 PDF 文件链接作为字符串,而无需实际访问此链接。例如:
const overrideWindowOpen = ClientFunction(() => {
window.open = function (url) {
window.__lastWindowOpenUrl = url;
};
});
const getResultUrl = ClientFunction(() => window.__lastWindowOpenUrl);
await overrideWindowOpen();
await t
.click(this.button)
.expect(getResultUrl()).eql('http://example.com/path/to/PDF/93023813-0984-1');
关于pdf - TestCafe:测试在新选项卡中打开 PDF 的页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57575052/