LironEr / cypress-mochawesome-reporter

Zero config Mochawesome reporter for Cypress with screenshots and videos
MIT License
159 stars 49 forks source link

before() after() hook part are not seen in the html report #103

Closed kilbc634 closed 1 year ago

kilbc634 commented 2 years ago

Environment

- OS: Mac
- Node: 16.16.0
- cypress-mochawesome-reporter: 3.2.2
- cypress: 10.7.0

What happened?

Hi, here is my e2e test file There are two simple test case. At first I used before() to open the google search home page

/// <reference types="cypress" />

describe('Test google search', {
    'env': {
        'HOME_PAGE': 'https://www.google.com/?hl=zh_tw'
    }
},() => {
    before(() => {
        cy.visit(Cypress.env('HOME_PAGE'))
    })
    afterEach(() => {
        if (cy.url() != Cypress.env('HOME_PAGE')) {
            cy.visit(Cypress.env('HOME_PAGE'))
        }
    })

    it('Check Element For Search Page', () => {
        // check google logo
        cy.get('img[alt="Google"][src]').should('be.visible')
        // check seach input
        cy.get('input[name="q"][type="text"]').should('be.visible')
        // check seach button
        cy.get('div.FPdoLc input[value="Google 搜尋"]').should('be.visible')
    })

    it('Search Keyword Should Succeed', () => {
        // type keyword
        cy.get('input[name="q"][type="text"]').type('Facebook')
        // submit keyword
        cy.get('div.CqAVzb input[value="Google 搜尋"]').click()
    })
})

The above cdoe works normally, but the problem is that before() and afterEach() are not seen in the html report (I'm sure the html report's sidebar show hooks = Always) https://i.imgur.com/bPc5xnt.png (report image)

And I'm sure the "before all" part is executed in cypress https://i.imgur.com/dtuRBmH.png (cypress execute image)

Config file

cypress.config.js:

const { defineConfig } = require('cypress');

module.exports = defineConfig({
  reporter: 'cypress-mochawesome-reporter',
  reporterOptions: {
    charts: true,
    debug: true,
    showHooks: 'always',
    saveJson: true
  },
  e2e: {
    setupNodeEvents(on, config) {
      require('cypress-mochawesome-reporter/plugin')(on);
    }
  },
});

Relevant log output

No response

Anything else?

No response

LironEr commented 1 year ago

Unfortunately, the reporter doesn't have access to this.

The reporter gets the code from Cypress and the only code sent is the test code, without anything else.