UNPKG

systelab-components-wdio-test

Version:
29 lines (28 loc) 1.22 kB
import { HttpStatus } from "../server/http-status.js"; export class ApplicationRemoteClient { static async start(host, browserType, options) { const response = await this.executeEndpoint(host, 'start', { browserType, options }); const body = await response.json(); return body.id; } static async stop(application) { await this.executeEndpoint(application.host, `${application.remoteId}/stop`); } static async executeEndpoint(remoteHost, route, body = {}) { const host = remoteHost.name; const port = remoteHost.port; const apiPrefix = remoteHost.apiPrefix; const baseURL = `http://${host}:${port}/${apiPrefix}/applications`; const endpointURL = `${baseURL}/${route}`; const response = await fetch(endpointURL, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(body), }); if (response.status === HttpStatus.INTERNAL_SERVER_ERROR || response.status == HttpStatus.NOT_FOUND) { const errorMessage = response.body.error; throw new Error('Error: ' + errorMessage); } return response; } }