systelab-components-wdio-test
Version:
Widgets to be use in the E2E Tests based in WDIO
68 lines (67 loc) • 2.83 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ApplicationAPI = void 0;
const http_status_1 = require("./http-status");
const error_handler_api_1 = require("./error-handler.api");
const wdio_1 = require("../../wdio");
const json_schema_validator_1 = require("./schema/json-schema-validator");
class ApplicationAPI {
static async start(req, res) {
try {
const requestBody = json_schema_validator_1.JSONSchemaValidator.validateApplicationStartRequest(req.body);
const application = await wdio_1.ApplicationManager.start(requestBody.browserType, requestBody.options);
return res.status(http_status_1.HttpStatus.CREATED).json({ id: application.id }).send();
}
catch (err) {
return error_handler_api_1.ErrorHandlerAPI.handle(res, err);
}
}
static async stop(req, res) {
try {
await wdio_1.ApplicationManager.stop(+req.params.id);
return res.status(http_status_1.HttpStatus.NO_CONTENT).send();
}
catch (err) {
return error_handler_api_1.ErrorHandlerAPI.handle(res, err);
}
}
static async navigate(req, res) {
try {
wdio_1.AutomationEnvironment.setApplication(+req.params.id);
const requestBody = json_schema_validator_1.JSONSchemaValidator.validateApplicationNavigateRequest(req.body);
await wdio_1.Browser.navigateToURL(requestBody.url);
return res.status(http_status_1.HttpStatus.NO_CONTENT).send();
}
catch (err) {
return error_handler_api_1.ErrorHandlerAPI.handle(res, err);
}
}
static async getName(req, res) {
try {
wdio_1.AutomationEnvironment.setApplication(+req.params.id);
return res.status(http_status_1.HttpStatus.OK).json({ name: await wdio_1.Browser.getName() }).send();
}
catch (err) {
return error_handler_api_1.ErrorHandlerAPI.handle(res, err);
}
}
static async getVersion(req, res) {
try {
wdio_1.AutomationEnvironment.setApplication(+req.params.id);
return res.status(http_status_1.HttpStatus.OK).json({ version: await wdio_1.Browser.getVersion() }).send();
}
catch (err) {
return error_handler_api_1.ErrorHandlerAPI.handle(res, err);
}
}
static async getOperatingSystem(req, res) {
try {
wdio_1.AutomationEnvironment.setApplication(+req.params.id);
return res.status(http_status_1.HttpStatus.OK).json({ os: await wdio_1.Browser.getOperatingSystem() }).send();
}
catch (err) {
return error_handler_api_1.ErrorHandlerAPI.handle(res, err);
}
}
}
exports.ApplicationAPI = ApplicationAPI;