【问题标题】:TestCafe: Testing a Page Opening a PDF in a New TabTestCafe:测试在新选项卡中打开 PDF 的页面
【发布时间】:2019-08-20 13:42:01
【问题描述】:

我正在测试的 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 做任何事情?

【问题讨论】:

    标签: pdf testing automation e2e-testing testcafe


    【解决方案1】:

    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,这样我就可以继续测试而不会通过访问 PDF 来破坏它?
    • 嘿@Artem,您如何将实际的 window.open 函数保存为另一个 ClientFunction 中的备份?
    猜你喜欢
    • 2015-11-14
    • 1970-01-01
    • 2011-04-23
    • 1970-01-01
    • 1970-01-01
    • 2021-12-26
    • 1970-01-01
    • 2021-12-02
    • 2017-01-05
    相关资源
    最近更新 更多