Upload files to "qkf/selenium"
This commit is contained in:
53
qkf/selenium/qkfSelenium.js
Normal file
53
qkf/selenium/qkfSelenium.js
Normal 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 };
|
||||
Reference in New Issue
Block a user