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

Screenshots taken in a afterEach hook are not being displayed in allure report #26

Closed
rodolforodriguess opened this issue Oct 15, 2020 · 2 comments
Labels
bug Something isn't working

Comments

@rodolforodriguess
Copy link

rodolforodriguess commented Oct 15, 2020

Hey guys,

My aim is to see screenshots for each test. Well, my code takes the screenshot in a afterEach hook and then I could see the .png added to the allure-results folder as shown in the image below.

image

The allure report opens nicely but the screenshot is not displayed although there is a kind of a section left to that. See below an image of the report:

image

So I tried a workaround by using attachment method of Allure API in order to add it programatically. However, I didn't have any success.

So, to summarize, it's seems attachment method of Allure API is not working properly.

I added the exact name of the screenshot generated by cypress as cypress documentation: https://docs.cypress.io/api/commands/screenshot.html#Notes
which worked in a mochawesome report.

Here is the code which I put in index.js under support folder.

import './commands'
import './login.js'
//import addContext from 'mochawesome/addContext'
import '@shelex/cypress-allure-plugin'

Cypress.on('test:after:run', (test, runnable) => {
  if (test.state === 'failed') {
    const screenshotFileName = `${runnable.parent.title} -- ${test.title} (failed).png`
    const path = `../reports/screenshots/${Cypress.spec.name}/${screenshotFileName}`
    cy.allure().attachment('screenshot', new Buffer.from(path,'base64'),'image/png')
    
  }
  else {
    const screenshotFileName = `${runnable.parent.title} -- ${test.title} -- after each hook.png`
    const path = `../reports/screenshots/${Cypress.spec.name}/${screenshotFileName}`
    cy.allure().attachment('screenshot', new Buffer.from(path,'base64'),'image/png')
  }
})

In my test I just have a afterEach calling cy.screenshot()
image

My OS is a Linux Mint 20 Ulyana and allure is in its most recent version I believe which is 2.13.6.

@rodolforodriguess rodolforodriguess added the bug Something isn't working label Oct 15, 2020
@Shelex Shelex changed the title Screenshots taken in a afterEach hook are not being displayed in allure report Screenshots taken in a test:after:run are not being displayed in allure report Oct 16, 2020
@Shelex Shelex changed the title Screenshots taken in a test:after:run are not being displayed in allure report Screenshots taken in a afterEach hook are not being displayed in allure report Oct 16, 2020
@Shelex
Copy link
Owner

Shelex commented Oct 16, 2020

Hi @rodolforodriguess
Thank you for opening an issue.

  1. Why it is not automatically attached:
    afterEach mocha hook is fired when test itself is finished, and because of that there is no logger for test available in allure at that time and it is trying to add screenshot to current executable, which is afterEach hook logger, and then this hook is attached to suite logger with no screenshot available as allure does not support showing it. Solution for such issue could be done in terms of Add "before all" and "after all" hooks to report #17 with weird idea to handle hooks as steps for test, as order of mocha events not allow to do that natively.

  2. Why it cannot be processed in test:after:run:
    The issue is that cypress internal test:after:run event has no relation to mocha runner as according to documentation test:after:run fires after the test and all afterEach and after hooks run. While allure reporter writer itself is an afterEach hook, it basically cannot access what is going on in test:after:run.

@Shelex
Copy link
Owner

Shelex commented Dec 29, 2020

Addressed in v1.10.0

@Shelex Shelex closed this as completed Dec 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants