Skip to content

Instantly share code, notes, and snippets.

@Xotabu4
Created September 10, 2024 08:46
Show Gist options
  • Save Xotabu4/0b527198c34105611b8d0c6952d947de to your computer and use it in GitHub Desktop.
Save Xotabu4/0b527198c34105611b8d0c6952d947de to your computer and use it in GitHub Desktop.
Helper methods for working with pw annotations
import { test } from '@playwright/test';
/**
* Updates exsiting annotation or creates new one for current test
*
* @throws {Error} if called outside of test or before/after hooks
*/
export function setAnnotation(annotation: {
type: string;
description: string;
}): void {
const existingAnnotation = test
.info()
.annotations.find((a) => a.type === annotation.type);
if (existingAnnotation) {
existingAnnotation.description = annotation.description;
} else {
test.info().annotations.push(annotation);
}
}
/**
* Updates exsiting annotation or creates new one for current test
*
* @throws {Error} if called outside of test or before/after hooks
*/
export function setAnnotations(
annotations: Parameters<typeof setAnnotation>[0][],
): void {
for (const annotation of annotations) {
setAnnotation(annotation);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment