import { STAGING_URL, PATHS, TIMEOUTS } from './config/staging-config'; import { test, expect } from '@playwright/test'; // Constants // STAGING_URL is now imported from config const LOGIN_URL = PATHS.login; const DASHBOARD_URL = PATHS.dashboard; const USERNAME = 'test_trainer'; const PASSWORD = 'Test123!'; // Test certificate navigation test('Navigate to certificate pages', async ({ page }) => { // Login await page.goto(LOGIN_URL); await page.fill('#user_login', USERNAME); await page.fill('#user_pass', PASSWORD); await page.click('#wp-submit'); await page.waitForLoadState('networkidle'); // Verify login successful expect(page.url()).toContain('hvac-dashboard'); // Navigate to Generate Certificates page const generateLink = page.locator('a:has-text("Generate Certificates")'); if (await generateLink.isVisible()) { await generateLink.click(); await page.waitForLoadState('networkidle'); // Check page title const genTitle = page.locator('h1:has-text("Generate Certificates")'); await expect(genTitle).toBeVisible(); // Go back to dashboard await page.goto(DASHBOARD_URL); await page.waitForLoadState('networkidle'); } else { console.log('Generate Certificates link not found, skipping'); } // Navigate to Certificate Reports page const reportsLink = page.locator('a:has-text("Certificate Reports")'); if (await reportsLink.isVisible()) { await reportsLink.click(); await page.waitForLoadState('networkidle'); // Check page title const reportsTitle = page.locator('h1:has-text("Certificate Reports")'); await expect(reportsTitle).toBeVisible(); // Check for filter form const filterForm = page.locator('form.hvac-certificate-filters'); if (await filterForm.isVisible()) { // Check if event filter exists const eventFilter = page.locator('#filter_event'); if (await eventFilter.isVisible()) { console.log('Event filter found'); } // Check if attendee search exists const attendeeSearch = page.locator('#search_attendee'); if (await attendeeSearch.isVisible()) { console.log('Attendee search found'); // Try a simple search await attendeeSearch.fill('test'); const filterButton = page.locator('button[type="submit"]'); if (await filterButton.isVisible()) { await filterButton.click(); await page.waitForLoadState('networkidle'); console.log('Filtered for "test"'); // Check for reset button const resetButton = page.locator('button[type="reset"]'); if (await resetButton.isVisible()) { await resetButton.click(); await page.waitForLoadState('networkidle'); console.log('Reset filters'); } } } } } else { console.log('Certificate Reports link not found, skipping'); } }); // Test certificate generation basics test('Certificate generation basics', async ({ page }) => { // Login await page.goto(LOGIN_URL); await page.fill('#user_login', USERNAME); await page.fill('#user_pass', PASSWORD); await page.click('#wp-submit'); await page.waitForLoadState('networkidle'); // Navigate to Generate Certificates page const generateLink = page.locator('a:has-text("Generate Certificates")'); if (await generateLink.isVisible()) { await generateLink.click(); await page.waitForLoadState('networkidle'); // Check for event dropdown const eventDropdown = page.locator('#event_id'); if (await eventDropdown.isVisible()) { // Count options to see if we have events const optionCount = await page.locator('#event_id option').count(); if (optionCount > 1) { // Select first non-empty option await eventDropdown.selectOption({ index: 1 }); await page.waitForLoadState('networkidle'); // Check for attendee list const attendeeList = page.locator('.hvac-attendee-list'); if (await attendeeList.isVisible()) { const attendeeCount = await page.locator('.hvac-attendee-item').count(); console.log(`Found ${attendeeCount} attendees`); if (attendeeCount > 0) { // Select first attendee const firstAttendee = page.locator('.hvac-attendee-item input[type="checkbox"]').first(); if (await firstAttendee.isVisible()) { await firstAttendee.check(); // Check for generate button const generateButton = page.locator('button:has-text("Generate Certificates")'); if (await generateButton.isVisible()) { console.log('Generate button found but not clicked for this test'); } } } } } else { console.log('No events available for certificate generation'); } } } });