cypress-io / cypress

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

Cypress test running locally but skipping tests on github actions beforeEach & afterEach Hook #27698

Closed EashBhanu-CCD closed 6 months ago

EashBhanu-CCD commented 1 year ago

Current behavior

beforeEach Hook fails everytime in github action

This is the error am getting in github action :

Customer Page - Partner

"before each" hook for "Click on customer icon & verify headers" 0 passing (19s) 1 failing

Customer Page - Partner "before each" hook for "Click on customer icon & verify headers": AssertionError: Timed out retrying after 4000ms: expected '/auth' to include '/user/'

Desired behavior

No response

Test code to reproduce

I am trying to visit url in beforeEach block but everttime it fails in github action

This is github workflow file :

name: Run Cypress Tests Automation

on:
push:
branches:
- feature/automation-testing

jobs:
run-cypress-tests:
runs-on: ubuntu-latest

steps:
  - name: Checkout repo
    uses: actions/checkout@v2
    with:
      repository: MyRepoName
      token: ${{ secrets.MYPAT }}

  - name: Cypress run
    uses: cypress-io/github-action@v5
    with:
      start: npm install
      build: npm run test
      browser: chrome

Cypress Version

12.17.3

Node version

v18.17.0

Operating System

gitthub action - cypress-io/github-action@v5

Debug Logs

No response

Other

No response

MikeMcC399 commented 1 year ago

@EashBhanu-CCD

Your submission is badly formatted and not readable. Please use backticks to format your workflow like this example of a correct workflow:

```yml
name: End-to-end tests
on: push
jobs:
  cypress-run:
    runs-on: ubuntu-22.04
    steps:
      - name: Checkout
        uses: actions/checkout@v3
      # Install npm dependencies, cache them correctly
      # and run all Cypress tests
      - name: Cypress run
        uses: cypress-io/github-action@v5

It seems that you are misusing the action, which automatically installs dependencies and runs your tests without needing to add extra commands to do this.

If you include 

```yml
build: npm run test

as a parameter to github-action then you will run your tests twice, perhaps with unpredictable results.

Please consult the README of github-action which explains how the action works and where there are many examples of how to use github-action correctly.

If you think you have found a bug in Cypress you can revisit this issue and provide a full reproducible example to demonstrate any bug, otherwise you have already started a conversation in Discord on https://discord.com/channels/755913899261296641/1146137405783556096 and the community may be able to help you there further.

EashBhanu-CCD commented 1 year ago

Below is github yaml file can you please suggest why am getting error @MikeMcC399 :

name: Run Cypress Tests Automation
on:
push:
branches:
- feature/automation-testing

jobs:
run-cypress-tests:
runs-on: ubuntu-latest

steps:
  - name: Checkout repo
    uses: actions/checkout@v2
    with:
      repository: MyRepoName
      token: ${{ secrets.MYPAT }}

  - name: Cypress run
    uses: cypress-io/github-action@v5
    with:
      start: npm install
      build: npm run test
      browser: chrome
MikeMcC399 commented 1 year ago

@EashBhanu-CCD

You should remove the line

start: npm install

because cypress-io/github-action@v5 already executes npm ci (see README > Installation) to install dependencies. You need to make sure that your repository has package-lock.json committed to it.

What is your script definition for test? Probably you should remove the line build: npm run test as well.

EashBhanu-CCD commented 1 year ago

@MikeMcC399 npm run test run will below command from package.json :

"scripts": { "test": "npx cypress run --headless --browser firefox --spec cypress/e2e/Customer.cy.js"

}

@MikeMcC399 If i will remove this build: npm run test how can i run the above spec file in github action ?

MikeMcC399 commented 1 year ago

@EashBhanu-CCD

You would need to pass your command line parameters instead as github-action parameters:

  - name: Cypress run
    uses: cypress-io/github-action@v5
    with:
      browser: firefox
      spec: cypress/e2e/Customer.cy.js

github-action automatically runs E2E tests by default if you do not specify anything else.

headless is default (see README > Headed)

There is not enough information here to know if that will resolve your issue, however that will definitely clean up your workflow.

EashBhanu-CCD commented 1 year ago

Still am facing below issue @MikeMcC399 @nagash77 :

Customer Page - Partner 1) "before each" hook for "Click on customer icon & verify headers" 2) "after each" hook for "Click on customer icon & verify headers"

0 passing (25s) 2 failing

1) Customer Page - Partner "before each" hook for "Click on customer icon & verify headers": AssertionError: Timed out retrying after 4000ms: expected '/auth' to include '/user/'

Because this error occurred during a before each hook we are skipping the remaining tests in the current suite: Customer Page - Partner at Context.eval (webpack://csc-external-ui-automation/./cypress/e2e/Customer.cy.js:36:32)

This is my github action file :

name: Chrome
on: push
jobs:
  chrome:
    runs-on: ubuntu-22.04
    name: E2E on Chrome
    steps:
      - uses: actions/checkout@v3
      - uses: cypress-io/github-action@v5
        with:
          browser: chrome
MikeMcC399 commented 1 year ago

@EashBhanu-CCD

Please create a reproducible example using a fork of Cypress Test Tiny. This gives us the best chance of seeing exactly what you are seeing and being able to investigate effectively. Your error is related to different components including your tests, the server you are testing and other configuration parameters you have set. The github-action workflow is not enough to judge where your problem is coming from.

MikeMcC399 commented 1 year ago

@EashBhanu-CCD

If you do not want to work on this issue anymore, then you may decide to close it. According to your posts in Discord, you have now progressed further.

cypress-app-bot commented 6 months ago

This issue has not had any activity in 180 days. Cypress evolves quickly and the reported behavior should be tested on the latest version of Cypress to verify the behavior is still occurring. It will be closed in 14 days if no updates are provided.

cypress-app-bot commented 6 months ago

This issue has been closed due to inactivity.