I want to use TestCafe to open a PDF file from my local directory and then take a screenshot of the PDF File.
But it keeps on giving me the Error
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.
My Code is very simple. Just opening the PDF and then Taking the Screenshot.
test('pdfscreenshot', async t => {
await t
.navigateTo(`file:///TestCafe/screenshots/picture.pdf`)
.takeScreenshot('picture.png')
});
I'm not sure what I'm doing wrong. I am able to take screenshots if its not a PDF tho. Ie. If I change it to
.navigateTo(`https://www.google.com`)
It works
TestCafe does not support working with non-Html files (e.g. an image or PDF file ). Nevertheless, you can create a test that will check status of your file.
For this, obtain file content by the file URL using the 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
If you want to do this in a TestCafe test, create "fixture" without a page:
fixture `Check PDF`;
test('first test', async t => {
// ...
});