cybernaut
Version:
Reliable, zero configuration end-to-end testing in BDD-style.
123 lines • 5.11 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const uuidV4 = require("uuid/v4");
const fs_promise_1 = require("fs-promise");
const path_1 = require("path");
const utils_1 = require("./utils");
class Browser {
constructor(screenshotDirectory) {
this._screenshotDirectory = screenshotDirectory;
}
get pageTitle() {
return {
description: { template: 'page title' },
get: (driver) => tslib_1.__awaiter(this, void 0, void 0, function* () { return driver.getTitle(); })
};
}
get pageUrl() {
return {
description: { template: 'page url' },
get: (driver) => tslib_1.__awaiter(this, void 0, void 0, function* () { return driver.getCurrentUrl(); })
};
}
get windowX() {
return {
description: { template: 'window x-position' },
get: (driver) => tslib_1.__awaiter(this, void 0, void 0, function* () { return (yield driver.manage().window().getPosition()).x; })
};
}
get windowY() {
return {
description: { template: 'window y-position' },
get: (driver) => tslib_1.__awaiter(this, void 0, void 0, function* () { return (yield driver.manage().window().getPosition()).y; })
};
}
get windowWidth() {
return {
description: { template: 'window width' },
get: (driver) => tslib_1.__awaiter(this, void 0, void 0, function* () { return (yield driver.manage().window().getSize()).width; })
};
}
get windowHeight() {
return {
description: { template: 'window height' },
get: (driver) => tslib_1.__awaiter(this, void 0, void 0, function* () { return (yield driver.manage().window().getSize()).height; })
};
}
// tslint:disable-next-line no-any
scriptResult(scriptName, script) {
return {
description: { template: 'result of script {}', args: [scriptName] },
get: (driver) => tslib_1.__awaiter(this, void 0, void 0, function* () { return driver.executeAsyncScript(script); })
};
}
executeScript(scriptName, script) {
return {
description: { template: 'execute script {}', args: [scriptName] },
perform: (driver) => tslib_1.__awaiter(this, void 0, void 0, function* () { return void (yield driver.executeAsyncScript(script)); })
};
}
loadPage(url) {
return {
description: { template: 'load page {}', args: [url] },
perform: (driver) => tslib_1.__awaiter(this, void 0, void 0, function* () { return driver.navigate().to(url); })
};
}
maximizeWindow() {
return {
description: { template: 'maximize window' },
perform: (driver) => tslib_1.__awaiter(this, void 0, void 0, function* () { return driver.manage().window().maximize(); })
};
}
navigateBack() {
return {
description: { template: 'navigate back' },
perform: (driver) => tslib_1.__awaiter(this, void 0, void 0, function* () { return driver.navigate().back(); })
};
}
navigateForward() {
return {
description: { template: 'navigate forward' },
perform: (driver) => tslib_1.__awaiter(this, void 0, void 0, function* () { return driver.navigate().forward(); })
};
}
reloadPage() {
return {
description: { template: 'reload page' },
perform: (driver) => tslib_1.__awaiter(this, void 0, void 0, function* () { return driver.navigate().refresh(); })
};
}
setWindowPosition(x, y) {
return {
description: { template: 'set window position to {},{}', args: [x, y] },
perform: (driver) => tslib_1.__awaiter(this, void 0, void 0, function* () { return driver.manage().window().setPosition(x, y); })
};
}
setWindowSize(width, height) {
return {
description: {
template: 'set window size to {}x{}', args: [width, height]
},
perform: (driver) => tslib_1.__awaiter(this, void 0, void 0, function* () { return driver.manage().window().setSize(width, height); })
};
}
sleep(duration) {
return {
description: { template: 'sleep for {} ms', args: [duration] },
perform: () => tslib_1.__awaiter(this, void 0, void 0, function* () { return utils_1.sleep(duration); })
};
}
takeScreenshot() {
const filename = path_1.join(this._screenshotDirectory, uuidV4() + '.png');
return {
description: { template: 'take screenshot {}', args: [filename] },
perform: (driver) => tslib_1.__awaiter(this, void 0, void 0, function* () {
const screenshot = yield driver.takeScreenshot();
yield fs_promise_1.outputFile(filename, screenshot, { encoding: 'base64' });
})
};
}
}
exports.Browser = Browser;
//# sourceMappingURL=browser.js.map