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:


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";


const loginPage = new LoginPageObjects();
const reportsPage = new ReportsDelegateReportPageObjects();

describe('Delegate Report Functionality', function (){

    beforeEach(() => {
        // Provides admin credentials
        // Navigates to Report Menu, Selects Report, Downloads PDF report.

    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.

  • are you getting any error ?
    – PDHide
    Aug 13, 2020 at 8:41
  • 2
    Cypress docs don't talk about using cy.readFile to read PDFs. Where have you seen it is useful? Additionally and alternatively, why not to use PDF.js instead of Cypress or simply cover the functionality in the backend service unit tests, since the PDF generation has nothing to do with the consumer (a web application)? Aug 13, 2020 at 8:50
  • @JoãoFarias i am wondering why there is no error or exception thrown
    – PDHide
    Aug 13, 2020 at 8:54
  • @PDHide - No, I am not getting any errors. It's just skipping the assertion.
    – ubcqetest
    Aug 13, 2020 at 14:47
  • What makes you think it's skipping the assertion?
    – jonrsharpe
    Aug 13, 2020 at 16:08


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.