64 lines
No EOL
1.5 KiB
JavaScript
64 lines
No EOL
1.5 KiB
JavaScript
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() {
|
|
return await this.isElementVisible(this.selectors.dashboard);
|
|
}
|
|
|
|
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; |