pdf - TestCafe:测试在新选项卡中打开 PDF 的页面

标签 pdf testing automation e2e-testing testcafe

我正在测试的 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');

另请参阅:Multiple Browser Windows

关于pdf - TestCafe:测试在新选项卡中打开 PDF 的页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57575052/

相关文章:

macos - 删除30天以上的下载内容?

python - 使用Python转换PDF坐标系

python - 使用selenium python滚动窗口

javascript - Kendo 导出的 PDF 页面上的边距

iphone - iPhone 上的 ocunit 测试

visual-studio - 从 Microsoft 测试管理器中的探索性 session 创建测试用例仅显示最后 10 个步骤

testing - 测试网页/网站时要寻找的首要事项

javascript - jQuery 限制复选框

ios - 在 UIWebview 中打开 pdf 时出错

python - 如何将结果列表保存到文件