const { By, until } = require('selenium-webdriver'); class TestUtils { constructor(driver) { this.driver = driver; } async waitForElement(selector, timeout = 10000) { const element = await this.driver.wait( until.elementLocated(By.css(selector)), timeout, `Element with selector '${selector}' not found within ${timeout}ms` ); return element; } async waitForElementVisible(selector, timeout = 10000) { const element = await this.waitForElement(selector, timeout); await this.driver.wait( until.elementIsVisible(element), timeout, `Element with selector '${selector}' not visible within ${timeout}ms` ); return element; } async waitForElementClickable(selector, timeout = 10000) { const element = await this.waitForElementVisible(selector, timeout); await this.driver.wait( until.elementIsEnabled(element), timeout, `Element with selector '${selector}' not clickable within ${timeout}ms` ); return element; } async waitForText(selector, text, timeout = 10000) { await this.driver.wait( until.elementTextContains( this.driver.findElement(By.css(selector)), text ), timeout, `Text '${text}' not found in element '${selector}' within ${timeout}ms` ); } async clearAndType(element, text) { await element.clear(); await element.sendKeys(text); } async scrollToElement(element) { await this.driver.executeScript('arguments[0].scrollIntoView(true);', element); // Small delay to ensure scroll completes await this.driver.sleep(500); } async takeScreenshot(filename) { const screenshot = await this.driver.takeScreenshot(); require('fs').writeFileSync(`screenshots/${filename}`, screenshot, 'base64'); } async getCurrentUrl() { return await this.driver.getCurrentUrl(); } async navigateTo(path) { const url = `${global.testConfig.baseUrl}${path}`; await this.driver.get(url); } async refreshPage() { await this.driver.navigate().refresh(); } async goBack() { await this.driver.navigate().back(); } } module.exports = TestUtils;