abramenal / cypress-file-upload

File upload testing made easy
https://npm.im/cypress-file-upload
MIT License
496 stars 89 forks source link

Getting a false positive about a file uploading[Bug] #347

Closed Tacoholic closed 2 years ago

Tacoholic commented 2 years ago

Current behavior:

So I am currently trying to create a test where I can upload a file from my computer. When I run the test, it tells me it passed, but when I check the browser to look at the way the test was executed, the file did not upload. So I then added an assertion that confirms that the message "File Successfully Uploaded!" will display when a file is uploaded. It is not failing. I followed the documentation, step-by-step, but no luck. Not sure why the test is saying that the file was uploaded, when it's not true.

This is telling me the test passed. https://share.getcloudapp.com/Jruny1Rp This is when I looked at the browser. There should be a message saying "file uploaded successfully". https://share.getcloudapp.com/Jruny4ll

Desired behavior:

Steps to reproduce: (app code and test code)

Spec file. My png image is in the fixtures folder.

describe("Upload test", () => {
    const imageFile = "lp.png";
  it("File can upload", () => {
  cy.get(".button-group > .btn.btn-primary").click().attachFile(imageFile)
  cy.contains("File Successfully Uploaded!")
        });
    });

The HTML for it:

<div class="button-group ng-star-inserted 
     <button class="btn btn-primary"/>  
/>

Versions

Cypress version: 8.0.0 Browser: Electron 89

tomaszczura commented 2 years ago

I used attachFile in a few of my tests and didn't have any problems with that. attachFile is not synchronous - it does not wait until file is uploaded. Second thing - cy.contains("File Successfully Uploaded!") probably look through your whole DOM, so how do you show that text? Is this just hidden before upload, or it is added to DOM when file is uploaded? Could you also paste code which you use to upload?

Tacoholic commented 2 years ago

@tomaszczura It turns out that the input was well hidden in the Dom. It was in the app-root, inside a selector called app-file-selector. Test is working and passing.

abramenal commented 2 years ago

@all-contributors add @tomaszczura for question

Thanks for helping out here, really appreciate that!

allcontributors[bot] commented 2 years ago

@abramenal

I've put up a pull request to add @tomaszczura! :tada: