68 lines
No EOL
1.6 KiB
JavaScript
68 lines
No EOL
1.6 KiB
JavaScript
const { By } = require('selenium-webdriver');
|
|
const TestUtils = require('../config/test-utils');
|
|
|
|
class BasePage {
|
|
constructor(driver) {
|
|
this.driver = driver;
|
|
this.utils = new TestUtils(driver);
|
|
}
|
|
|
|
async navigateTo(path = '/') {
|
|
await this.utils.navigateTo(path);
|
|
await this.waitForPageLoad();
|
|
}
|
|
|
|
async waitForPageLoad() {
|
|
// Wait for React to mount
|
|
await this.driver.wait(
|
|
() => this.driver.executeScript('return document.readyState === "complete"'),
|
|
10000
|
|
);
|
|
|
|
// Additional wait for React components to render
|
|
await this.driver.sleep(1000);
|
|
}
|
|
|
|
async getCurrentUrl() {
|
|
return await this.utils.getCurrentUrl();
|
|
}
|
|
|
|
async getPageTitle() {
|
|
return await this.driver.getTitle();
|
|
}
|
|
|
|
async isElementPresent(selector) {
|
|
try {
|
|
await this.driver.findElement(By.css(selector));
|
|
return true;
|
|
} catch (error) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
async isElementVisible(selector) {
|
|
try {
|
|
const element = await this.driver.findElement(By.css(selector));
|
|
return await element.isDisplayed();
|
|
} catch (error) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
async getElementText(selector) {
|
|
const element = await this.utils.waitForElement(selector);
|
|
return await element.getText();
|
|
}
|
|
|
|
async clickElement(selector) {
|
|
const element = await this.utils.waitForElementClickable(selector);
|
|
await element.click();
|
|
}
|
|
|
|
async typeIntoElement(selector, text) {
|
|
const element = await this.utils.waitForElement(selector);
|
|
await this.utils.clearAndType(element, text);
|
|
}
|
|
}
|
|
|
|
module.exports = BasePage; |