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

Spying on XHR request fails on Travis, but runs on Mac fine #1201

Closed
bahmutov opened this issue Jan 18, 2018 · 9 comments
Closed

Spying on XHR request fails on Travis, but runs on Mac fine #1201

bahmutov opened this issue Jan 18, 2018 · 9 comments
Labels
browser: electron CI General issues involving running in a CI provider

Comments

@bahmutov
Copy link
Contributor

bahmutov commented Jan 18, 2018

Current behavior:

On Mac a test that sets up XHR spy (from test spec) can spy on it. On Travis it fails to get the response. See https://dashboard.cypress.io/#/projects/9fap2d/runs/20b0cf0a-828b-4992-b7cf-25dfd71625cf/screenshots

Desired behavior:

Be able to run this test on Travis

How to reproduce:

Take repo https://github.com/bahmutov/cypress-form-data-with-file-upload and look at spec.js https://github.com/bahmutov/cypress-form-data-with-file-upload/blob/777f6df8725985d2dfcb410b375f45ed59b55cd4/cypress/integration/spec.js#L38

Test code:

   it('upload with spying', () => {
      // spy on XHR calls
      cy.server()
      cy.route('POST', '/upload').as('upload')

      // we can enter info into the form fields
      cy.get('input[name="userid"]').type('[email protected]')

      // files to upload for each input[type="file"] name
      // we are going to construct a single text file
      const files = {
        fileToUpload: new File(['foo bar'], 'test-file.txt', {
          type: 'text/plain'
        })
      }
      // get the form element and attach files to upload
      cy.get('form').then(attachFiles(files))

      // submit the form
      cy.get('input[type="submit"]').click()

      // check upload response
      cy
        .get('@upload')
        .its('response.body')
        .should('include', 'Uploaded test-file.txt')
        .and('include', 'for [email protected]')
    })

Additional Info (images, stack traces, etc)

Fails on Travis

failed-spy

Runs fine on Mac (both in Electron and in Chrome)

screen shot 2018-01-17 at 10 20 05 pm

I did not have time to run local Docker image or try Chrome on Travis

  • Operating System: Linux (TravisCI)
  • Cypress Version: 1.4.1
  • Browser Version: Electron
@lethot
Copy link

lethot commented Mar 5, 2018

I have similar problem on circleci, cypress 2.1.0,
I have 2 routes declared, called in several tests:

test 1 :

  • call to route 1: ok
  • call to route 2: xhr sent but not detected by cypress, lead to timeout

test 2 and following:

  • call to route 1: xhr sent but not detected by cypress, lead to timeout

Everything works well locally, tests pass 100%, even with cli --headed, but fail 100% in circleci
I tried with chrome too, same thing happens

Screenshots:

locally: (I can see xhr)
image

circleci: (xhr does not appear)
image

@OrganicCat
Copy link

I have a possible related issue, where on response with a 200 status the XHR POST request shows as "aborted" and the XHR status property reads "readyState" 0. However, the request goes through as verified in the network tab AND the upper "Status:" output if you click on the call.

The post response has a body of "" (nothing in there) which I THINK might be the issue? This is still a valid 200 response and should not show as failed.

@phellipeandrade
Copy link

phellipeandrade commented Apr 8, 2018

I have the same problem on circleci 2.0, cypress 2.1.0

locally:
screenshot from 2018-04-07 22-02-00

circleci (no XHR detection):
screenshot from 2018-04-07 22-04-09

Making the tests fail by timeout

Do you have any progress or even a workaround?

Thanks

@filiphric
Copy link

filiphric commented May 28, 2018

I have been able to replicate this outside of CI. I ran a test in Chrome, received an empty response body, though a response code was 201. Request came through, so problem points to Cypress.

I was able to replicate this in CI too, it seems to me that on on CI this happens more often, so I’m thinking if this could be some case of race condition.

screenshot-2

@bsmithEG
Copy link

I'm currently experiencing an issue where all of my wait for xhr's are failing on CircleCI with 3.0.1 and the chrome65-ff container.

I can't reproduce locally. Is there any extra amount of logging I could configure when the test runs and capture the output into a build artifact that would be beneficial? Perhaps like a network request/response log?

@kuceb
Copy link
Contributor

kuceb commented Jun 13, 2018

@bsmithEG do they sometimes fail or always? when did this start happening?

@bsmithEG
Copy link

bsmithEG commented Jun 14, 2018

@bkucera:

So on #1716 I discovered even though I thought I was running Chrome on CircleCI, I was actually running electron, do to misusage of command line arguments. It seems like passing in invalid parameters to the cypress command line simply runs the default cypress run without any options.

I'll report back after I run a few CI runs to make sure it's related to something else (Electron usage) -- edit: I spoke to soon, but I'll update again after a few runs (doesn't seem to be working with Chrome either)

@jennifer-shehane
Copy link
Member

@bsmithEG What were the invalid parameters that you were sending to cypress run? The command should error if you send invalid parameters, so we'd like to catch anything we may have missed. Thanks.

@jennifer-shehane
Copy link
Member

Closing as resolved.

If you're experiencing a bug similar to this in Cypress, please open a new issue with a fully reproducible example that we can run. There may be a specific edge case with the issue that we need more detail to fix.

@jennifer-shehane jennifer-shehane removed the stage: needs investigating Someone from Cypress needs to look at this label Jun 29, 2020
@jennifer-shehane jennifer-shehane added CI General issues involving running in a CI provider and removed CI: circle labels Oct 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
browser: electron CI General issues involving running in a CI provider
Projects
None yet
Development

No branches or pull requests

8 participants