cybernaut
Version:
Reliable, automated web UI testing in BDD-style.
102 lines • 4.25 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const selenium_webdriver_1 = require("selenium-webdriver");
const element_1 = require("./element");
function defineElement(name, selector, index = 0) {
return new element_1.SeleniumElement([{ index, name, selector }]);
}
exports.defineElement = defineElement;
function elementCount(selector) {
const description = 'The count of matching elements ' +
`for the specified selector (${selector})`;
return {
description,
get: (driver) => tslib_1.__awaiter(this, void 0, void 0, function* () {
const elements = yield driver.findElements(selenium_webdriver_1.By.css(selector));
return elements.length;
})
};
}
exports.elementCount = elementCount;
function executeScript(scriptName, script) {
return {
description: `Execute the ${scriptName} script`,
perform: (driver) => tslib_1.__awaiter(this, void 0, void 0, function* () { return void (yield driver.executeAsyncScript(script)); })
};
}
exports.executeScript = executeScript;
function loadPage(url) {
return {
description: 'Load the page at ' + url,
perform: (driver) => tslib_1.__awaiter(this, void 0, void 0, function* () { return driver.navigate().to(url); })
};
}
exports.loadPage = loadPage;
function navigateBack() {
return {
description: 'Navigate back',
perform: (driver) => tslib_1.__awaiter(this, void 0, void 0, function* () { return driver.navigate().back(); })
};
}
exports.navigateBack = navigateBack;
function navigateForward() {
return {
description: 'Navigate forward',
perform: (driver) => tslib_1.__awaiter(this, void 0, void 0, function* () { return driver.navigate().forward(); })
};
}
exports.navigateForward = navigateForward;
exports.pageTitle = {
description: 'The title of the page',
get: (driver) => tslib_1.__awaiter(this, void 0, void 0, function* () { return driver.getTitle(); })
};
exports.pageUrl = {
description: 'The URL of the page',
get: (driver) => tslib_1.__awaiter(this, void 0, void 0, function* () { return driver.getCurrentUrl(); })
};
function reloadPage() {
return {
description: 'Reload the page',
perform: (driver) => tslib_1.__awaiter(this, void 0, void 0, function* () { return driver.navigate().refresh(); })
};
}
exports.reloadPage = reloadPage;
function scriptResult(scriptName, script) {
return {
description: `The result of the ${scriptName} script`,
get: (driver) => tslib_1.__awaiter(this, void 0, void 0, function* () { return driver.executeAsyncScript(script); })
};
}
exports.scriptResult = scriptResult;
function setWindowPosition(x, y) {
return {
description: `Set the window position to ${x},${y}`,
perform: (driver) => tslib_1.__awaiter(this, void 0, void 0, function* () { return driver.manage().window().setPosition(x, y); })
};
}
exports.setWindowPosition = setWindowPosition;
function setWindowSize(width, height) {
return {
description: `Set the window size to ${width}x${height}`,
perform: (driver) => tslib_1.__awaiter(this, void 0, void 0, function* () { return driver.manage().window().setSize(width, height); })
};
}
exports.setWindowSize = setWindowSize;
exports.windowHeight = {
description: 'The height of the window',
get: (driver) => tslib_1.__awaiter(this, void 0, void 0, function* () { return (yield driver.manage().window().getSize()).height; })
};
exports.windowWidth = {
description: 'The width of the window',
get: (driver) => tslib_1.__awaiter(this, void 0, void 0, function* () { return (yield driver.manage().window().getSize()).width; })
};
exports.windowXPosition = {
description: 'The X position of the window',
get: (driver) => tslib_1.__awaiter(this, void 0, void 0, function* () { return (yield driver.manage().window().getPosition()).x; })
};
exports.windowYPosition = {
description: 'The Y position of the window',
get: (driver) => tslib_1.__awaiter(this, void 0, void 0, function* () { return (yield driver.manage().window().getPosition()).y; })
};
//# sourceMappingURL=browser.js.map