Not able to upload a png file in cypress
See original GitHub issueI am trying to upload a png file using cypress and this is that i have tried so far
Cypress.Commands.add('upload_file', (fileName, selector) => {
return cy.get(selector).then(subject => {
return cy.fixture(fileName, 'base64')
.then(Cypress.Blob.base64StringToBlob)
.then(blob => {
const el = subject[0]
const testFile = new File([blob], fileName, { type: 'image/png' })
const dataTransfer = new DataTransfer()
dataTransfer.items.add(testFile)
el.files = dataTransfer.files
return subject;
})
})
})
calling this in my test as below:
cy.upload_file("logo.png", ".jss378");
Have also tried different locators but no luck
it does not give any error but also it does not upload anything. note that the selector(.jss378) is dynamic so i want to use something that is not dynamic
Here is my HTML code
I am not getting any error but it not uploading anything
Issue Analytics
- State:
- Created 4 years ago
- Comments:5
Top Results From Across the Web
Not able to upload the png image(logo) using cypress
Got it working by using cypress upload plugin. here are the steps: 1) adding the following in the command.js: import 'cypress-file-upload';.
Read more >How to upload a file in cypress - TestersDock
1. Go to https://the-internet.herokuapp.com/upload. · 2. Select a file and upload it. · 3. After upload, validate that the file was successfully ...
Read more >How to upload a file in Cypress? - YouTube
cypress # upload #automationbroIn this tutorial, we will learn how to upload a file in Cypress. ... Your browser can't play this video....
Read more >Uploading files made easy with the .selectFile command
selectFile() command, new in Cypress 9.3.0. Selecting files in an HTML5 input elementWith the new .selectFile() command, you.
Read more >How to upload files with Cypress - DEV Community
png file, checks that the previous file has been replaced by the new one. Finally, it deletes the note and verifies that it...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Use cypress file upload package: https://www.npmjs.com/package/cypress-file-upload Note: testPicture.png must be in fixture folder of cypress
@must-git-good - thank you, it worked