cypress-io / cypress

Fast, easy and reliable testing for anything that runs in a browser.
https://cypress.io
MIT License
47.12k stars 3.19k forks source link

Server is running but 404s on visit to application during cypress run #3245

Closed TanvirAlam closed 5 years ago

TanvirAlam commented 5 years ago

Current behavior:

Circle config.yml:

frontend-test:
    <<: *defaults
    docker:
      - image: cypress/base:8
      - image: circleci/node:10
    working_directory: ~/repo
    steps:
      - checkout
      # Download and cache dependencies
      - restore_cache:
          keys:
            - v1-dependencies-{{ checksum "package.json" }}
            # fallback to using the latest cache if no exact match is found
            - v1-dependencies-
      - run: npm ci
      - save_cache:
          paths:
            - node_modules
          key: v1-dependencies-{{ checksum "package.json" }}
      - run: npm run test:cypress

Package.json:

{
    "cypress:run": "cypress run",
    "start": "webpack-dev-server --config ./webpack.config.js --mode development",
    "test:cypress": "start-server-and-test start http://localhost:8080 cypress",
    "cypress": "cypress run",
}

cypress:json:

{
    "baseUrl": "http://localhost:8080/",
    "fixturesFolder": "cypress/fixtures",
    "integrationFolder": "cypress/integration",
    "pluginsFile": "cypress/plugins",
    "screenshotsFolder": "cypress/screenshots",
    "supportFile": "cypress/support",
    "videosFolder": "cypress/videos"
}

webpack.config.js:

module.exports = {
    entry: "./public/js/app.js"
}

GETTING ERROR:

circlecieror

Desired behavior:

it says:

CypressError: cy.visit() failed trying to load:

http://localhost:8080/login

The response we received from your web server was:

  > 404: Not Found

I have been trying this past 4 days, I don't know what is wrong, please help

The front-end is vuejs, hence the login page is login.vue which is loading vue-router

DylanVann commented 5 years ago

I'm also having an issue similar to this.

screen shot 2019-01-29 at 10 46 37 pm
jennifer-shehane commented 5 years ago

Hey @TanvirAlam, have you been able to look at the screenshots or video of the test failure?

@DylanVann Be sure you are not experiencing this issue which has a fix pending release. https://github.com/cypress-io/cypress/issues/3045

DylanVann commented 5 years ago

@jennifer-shehane Yes that was actually my issue, thanks for the help 🙏 .

TanvirAlam commented 5 years ago

@jennifer-shehane Kindly look at the following screenshots: login page -- see the login page -- before each hook failed

jennifer-shehane commented 5 years ago

@TanvirAlam Hmm, do you have a video of this test run? It doesn't look like this captured before cy.visit() resolved.

TanvirAlam commented 5 years ago

@jennifer-shehane yes I got the video but its mp4 git doesn't support to upload

TanvirAlam commented 5 years ago

@jennifer-shehane converted mp4 to gif ezgif com-video-to-gif

embiem commented 5 years ago

We're experiencing a similar issue right now. It looks like cypress reloads the whole page with the baseUrl of the site we want to test instead of cypress's baseUrl. In more detail:

When no baseUrl is set, we see the test page (where the tests are listed on the left side) at the url http://localhost:56113/__/#/tests/integration\myTestFolder\myTest.spec.js and once we go into the first test and call cy.visit(), the whole page reloads with the http://localhost:3000/__/#/tests/integration\myTestFolder\myTest.spec.js URL, which of course is a 404 on our website. The whole test run is then stuck. It pretty much looks like in the gif @TanvirAlam posted above, where the blank at the end is loading our website which then shows the 404 page.

When we have the baseURL set in the cypress.json, then the test window immediately loads the 404 page. The actual test window is not shown.

This only happens when running the tests in Chrome, but works when running in Electron. We have a dependency on Chrome because of our CI setup.

OussamaBaybay commented 5 years ago

@embiem try this : https://github.com/cypress-io/cypress/issues/1872#issuecomment-450807452

embiem commented 5 years ago

