Skip to content

Instantly share code, notes, and snippets.

@marcandrewb
Created November 1, 2025 16:43
Show Gist options
  • Select an option

  • Save marcandrewb/a072ac890d6c49bace5301a4ff1e769c to your computer and use it in GitHub Desktop.

Select an option

Save marcandrewb/a072ac890d6c49bace5301a4ff1e769c to your computer and use it in GitHub Desktop.
import {
PlaywrightTestArgs,
PlaywrightTestOptions,
PlaywrightWorkerArgs,
PlaywrightWorkerOptions,
TestType,
} from '@playwright/test';
export const afterEachTasks = (
test: TestType<
PlaywrightTestArgs & PlaywrightTestOptions,
PlaywrightWorkerArgs & PlaywrightWorkerOptions
>,
) => {
test.afterEach(async ({ page, context }, testInfo) => {
if (process.env.RUNNING_IN_BROWSERSTACK) {
if (testInfo.status) {
await page.evaluate(
(_) => {},
`browserstack_executor: ${JSON.stringify({
action: 'setSessionStatus',
arguments: { status: testInfo.status },
})}`,
);
}
}
context.pages().forEach(async (page) => {
await page.close();
});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment