Skip to content

Instantly share code, notes, and snippets.

@korobochka
Last active January 11, 2019 14:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save korobochka/3c7c6b67f7745ac2a845f6ed362e5026 to your computer and use it in GitHub Desktop.
Save korobochka/3c7c6b67f7745ac2a845f6ed362e5026 to your computer and use it in GitHub Desktop.
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