cypress-io / github-action

GitHub Action for running Cypress end-to-end & component tests
https://on.cypress.io/guides/continuous-integration/github-actions
MIT License
1.37k stars 348 forks source link

Cypress test always fails in GitHub Actions & headless, but not locally #1048

Closed EashBhanu-CCD closed 1 year ago

EashBhanu-CCD commented 1 year ago

on: push

jobs:
  cypress-run:
    runs-on: ubuntu-22.04
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Cypress run
        uses: cypress-io/github-action@v6
        with:
          record: true
          browser: chrome
          spec: cypress/e2e/Customer.cy.js
        env:
          CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Version

  │ Cypress:        13.3.0                                                                         
  │ Browser:        Chrome 117                                                                     
  │ Node Version:   v20.5.0 (/home/runner/runners/2.309.0/externals/node20/bin/node)               
  │ Specs:          1 found (Customer.cy.js)                                                       
  │ Searched:       cypress/e2e/Customer.cy.js                                                     
  │ Params:         Tag: false, Group: false, Parallel: false                                      
  │ Run URL:        https://cloud.cypress.io/projects/f3fmt4/runs/18   

Error in Github action its not able to click button but it always pass in local

1) Customer Page - Partner Click on customer icon & verify headers: AssertionError: Timed out retrying after 60000ms: Expected to find element://button[@type='button'][normalize-space()='New customer'], but never found it. at Context.eval (webpack://csc-external-ui-automation/./cypress/e2e/Customer.cy.js:44:33)

MikeMcC399 commented 1 year ago

@EashBhanu-CCD

The error message:

1) Customer Page - Partner Click on customer icon & verify headers: AssertionError: Timed out retrying after 60000ms: Expected to find element://button[@type='button'][normalize-space()='New customer'], but never found it. at Context.eval (webpack://csc-external-ui-automation/./cypress/e2e/Customer.cy.js:44:33)

is not caused by GitHub Actions, so there is nothing that the action can do to fix this problem for you.

There is some general advice in the FAQs Why do my Cypress tests pass locally but not in CI? which may help you.

Since you are using Cypress 13.x and you are recording into the Cypress Cloud under https://cloud.cypress.io/projects/f3fmt4 you should have access to Test Replay where you can visit your test and go through it step by step.

If you want the community to assist you, then you would either need to make your Cypress Cloud project f3fmt4 public or at least share your failing test spec Customer.cy.js.

EashBhanu-CCD commented 1 year ago

@MikeMcC399 It is difficult to make cypress cloud project public since it my organization based project but i can share Customer.cy.js

/// <references types="Cypress">
import { faker } from '@faker-js/faker'
import LoginPage from '../PageObjects/LoginPage'
import CustomerPage from '../PageObjects/CustomerPage'

let NewCustNum = faker.helpers.rangeToNumber({ min: 1, max: 100000 })
let EditCustNum = faker.helpers.rangeToNumber({ min: 1, max: 100000 })

const LegalName = 'LegalCustm' + NewCustNum
const BrandName = 'BrandPartner' + NewCustNum
const Internalref = 'IRP' + NewCustNum
const InternalrefLowercase = Internalref.toLowerCase()
const contactemail = faker.internet.email()

const EditLegalName = 'LegalCustm' + EditCustNum
const EditBrandName = 'BrandPartner' + EditCustNum
const Editcontactemail = faker.internet.email()

const loginPage = new LoginPage()
const CustPage = new CustomerPage()
let data

describe('Customer Page - Partner', () => {

  beforeEach(() => {
    cy.fixture('login').then((loginData) => {
    data = loginData
    cy.clearCookies()
    cy.clearLocalStorage()
    cy.login(data.UserName, data.Password)
    })
  })

  it('Click on customer icon & verify headers', () => {

    cy.log('Running')
    CustPage.UAM_Page().click()
    CustPage.CustomerIcon().should('be.visible')
    CustPage.CustomerIcon().click()
    CustPage.NewCustomerButton().should('be.visible')
    CustPage.BrandNameHeader().should('be.visible')
    CustPage.LegalNameHeader().should('be.visible')
    CustPage.ContactEmailHeader().should('be.visible')
    CustPage.InternalRefHeader().should('be.visible')
    CustPage.CreationDateHeader().should('be.visible')
  })

 it('Verify cancel Button & save Empty Form', () => {

    CustPage.UAM_Page().click()
    CustPage.CustomerIcon().should('be.visible')
    CustPage.CustomerIcon().click()
    CustPage.NewCustomerButton().should('be.visible')
    CustPage.NewCustomerButton().click()
    CustPage.CustomerFormHeader().should('be.visible')

    //Click on cancel button & verify

    CustPage.CancelButton().click()
    CustPage.CustomerFormHeader().should("not.exist")

    //Save Empty form it should not work 
    CustPage.NewCustomerButton().click()
    CustPage.AddNewCustomerButton().click()
    CustPage.EmptyLegalMessage().should('be.visible')
    CustPage.EmptyBrandMessage().should('be.visible')
    CustPage.EmptyEmailMessage().should('be.visible')
    CustPage.EmptyIntRefMessage().should('be.visible')

    //Click on save it should not save
    CustPage.AddNewCustomerButton().click()
    CustPage.CustomerCreated_Message().should('not.exist')
    CustPage.CancelButton().click()

  })

  afterEach(() => {
    CustPage.MenuContainer().click()
    CustPage.Logout().click()
  })

})
MikeMcC399 commented 1 year ago

@EashBhanu-CCD

Thank you for sharing your test spec. I don't think it will be possible to help you here as a GitHub Action issue.

You have a problem with your Application under Test and Cypress working together. Your Cypress test is also using modules from your application to run, so it is not enough to just see the contents of the test spec in order to understand what is happening.

If you can reduce your problem to a simple example which does not work, then perhaps the Discord community will be able to help you.

Sorry that I can't help you anymore on this issue.

EashBhanu-CCD commented 1 year ago

@MikeMcC399 In short answer its not able to click the below element in github action even though i have given timeout of 60000ms : //button[@type='button'][normalize-space()='New customer']

MikeMcC399 commented 1 year ago

@EashBhanu-CCD I suggest to close this issue as the problem is not caused by cypress-io/github-action. You can continue to request assistance in your Discord thread.

fabu1985 commented 2 months ago

are fix solved your problem @EashBhanu-CCD ?