@OussamaBaybay thanks, that fixes our issue!

TanvirAlam commented 5 years ago

@embiem should I remove the baseURL from cypress.json?

beagleknight commented 5 years ago

I am experiencing the same issue @embiem today but yesterday was working fine. I tried @OussamaBaybay suggestion but now it doesn't work during the first run because the full page reload is killing the cookies (I think). If I reload the Cypress chrome instance when using cypress open it works thought.

embiem commented 5 years ago

@TanvirAlam no, it works for us now with baseUrl in cypress.json

beagleknight commented 5 years ago

I am experiencing the same issue @embiem today but yesterday was working fine. I tried @OussamaBaybay suggestion but now it doesn't work during the first run because the full page reload is killing the cookies (I think). If I reload the Cypress chrome instance when using cypress open it works thought.

Well... it wasn't related to cookies stuff so I can say the solution provided in #1872 kinda works. I don't understand why this was working yesterday without the patch 😞

embiem commented 5 years ago

I don't understand why this was working yesterday without the patch 😞

As far as I understood #1872 it has to do with a chromium update. So if your Chrome browser was updated between yesterday and today, this might be the reason.

TanvirAlam commented 5 years ago

@jennifer-shehane Just give you little more information as to this is a Laravel vue SPA project run on Docker.

Do I need to install something? like composer? and do npm run dev

So far tried many things ended up with this:

frontend-test:
    <<: *defaults
    docker:
      - image: circleci/php:7.2-node-browsers
      - image: circleci/mysql:5.6

      - image: cypress/base:8
      - image: circleci/node:10
      #- image: cypress/base:8
      #- image: circleci/node:10
    working_directory: ~/repo
    steps:
      - checkout
      - run: sudo docker-php-ext-install pdo pdo_mysql
      - run: sudo pecl channel-update pecl.php.net
      #- run: sudo pecl install xdebug && sudo docker-php-ext-enable
      - run: sudo composer self-update
      - restore_cache: # special step to restore the dependency cache if `composer.lock` does not change
          keys:
            - composer-v1-{{ checksum "composer.lock" }}
            # fallback to using the latest cache if no exact match is found (See https://circleci.com/docs/2.0/caching/)
            - composer-v1-
      - run: composer install -n --prefer-dist
      - save_cache: # special step to save the dependency cache with the `composer.lock` cache key template
          key: composer-v1-{{ checksum "composer.lock" }}
          paths:
            - vendor
      - restore_cache: # special step to restore the dependency cache if `package.json` does not change
          keys:
            - node-v1-{{ checksum "package.json" }}
            # fallback to using the latest cache if no exact match is found (See https://circleci.com/docs/2.0/caching/)
            - node-v1-
      - run: npm install
      - save_cache: # special step to save the dependency cache with the `package.json` cache key template
          key: node-v1-{{ checksum "package.json" }}
          paths:
            - node_modules
      #- run: touch storage/testing.sqlite
      - run: php artisan migrate
      - run: npm run dev
      - run: npm run test:cypress

Still the same ERROR:

CypressError: cy.visit() failed trying to load:

http://localhost:8080/login

The response we received from your web server was:

  > 404: Not Found

I am so sorry, but I am little new to Cypress and I would really like it if CircleCI could take care of it

Locally, it works just fine

jennifer-shehane commented 5 years ago

I noticed some of the other commenters problems were related to a bug that was fixed in Cypress version 3.1.5.

@TanvirAlam Can you verify this error is still occurring in version 3.1.5+

TanvirAlam commented 5 years ago

@jennifer-shehane Yes, I will check and let you know as soon as i can

jennifer-shehane commented 5 years ago

Closing as resolved. Please comment if you are still having this issue and we will consider reopening.

spiray commented 5 years ago

@jennifer-shehane I am having this issue on 3.4.1. I am using GitHub Actions and it works for me perfectly locally.

colbyallenc commented 5 years ago

set a baseUrl in your cypress.json file

jennifer-shehane commented 4 years ago

@spiray Please open a new issue and provide a fully reproducible example.