Skip to content

Instantly share code, notes, and snippets.

@unickq
Last active April 23, 2024 15:08
Show Gist options
  • Save unickq/ab7e920773f79ada57b49d11553d65a6 to your computer and use it in GitHub Desktop.
Save unickq/ab7e920773f79ada57b49d11553d65a6 to your computer and use it in GitHub Desktop.
Playwright typescript @step decorator
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