UNPKG

qajin

Version:

Playwright Test Runner Library

39 lines (28 loc) 1.26 kB
// utils/allure/global-setup.ts import { FullConfig, chromium } from '@playwright/test'; import { config as loadEnv } from 'dotenv'; import path from 'path'; import { cleanAllure } from './allure-extension'; // 1️⃣ Load environment variables from the appropriate .env file based on NODE_ENV const env = process.env.NODE_ENV ?? 'development'; const envFile = path.resolve( process.cwd(), `.env.${ env }` ); loadEnv( { path: envFile } ); console.log( `Loaded environment variables from ${ envFile }` ); // 2️⃣ Import the cleanup function for Allure export default async function globalSetup( config: FullConfig ) { // Clean existing Allure results and reports await cleanAllure(); // Read the URL from env const siteUrl = process.env.URL; console.log( `Global setup navigating to: ${ siteUrl }` ); if ( !siteUrl ) { throw new Error( 'Environment variable URL is not defined' ); } // Launch browser and setup context const browser = await chromium.launch(); const context = await browser.newContext(); const page = await context.newPage(); // Navigate to the site await page.goto( siteUrl, { timeout: 30_000 } ); // Return the browser context }