systelab-components-wdio-test
Version:
Widgets to be use in the E2E Tests based in WDIO
29 lines (28 loc) • 1.17 kB
JavaScript
import { HttpStatus } from './http-status';
import { ErrorHandlerAPI } from './error-handler.api';
import { AutomationEnvironment, Browser, ElementFinderBuilder } from '../../wdio';
import { JSONSchemaValidator } from './schema/json-schema-validator';
export class ScreenshotAPI {
static async takeAll(req, res) {
try {
AutomationEnvironment.setApplication(+req.params.id);
const screenshot = await Browser.takeScreenshot();
return res.status(HttpStatus.OK).json({ screenshot }).send();
}
catch (err) {
return ErrorHandlerAPI.handle(res, err);
}
}
static async takeElement(req, res) {
try {
AutomationEnvironment.setApplication(+req.params.id);
const requestBody = JSONSchemaValidator.validateBasicElementRequest(req.body);
const element = ElementFinderBuilder.build(requestBody.locators);
const screenshot = await element.takeScreenshot();
return res.status(HttpStatus.OK).json({ screenshot }).send();
}
catch (err) {
return ErrorHandlerAPI.handle(res, err);
}
}
}