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

Improve error handling #81

Open
OrKoN opened this issue Apr 6, 2022 · 3 comments
Open

Improve error handling #81

OrKoN opened this issue Apr 6, 2022 · 3 comments
Assignees

Comments

@OrKoN
Copy link
Collaborator

OrKoN commented Apr 6, 2022

For example, should the hooks like afterEach/afterAll be invoked when an error happens? I think it'd be expected if they are still invoked on errors.

@pbkompasz
Copy link

What is the status on this issue?
Can we maybe add an onError hook that is called if a step throws an error?

@davidlaprade
Copy link

+1 on adding an onError hook.

It'd be really great not to have to call runner.run() in a try block -- especially given how brittle some recordings can turn out to be on certain sites

@youhackme
Copy link

youhackme commented Oct 2, 2023

I ended up in the same situation and after hours of digging into this package code, I finally found the solution. We can capture the errors from WITHIN the extension by using the runStep hook, which runs every time a step is executed. Here's a simple example:

import {PuppeteerRunnerExtension, Step, getSelectorType, selectorToPElementSelector} from "@puppeteer/replay"

class ScreenshotExtension extends PuppeteerRunnerExtension {

    async runStep(step: Step, flow: UserFlow) {

        try {
            await super.runStep(step, flow)
        } catch (error) {
            let message = 'Unknown Error'
            if (error instanceof Error) message = error.message

            if (message.includes('waitForElement timed out')) {
                    throw new Error(`The selector(s) ${step.selectors.join()} is either not present or took too long to render.`)
            }
            throw new Error(message)
        }

    }
}

export default ScreenshotExtension;

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

5 participants