Instantly share code, notes, and snippets.

Embed
What would you like to do?
Allure 2 Typescript step decorators
import { allure } from "../conf/protractorConf"; // export AllureInterface from the config file with onPrepare etc.
export function step(description: string): (...args: any[]) => TypedPropertyDescriptor<any> {
return (target: Object, key: string | symbol, descriptor: TypedPropertyDescriptor<any>): TypedPropertyDescriptor<any> => {
const original = descriptor.value;
descriptor.value = function(...args: any[]) {
// todo you can inject args into the description here if needed
return allure.step(description, () => {
console.log(`Running step: ${description}`);
return original.apply(this, args);
});
};
return descriptor;
};
}
// don't forget to set "compilerOptions": { "experimentalDecorators": true } in `tsconfig.json`
import { step } from "decorators";
class Page {
@step("Navigating to main page")
public go() {
return browser.get("http://example.com/");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment