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

No way to attach video of failed test to allure report in afterTest hook #929

Open
lifanov-rza opened this issue Apr 14, 2024 · 1 comment
Milestone

Comments

@lifanov-rza
Copy link

Describe the bug

From PW documentation:

Videos are saved upon browser context closure at the end of a test. If you create a browser context manually, make sure to await browserContext.close().

So, if we need to get video of failed test we should wait for browserContext to be closed.

The implementation for allure-legacy plugin is present below:

 async _after() {
    const Playwright = container.helpers('Playwright');
    const allure = container.plugins('allure');
    await Playwright.browserContext.close();
    if (this.#artifacts.video) {
      output.debug(`Attaching a video: ${this.#artifacts.video}`);
      allure.addAttachment('Video', fs.readFileSync(this.#artifacts.video), 'video/webm');
    }
    allure.currentTest = null;
  }

Tried this implementation for allure-codeceptjs plugin but faced with the problem that currentTest is equal to null when test finished (passed / failed). The step 'allure.addAttachment' copies video file to allure-results repository but don't update <%.result.json> file by adding one more attachment.

Expected result:

"attachments": [
    {
      "name": "Console errors",
      "type": "text/plain",
      "source": "40b3cb14-4fde-42cf-b871-0d4c3812884b-attachment.txt"
    },
    {
      "name": "Main session - Last Seen Screenshot",
      "type": "image/png",
      "source": "c2ecc7ea-c805-4553-82ec-84a02260cd34-attachment.png"
    },
    {
      "name": "Video",
      "type": "video/webm",
      "source": <path to video file.webm>
    }
  ],

Actual result:

"attachments": [
    {
      "name": "Console errors",
      "type": "text/plain",
      "source": "40b3cb14-4fde-42cf-b871-0d4c3812884b-attachment.txt"
    },
    {
      "name": "Main session - Last Seen Screenshot",
      "type": "image/png",
      "source": "c2ecc7ea-c805-4553-82ec-84a02260cd34-attachment.png"
    }
  ],

Tried to add an entry about the video attachment and run 'allure serve' -> the video was present in the report.

To Reproduce
Steps to reproduce the behavior:

  1. Create AllureVideoHelper in codeceptJS project:
const Helper = require('@codeceptjs/helper');
const { event, container, output } = require('codeceptjs');
const fs = require('fs');

class AllureVideoHelper extends Helper {
  #artifacts;

  /**
   * Constructor
   *
   * @param {object} config - Helper config
   */
  constructor(config) {
    super(config);
    event.dispatcher.on(event.test.started, (test) => {
      this.#artifacts = test.artifacts;
    });
  }

  /**
   * After test execution close browser context and add video to Allure report
   *
   */
  async _after() {
    const Playwright = container.helpers('Playwright');
    const allure = container.plugins('allure');
    await Playwright.browserContext.close();
    if (this.#artifacts.video) {
      output.debug(`Attaching a video: ${this.#artifacts.video}`);
      allure.addAttachment('Video', fs.readFileSync(this.#artifacts.video), 'video/webm');
    }
  }
}

module.exports = AllureVideoHelper;
  1. Add video: true in codeceptJS configuration file
Playwright: {
     ....
      video: true,
     ....
},
  1. Run test with a failure
  2. Run allure serve
  3. Check if video present as attach in allure report

Expected result
The video is present

Actual result
The video is NOT present

Desktop (please complete the following information):

  • OS: mac
  • Browser chrome
  • Version: doesn't matter
@dimas-rymera
Copy link

I have a similar issue with Cypress, code allure.attachment is not working when I put in hook afterEach
here is the sample code

afterEach(function () {
  let path = Cypress.spec.absolute.split('/cypress/tests/')[0]

  cy.readFile(`${path}/cypress/1.png`, null).then((file) => {
    allure.step('Get screenshot', () => {
      allure.attachment('fileName', file, "image/png");
    });
  });

This code will now show on the allure report..
Maybe someone can check it? or maybe you guys don't support this on this hook ?

@baev baev added this to the 3.0 milestone May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants