import { test, expect } from '@playwright/test'; import { CertificatePage } from './pages/CertificatePage'; import { DashboardPage } from './pages/DashboardPage'; import { LoginPage } from './pages/LoginPage'; import { CreateEventPage } from './pages/CreateEventPage'; import { EventSummaryPage } from './pages/EventSummaryPage'; import { CertificateTestData } from './utils/CertificateTestData'; import { Config } from './utils/Config'; // Full Trainer Journey Including Certificate Functionality test('Trainer journey with certificate functionality', async ({ page }) => { console.log('Starting trainer journey with certificates test...'); try { // STEP 1: Login as trainer console.log('Step 1: Logging in as trainer...'); const loginPage = new LoginPage(page); await loginPage.navigate(); await loginPage.login(Config.testTrainer.username, Config.testTrainer.password); // STEP 2: Navigate to dashboard console.log('Step 2: Accessing dashboard...'); const dashboardPage = new DashboardPage(page); await dashboardPage.navigate(); // Verify dashboard is accessible const isOnDashboard = await dashboardPage.isOnDashboard(); expect(isOnDashboard).toBeTruthy(); // STEP 3: Create a new event console.log('Step 3: Creating a new event...'); await dashboardPage.clickCreateEvent(); const createEventPage = new CreateEventPage(page); // Generate a unique event title with timestamp const timestamp = new Date().getTime(); const eventTitle = `Certificate Journey Test Event ${timestamp}`; // Fill event details await createEventPage.fillEventTitle(eventTitle); await createEventPage.fillEventDescription(`This is a test event for trainer journey with certificates ${timestamp}`); // Set event dates (future dates) const futureDate = new Date(); futureDate.setDate(futureDate.getDate() + 30); await createEventPage.setStartDate(futureDate.toLocaleDateString('en-US')); await createEventPage.setEndDate(futureDate.toLocaleDateString('en-US')); await createEventPage.setStartTime('10:00 AM'); await createEventPage.setEndTime('4:00 PM'); // Add ticket await createEventPage.addTicket('General Admission', '100'); // Submit the form const eventId = await createEventPage.submitForm(); expect(eventId).toBeTruthy(); console.log(`Event created with ID: ${eventId}`); // Wait for navigation to Event Summary await page.waitForLoadState('networkidle'); // STEP 4: Add test attendees console.log('Step 4: Adding test attendees...'); // Use the utility to create test attendees const testData = new CertificateTestData(page); await testData.createTestAttendees(eventId as string, 6); // STEP 5: Access dashboard to navigate to Certificate features console.log('Step 5: Returning to dashboard...'); await dashboardPage.navigate(); // STEP 6: Generate certificates console.log('Step 6: Generating certificates...'); await dashboardPage.clickGenerateCertificates(); const certificatePage = new CertificatePage(page); // Verify we're on generate certificates page const onGeneratePage = await certificatePage.isGenerateCertificatesPageVisible(); expect(onGeneratePage).toBeTruthy(); // Select our test event await certificatePage.selectEvent(eventTitle); // Get attendee counts const totalAttendees = await certificatePage.getAttendeeCount(); const checkedInAttendees = await certificatePage.getCheckedInAttendeeCount(); console.log(`Found ${totalAttendees} total attendees, ${checkedInAttendees} checked in`); expect(totalAttendees).toBeGreaterThan(0); // Select all attendees await certificatePage.selectAllAttendees(); // Generate certificates await certificatePage.generateCertificates(); // Check if successful const isSuccess = await certificatePage.isSuccessMessageVisible(); expect(isSuccess).toBeTruthy(); // STEP 7: Manage certificates console.log('Step 7: Managing certificates...'); await dashboardPage.navigate(); await dashboardPage.clickCertificateReports(); // Verify we're on certificate reports page const onReportsPage = await certificatePage.isCertificateReportsPageVisible(); expect(onReportsPage).toBeTruthy(); // Search for our event's certificates await certificatePage.searchCertificates(eventTitle); // Verify certificates exist const certificateCount = await certificatePage.getCertificateCount(); console.log(`Found ${certificateCount} certificates`); expect(certificateCount).toBeGreaterThan(0); // View a certificate if (certificateCount > 0) { console.log('Viewing certificate...'); await certificatePage.viewCertificate(0); await certificatePage.closePreview(); } } catch (error) { console.error('Error during trainer journey test:', error.message); // Take a screenshot for debugging await page.screenshot({ path: `${Config.screenshotPath}/error-trainer-journey.png` }); throw error; } console.log('Trainer journey with certificates completed successfully'); });