Objective: To find distinctive data that has been encoded in a pdf and write assertions using cypress to ensure data accuracy.
Observed Behavior: Assertions that have been written do not execute. I have tried the assertions and Cypress skipped them.
Cypress Automation Setup:
\plugins\index.js
const parsePdf = async (pdfName) => {
const pdfPathname = path.join(repoRoot, pdfName)
let dataBuffer = fs.readFileSync(pdfPathname)
return pdf(dataBuffer);
};
module.exports = (on, config) => {
on('task', {
getPdfContent (pdfName) {
return String(parsePdf(pdfName))
}
});
};
Test File admin.reports.spec.js
(Uses pageObject classes)
import LoginPageObjects from "../../support/pageObjects/common.pageObjects/login.pageObjects";
import ReportsDelegateReportPageObjects
from "../../support/pageObjects/common.pageObjects/reports.delegateReport.pageObjects";
import(LoginPageObjects);
import(ReportsDelegateReportPageObjects);
const loginPage = new LoginPageObjects();
const reportsPage = new ReportsDelegateReportPageObjects();
describe('Delegate Report Functionality', function (){
beforeEach(() => {
// Provides admin credentials
loginPage.getAdminLogin();
// Navigates to Report Menu, Selects Report, Downloads PDF report.
reportsPage.getMenuReport();
});
it('should return the report and verify the data in it', function () {
cy.readFile('C:/Users/michael.frazier/Downloads/delegate_report.pdf', 'base64').should('contain.value', "Report");
});
});
Steps I have Tried:
I have used the .should
, .expect
commands, does not search the file.
Used pdfparse
to read the file. Lots of Google Searches
Also, I did this as well and it was ignored.
it('tests a pdf', () => {
cy.task('getPdfContent', 'delegate_report.pdf').then(content => {
.should('contain', "Reports" });
})
The Ask: Is there a way where I can download the file, read the file then parse the data inside it so a assertion can be made? Can it be converted to something more easier to parse? (json, txt, etc?)
Any insight on this would be great.