Testcafe打开PDF无法截屏

Testcafe cant take screenshot when opening PDF

我想使用 TestCafe 从我的本地目录打开一个 PDF 文件,然后截取该 PDF 文件的屏幕截图。

但它一直给我错误

ERROR The Chrome 68.0.3440 / Windows 10.0.0 browser disconnected. This problem may appear when a browser hangs or is closed, or due to network issues.

我的代码很简单。只需打开 PDF,然后进行屏幕截图。

test('pdfscreenshot', async t => {
    await t
        .navigateTo(`file:///TestCafe/screenshots/picture.pdf`)
        .takeScreenshot('picture.png')
});

我不确定我做错了什么。如果它不是 PDF,我可以截图。 IE。如果我把它改成

.navigateTo(`https://www.google.com`)

有效

TestCafe 不支持使用非Html 文件(例如图像或 PDF 文件)。不过,您可以创建一个测试来检查文件的状态。

为此,使用 Request module. You can also use the "fs" module if picture.pdf is located in your file system. Then, you can process this content as you need (e.g. check if a file is PDF). The following nodejs module might be helpful for this: https://www.npmjs.com/package/is-pdf-file

获取文件 URL 的文件内容

如果您想在 TestCafe 测试中执行此操作,请创建 "fixture" 没有页面:

fixture `Check PDF`;
   test('first test', async t => {
   // ...
});