Last active
April 23, 2024 15:08
-
-
Save unickq/ab7e920773f79ada57b49d11553d65a6 to your computer and use it in GitHub Desktop.
Playwright typescript @step decorator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { test } from "@playwright/test"; | |
export function step(title?: string) { | |
return function actualDecorator( | |
target: (this: any, ...args: any[]) => Promise<any>, | |
context: ClassMethodDecoratorContext, | |
) { | |
async function replacementMethod(this: any, ...args: any): Promise<any> { | |
const name = | |
title || | |
`${this.constructor.name}.${context.name as string}(${args.map((a: any) => JSON.stringify(a)).join(",")})`; | |
return test.step(name, async () => target.call(this, ...args), { box: true }); | |
} | |
return replacementMethod; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment