Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test runs fine individually but fails when "run all" is given #2028

Closed
srinivasrk opened this issue Jun 25, 2018 · 4 comments
Closed

Test runs fine individually but fails when "run all" is given #2028

srinivasrk opened this issue Jun 25, 2018 · 4 comments

Comments

@srinivasrk
Copy link

Current behavior:

I am uploading a csv file using XHR and form data. It takes nearly a minute for the server to parse the .csv and write the content in the database. These test cases work fine when run by itself, when I click on run all it fails and it gets status 500 even when the server sends back 200 !

image

image

image

image

@srinivasrk
Copy link
Author

srinivasrk commented Jun 26, 2018

I guess it was timing out. I increased the time out to work.

    it('should verify the file upload for channels', function() {
      const fileName = 'channels.csv';
      const method = 'POST';
      const url = 'http://localhost:3000/api/channels';
      const fileType = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
      const expectedAnswer = 'Successfully updated channels database';

      // Get file from fixtures as binary
      cy.fixture(fileName, 'binary').then((excelBin) => {
          // File in binary format gets converted to blob so it can be sent as Form data
          Cypress.Blob.binaryStringToBlob(excelBin, fileType).then((blob) => {
              // Build up the form
              const formData = new FormData();
              formData.set('file', blob, fileName); //adding a file to the form
              // Perform the request
              cy.form_request(method, url, formData, function (response) {
                  console.log(response);
                  expect(response.status).to.equal(200)
                  expect(response.response).to.equal(expectedAnswer)
              })
          })
      }).wait(55000)
    });

@brian-mann
Copy link
Member

You're not returning the Cypress.Blog.binaryStringToBlob promise which is going to create a race condition that can cause random failures / timeouts, etc.

You have to return promises to a cy.then so it knows to await it, else it has no idea you've kicked one off and it doesn't know when to wait to resolve.

Also - running "All Tests" from the GUI is not a good idea. We've documented this in detail in another issue, which is why we moved to running all of your specs in isolation with cypress run.

In other words, don't use cypress open to run all your test. Use cypress run to do it. Yes, I know we do provide that button, and we've internally talked about how to improve this, but the work isn't done yet, so we've left things as is to keep current users happy.

@srinivasrk
Copy link
Author

Thank you @brian-mann

@jcn-ithaca
Copy link

@brian-mann : You wrote that 'running "All Tests" from the GUI is not a good idea';
Is this still true in Cypress 4.6?
We're experiencing tests that succeed individually but fail during 'Run All'.
thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants