Created
September 10, 2024 08:46
-
-
Save Xotabu4/0b527198c34105611b8d0c6952d947de to your computer and use it in GitHub Desktop.
Helper methods for working with pw annotations
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'; | |
/** | |
* 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