https://cypress.io logo
selectFile command deprecated?
# i-need-help
w
Source: https://docs.cypress.io/api/commands/selectfile I would just like to share my experience with this command - I tried using this official command to get image file from my fixtures and upload it to input=file field but every time the image would get uploaded and I wanted to preview it, it would look something like this (no img element) - image 1 After trying many workarounds, I figured that I can just use attachFile command which provided me with good solution, image preview available (rendered as img element). https://www.npmjs.com/package/cypress-file-upload Hope this will save someone some time 🙂
g
Never had problems with selectFile, it is definitely the way to go. If you believe it is not working correctly, open a github issue with a reproducible example showing the problem
w
Do you maybe know the reason why does preview of the image look like this compared to the one with attachFile which becomes img element?
a
@witty-gpu-64102 I've not heard of this issue before. Can you provide a reproducible example?
w
Sure, so I have my image file on this location and I call it via fixture command, and load it in selectFile, after which I force to upload it (because input=file element is hidden because of use of Ant design on front), after which I press save button. Image gets uploaded but when I click on it, it is opened as this element shown on uploaded image above. Snippet of code: cy.fixture('/images/testImageFile.jpeg').as('imageFile'); ProjectNameAssetDetailsPage.elements.uploadImageFileButton() .selectFile('@imageFile', { force: true, }); ProjectNameAssetDetailsPage.elements.saveAssetChangesButton() .click({force : true}); // assert that the file is uploaded and present in the list on the asset ProjectNameAssetDetailsPage.elements.uploadedFilesList() .should('contain.text', 'testImageFile.jpeg');