systelab-components-wdio-test
Version:
Widgets to be use in the E2E Tests based in WDIO
87 lines (86 loc) • 2.89 kB
JavaScript
import { ApplicationManager } from './application-manager.js';
export var AutomationMode;
(function (AutomationMode) {
AutomationMode[AutomationMode["Runner"] = 0] = "Runner";
AutomationMode[AutomationMode["Standalone"] = 1] = "Standalone";
AutomationMode[AutomationMode["Remote"] = 2] = "Remote";
})(AutomationMode || (AutomationMode = {}));
export var BrowserType;
(function (BrowserType) {
BrowserType["Chrome"] = "Chrome";
BrowserType["Edge"] = "Edge";
BrowserType["Firefox"] = "Firefox";
BrowserType["Safari"] = "Safari";
BrowserType["WebKitGTK"] = "WebKitGTK";
BrowserType["TauriApp"] = "TauriApp";
})(BrowserType || (BrowserType = {}));
export class AutomationEnvironment {
static getMode() {
return this.mode;
}
static isLocalMode() {
return !this.isRemoteMode();
}
static isRemoteMode() {
return this.mode === AutomationMode.Remote;
}
static hasWorkingBrowser() {
if (this.mode === AutomationMode.Standalone) {
return !!(this.workingBrowser);
}
else {
return true;
}
}
static getWorkingBrowser() {
if (this.mode === AutomationMode.Standalone) {
if (this.workingBrowser) {
return this.workingBrowser;
}
else {
throw new Error('No working browser defined in WDIO standalone mode');
}
}
else {
return browser;
}
}
static setTestRunnerMode() {
this.mode = AutomationMode.Runner;
this.workingBrowser = null;
this.workingRemoteApplication = null;
}
static setStandaloneMode(workingBrowser) {
this.mode = AutomationMode.Standalone;
this.workingBrowser = workingBrowser;
this.workingRemoteApplication = null;
}
static getBrowserType() {
return this.browserType;
}
static setBrowserType(browserType) {
this.browserType = browserType;
}
static setApplication(applicationId) {
const application = ApplicationManager.get(applicationId);
if (application) {
this.setBrowserType(application.browserType);
this.setStandaloneMode(application.browser);
}
else {
throw new Error(`Application with id ${applicationId} not found`);
}
}
static getWorkingRemoteApplication() {
return this.workingRemoteApplication;
}
static setRemoteApplication(remoteApplication) {
this.mode = AutomationMode.Remote;
this.workingBrowser = null;
this.workingRemoteApplication = remoteApplication;
}
}
AutomationEnvironment.mode = AutomationMode.Runner;
AutomationEnvironment.workingBrowser = null;
AutomationEnvironment.browserType = BrowserType.Chrome;
AutomationEnvironment.workingRemoteApplication = null;