Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

82
Views
Cypress is not uploading the image

I am automating one of the use cases in cypress and I am unable to upload the image using attach file function. Below is the code and the snippets from HTML tags

UI Upload Image

UI Upload Image

HTML tags

HTML tags

VS code

VS code

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I think you want to attach the file to the <input> as a first step. Then click the button, or you may not even have to do the click().

From the docs,

// start watching the POST requests
cy.intercept({ method: 'POST', url: /upload_endpoint/ }).as('upload');

const myFilePath = 'product.jpeg'; // file is in "/cypress/fixtures/" folder

cy.fixture(myFilePath, 'binary')
  .then(Cypress.Blob.binaryStringToBlob)
  .then(fileContent => {
    cy.get('input#productImageUpload').attachFile({
      fileContent,
      fileName: myFilePath,
      mimeType: 'application/octet-stream',
      encoding:'utf8',
      lastModified: new Date().getTime(
    })
  })

cy.get('.label-side').click()   // may not need to do this

// wait for the 'upload_endpoint' request, and leave a 2 minutes delay before throwing an error
cy.wait('@upload', { requestTimeout: 120000 });
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!