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 when a test failed? #5

Open
damasofc opened this issue Dec 26, 2022 · 4 comments
Open

Screenshots when a test failed? #5

damasofc opened this issue Dec 26, 2022 · 4 comments

Comments

@damasofc
Copy link

damasofc commented Dec 26, 2022

This feature is really important please so we can get screenshots on the report when a test fails

I had this with detox:

const Allure = require('allure-js-commons'); // version "1.3.2",
const fs = require('fs');
const stripAnsi = require('strip-ansi');

class AllureReporterCircus {

  constructor({ detox }) {
    this.allure = new Allure();
    this.detox = detox;
  }

  run_describe_start(event) {
    if (event.describeBlock.parent !== undefined) {
      this.allure.startSuite(event.describeBlock.name);
    }
  }

  run_describe_finish(event) {
    if (event.describeBlock.parent !== undefined) {
      this.allure.endSuite();
    }
  }

  test_start(event) {
    const { test } = event;
    this.allure.startCase(test.name)
  }

  async test_done(event) {
    if (event.test.errors.length > 0) {
      const { test } = event;
      const screenshotPath = await this.detox.device.takeScreenshot(`${test.startedAt}-failed`);
      const buffer = fs.readFileSync(`${screenshotPath}`);
      this.allure.addAttachment('Screenshot test failue', Buffer.from(buffer, 'base64'), 'image/png');

      const err = test.errors[0][0];
      err.message = stripAnsi(err.message);
      err.stack = stripAnsi(err.stack);

      this.allure.endCase('failed', err);
    }
    else {
      this.allure.endCase('passed')
    }
  }

  test_skip(event) {
    const { test } = event;
    this.allure.startCase(test.name);
    this.allure.pendingCase(test.name);
  }
}

module.exports = AllureReporterCircus;

Is there a way I could have this with jest-allure2-reporter?

@noomorph
Copy link
Collaborator

noomorph commented Dec 28, 2022

Sure, I realize the importance of this feature.
This is blocked currenly by #4, and I plan to renew works on it very soon.

This is exactly the reason why wix/Detox#2337 is still open.

I'll leave your issue open for other people looking for the screenshots functionality so they don't create duplicates.

Thanks for checking out this repo. I hope it brings you joy soon.

@noomorph
Copy link
Collaborator

noomorph commented Oct 9, 2023

I think that ETA for Detox+Allure is likely to be around December 2023.

Today I released the alpha v2 of jest-allure2-reporter, but it will take some time to rewrite the artifacts subsystem in Detox so it can be easily integrated with it.

The rewrite is mostly about simplification of the source code of Detox, but since there's a huge piece of it (around 10k lines of code, AFAIR), it is not that trivial. 🫠

@professorkolik
Copy link

@noomorph any new ETA on this? thank you

@noomorph
Copy link
Collaborator

noomorph commented Nov 6, 2024

Have you checked this adapter, just in case?

https://github.com/wix-incubator/detox-allure2-adapter

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