From 4bd0eb16fcbc2285a9f18eea73c95125dfd1b64e Mon Sep 17 00:00:00 2001 From: "eric.pereyra" Date: Sun, 8 Feb 2026 20:37:49 -0600 Subject: [PATCH] Upload files to "qkf/selenium" --- qkf/selenium/qkfSelenium.js | 53 +++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 qkf/selenium/qkfSelenium.js diff --git a/qkf/selenium/qkfSelenium.js b/qkf/selenium/qkfSelenium.js new file mode 100644 index 0000000..294e27d --- /dev/null +++ b/qkf/selenium/qkfSelenium.js @@ -0,0 +1,53 @@ +// qkf/selenium/qkfSelenium.js +const { until } = require("selenium-webdriver"); + +function ms(n) { return n; } + +async function safeFind(driver, locator, timeoutMs = 15000) { + await driver.wait(until.elementLocated(locator), ms(timeoutMs)); + const el = await driver.findElement(locator); + await driver.wait(until.elementIsVisible(el), ms(timeoutMs)); + return el; +} + +function createQkfSelenium(driver, { defaultTimeoutMs = 15000 } = {}) { + return { + driver, + + async goto(url) { + await driver.get(url); + }, + + async enterValue(locator, value) { + const el = await safeFind(driver, locator, defaultTimeoutMs); + await el.clear(); + await el.sendKeys(String(value)); + }, + + async click(locator) { + const el = await safeFind(driver, locator, defaultTimeoutMs); + await el.click(); + }, + + async waitVisible(locator, timeoutMs = defaultTimeoutMs) { + const el = await safeFind(driver, locator, timeoutMs); + return el; + }, + + async getText(locator, timeoutMs = defaultTimeoutMs) { + const el = await safeFind(driver, locator, timeoutMs); + return await el.getText(); + }, + + async screenshotBase64() { + // returns base64 png (no data: prefix) + return await driver.takeScreenshot(); + }, + + async quit() { + await driver.quit(); + } + }; +} + +module.exports = { createQkfSelenium };