question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

In Cypress 3.3.0, Cypress.Blob.base64StringToBlob doesn't work with pdf

See original GitHub issue

Current behavior:

My test simulate a drop event to test React DropZone (https://github.com/react-dropzone/react-dropzone).

The test drop a base 64 encoded with Cypress.Blob.base64StringToBlob pdf into the drop zone.

Since Cypress 3.3.0, the test fails.

The event is triggered but the endpoint that receive the pdf never answers. The process works if done by hand without Cypress so the endpoint works.

I have tested with other file type (png, jpeg …) and the test works. It only fails with pdf.

Desired behavior:

The pdf gets encoded properly to be sent in a formData.

Steps to reproduce: (app code and test code)

The Cypress command that encode the file and trigger a drop event:

Cypress.Commands.add('dropFixtureInDropZone', (fixturePath, fixtureMime, dropZoneSelector) => {
  const dropEvent = { dataTransfer: { files: [] } }
  cy.fixture(fixturePath, 'base64').then(fixture => {
    return Cypress.Blob.base64StringToBlob(fixture, fixtureMime).then(blob => {
      dropEvent.dataTransfer.files.push(blob)
    })
  })

  cy.get(dropZoneSelector).trigger('drop', dropEvent)
})

The function that calls it:

export const create_file = (cy, fileTitle = 'newFile') => {
  cy.get('[data-cy=dropdownCreateBtn]').should('be.visible').click()
  cy.get('.show .subdropdown__link__file__icon').should('be.visible').click()

  cy.dropFixtureInDropZone('the_pdf.pdf', 'application/pdf', '.filecontent__form')

  cy.get('[data-cy=popup__createcontent__form__button]')
    .click()

  cy.get('[data-cy="popinFixed"].file')
    .should('be.visible')

  cy.get(`.workspace__content__fileandfolder > .content[title="blob"] .fa.fa-paperclip`)
    .should('be.visible')
}

The test fails at cy.get('[data-cy="popinFixed"].file')).should('be.visible') because since the endpoint doesn’t answer, that dom element isn’t displayed

Versions

tested in cypress open and cypress run, with electron and chrome in Cypress 3.3.0

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:16 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
cypress-bot[bot]commented, May 23, 2019

Released in 3.3.1.

1reaction
flotwigcommented, May 20, 2019

@skjnldsv That also looks like a duplicate of #4240, so no need to re-open for now

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cypress.Blob
Cypress automatically includes a Blob library and exposes it as Cypress.Blob. Use Cypress.Blob to convert base64 strings to Blob objects. Useful for.
Read more >
Unable to upload pdf file in POST request using Cypress 6.4.0 ...
Resolved this issue! The main issue was that my Cypress version was too old. Upgraded to 9.7.0. Then added the following code:
Read more >
cypress-file-upload - UNPKG
The CDN for cypress-file-upload. ... cypress-file-upload/dist/bundle.js.map. Version: ... Blob.base64StringToBlob(fileContent, mimeType)),\n [ENCODING.
Read more >
Testing File Uploads With Cypress.io - Brandon Parker
In particular, application/pdf and image/* mime-type files. Doing this with Cypress seems simple enough, but at the time of this article, Cypress does...
Read more >
about "Upload and download files from ADF into blob type ...
hi Using JDeveloper 10.1.3.3.0 I have tried the example available ... After that, there is not problem using the PDF file in Adobe...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found