I have been trying to use pdf-parse plugin on cypress to validate the context of some pdfs but I get the error "Fs.readFileSync is not a function". I am on version 12.4.1 but I did try other cypress versions with the same results (6.0.0, 7.5.0, 8.5.0, 9.0.0, 10.0.0). How do I use cypress pdf-parse? If you know any other way to parse the pdf content, please guide me as I have used pdfjs-dist and pdf2json with no success. Bellow is my code on one of my tries:
/// \<reference types="Cypress" /\>
import PdfParse from 'pdf-parse';
import Loader from './loader.js';
import Login from './login.js'
import PageActions from './pageActions.js';
import Validations from './validations.js';
describe('', () =\> {
const login = new Login()
const loader = new Loader()
const pageActions = new PageActions()
const validations = new Validations()
it('', () =\> {
cy.visit('/')
login.userName()
login.password();
login.clickSignIn()
loader.waitForLoaderToFinish()
pageActions.clickView();
loader.waitForLoaderToFinish();
Actions.clickLibrary();
loader.waitForLoaderToFinish()
pageActions.clickDownload();
loader.waitForLoaderToFinish();
validations.validatePDFHasBeenDownloaded();
cy.readFile('./cypress/downloads/Application Form.pdf')
.then(pdfBuffer =\> {
const options = {}; // optional options object
return pdfParse.pdf2json(pdfBuffer, options);
}).then(pdfData =\> {
cy.log(pdfData)
});
});
})
The problem seems to be with the "import PdfParse from 'pdf-parse';" but I have no clue what to do. Thank you in advance!!
I have tried to install it on versions 6.0.0, 7.5.0, 8.5.0, 9.0.0, 10.0.0 and I also have tried to use pdf2json and pdf-dist