Upload files to "qkf/selenium"

This commit is contained in:
2026-02-08 20:37:49 -06:00
parent 869d3508ab
commit 4bd0eb16fc

View File

@@ -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 };