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

how to take picture only when a jest test failed? #26

Open
adamchenwei opened this issue Aug 23, 2019 · 1 comment
Open

how to take picture only when a jest test failed? #26

adamchenwei opened this issue Aug 23, 2019 · 1 comment

Comments

@adamchenwei
Copy link

adamchenwei commented Aug 23, 2019

I researched this topic and saw a similar question in https://github.com/allure-framework/allure-jasmine/issues/10 and
But I wonder if this is something jest do or allure, or... jest-allure?
Is there some sort of each test on error event can be utilized in each description / it scope when onError without building another custom reporter?
I know I can take a screenshot by building another reporter (https://stackoverflow.com/questions/48388206/how-to-run-function-when-any-test-fails-jest)... but is that the only way to go in this case?

Thanks!

@andreabisello
Copy link

@adamchenwei
i'm using puppeeteer,
i use to try / catch every puppeteer method in a helper library and then i add a screenshot in the catch

for example

        try {
            const selectorScreenshot = await selectorImage.screenshot()
            await expect(selectorScreenshot).toMatchImageSnapshot({
                failureThreshold: 0,
                failureThresholdType: "percent",
                diffDirection: "vertical"
            })
        } catch (error) {
            const selectorScreenshot = await selectorImage.screenshot()
            reporter.addAttachment("imageShouldToBe", selectorScreenshot, "image/png");
            throw new Error(`unable to take screenshot ` + error)
        }

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

2 participants