const BasePage = require('./BasePage'); class DashboardPage extends BasePage { constructor(driver) { super(driver); // Selectors for the Dashboard component this.selectors = { dashboard: '.dashboard', welcomeMessage: '.dashboard h2', userInfo: '.user-info', logoutButton: 'button[onclick*="logout"]' }; } async navigateToDashboard() { await this.navigateTo('/dashboard'); await this.waitForDashboard(); } async waitForDashboard() { await this.utils.waitForElementVisible(this.selectors.dashboard); } async isDashboardDisplayed() { try { // Wait up to 8 seconds for the dashboard to appear (longer for slow systems) await this.driver.wait( async () => { // Also wait for auth-container to disappear const authElements = await this.driver.findElements({ css: '.auth-container' }); const authVisible = authElements.length > 0 && await authElements[0].isDisplayed(); // Check for dashboard const dashboardElements = await this.driver.findElements({ css: this.selectors.dashboard }); const dashboardVisible = dashboardElements.length > 0 && await dashboardElements[0].isDisplayed(); // Dashboard should be visible AND auth container should be gone return !authVisible && dashboardVisible; }, 8000 ); return true; } catch (error) { // If waiting times out, check one more time without waiting try { const elements = await this.driver.findElements({ css: this.selectors.dashboard }); return elements.length > 0 && await elements[0].isDisplayed(); } catch (e) { return false; } } } async getWelcomeMessage() { try { return await this.getElementText(this.selectors.welcomeMessage); } catch (error) { return null; } } async getUserInfo() { try { return await this.getElementText(this.selectors.userInfo); } catch (error) { return null; } } async logout() { if (await this.isElementVisible(this.selectors.logoutButton)) { await this.clickElement(this.selectors.logoutButton); } } async waitForLogout() { // Wait for redirect away from dashboard await this.driver.wait( async () => { const currentUrl = await this.getCurrentUrl(); return !currentUrl.includes('/dashboard'); }, 10000, 'Logout did not redirect within expected time' ); } } module.exports = DashboardPage;