added all files to project

This commit is contained in:
2022-03-10 10:36:59 +01:00
parent 09dd957b33
commit 46a936d7de
25351 changed files with 3883356 additions and 0 deletions
+39
View File
@@ -0,0 +1,39 @@
/// <reference types="webdriver" />
export declare function isW3C(capabilities?: WebDriver.DesiredCapabilities): boolean;
export declare function capabilitiesEnvironmentDetector(capabilities: WebDriver.Capabilities, automationProtocol: string): {
isChrome: boolean;
isMobile: boolean;
isIOS: boolean;
isAndroid: boolean;
isSauce: boolean;
};
export declare function sessionEnvironmentDetector({ capabilities, requestedCapabilities }: {
capabilities?: WebDriver.DesiredCapabilities;
requestedCapabilities?: WebDriver.DesiredCapabilities | WebDriver.W3CCapabilities;
}): {
isW3C: boolean;
isChrome: boolean;
isMobile: boolean;
isIOS: boolean;
isAndroid: boolean;
isSauce: boolean;
isSeleniumStandalone: boolean;
};
export declare function devtoolsEnvironmentDetector({ browserName }: WebDriver.Capabilities): {
isDevTools: boolean;
isW3C: boolean;
isMobile: boolean;
isIOS: boolean;
isAndroid: boolean;
isChrome: boolean;
isSauce: boolean;
isSeleniumStandalone: boolean;
};
export declare function webdriverEnvironmentDetector(capabilities: WebDriver.Capabilities): {
isChrome: boolean;
isMobile: boolean;
isIOS: boolean;
isAndroid: boolean;
isSauce: boolean;
};
//# sourceMappingURL=envDetector.d.ts.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"envDetector.d.ts","sourceRoot":"","sources":["../src/envDetector.ts"],"names":[],"mappings":";AAWA,wBAAgB,KAAK,CAAE,YAAY,CAAC,EAAE,SAAS,CAAC,mBAAmB,WA8BlE;AAuHD,wBAAgB,+BAA+B,CAAE,YAAY,EAAE,SAAS,CAAC,YAAY,EAAE,kBAAkB,EAAE,MAAM;;;;;;EAIhH;AAQD,wBAAgB,0BAA0B,CAAE,EAAE,YAAY,EAAE,qBAAqB,EAAE,EAAE;IAAE,YAAY,CAAC,EAAE,SAAS,CAAC,mBAAmB,CAAC;IAAC,qBAAqB,CAAC,EAAE,SAAS,CAAC,mBAAmB,GAAG,SAAS,CAAC,eAAe,CAAA;CAAE;;;;;;;;EAUvN;AAOD,wBAAgB,2BAA2B,CAAE,EAAE,WAAW,EAAE,EAAE,SAAS,CAAC,YAAY;;;;;;;;;EAWnF;AAQD,wBAAgB,4BAA4B,CAAE,YAAY,EAAE,SAAS,CAAC,YAAY;;;;;;EAQjF"}
+108
View File
@@ -0,0 +1,108 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.webdriverEnvironmentDetector = exports.devtoolsEnvironmentDetector = exports.sessionEnvironmentDetector = exports.capabilitiesEnvironmentDetector = exports.isW3C = void 0;
const MOBILE_BROWSER_NAMES = ['ipad', 'iphone', 'android'];
const MOBILE_CAPABILITIES = [
'appium-version', 'appiumVersion', 'device-type', 'deviceType',
'device-orientation', 'deviceOrientation', 'deviceName'
];
function isW3C(capabilities) {
if (!capabilities) {
return false;
}
const isAppium = Boolean(capabilities.automationName ||
capabilities.deviceName ||
capabilities.appiumVersion);
const hasW3CCaps = Boolean(capabilities.platformName &&
capabilities.browserVersion &&
(capabilities.platformVersion || Object.prototype.hasOwnProperty.call(capabilities, 'setWindowRect')));
return Boolean(hasW3CCaps || isAppium);
}
exports.isW3C = isW3C;
function isChrome(capabilities) {
if (!capabilities) {
return false;
}
return Boolean(capabilities.chrome || capabilities['goog:chromeOptions']);
}
function isMobile(capabilities) {
if (!capabilities) {
return false;
}
const browserName = (capabilities.browserName || '').toLowerCase();
return Boolean(Object.keys(capabilities).find((cap) => MOBILE_CAPABILITIES.includes(cap)) ||
capabilities.browserName === '' ||
MOBILE_BROWSER_NAMES.includes(browserName));
}
function isIOS(capabilities) {
if (!capabilities) {
return false;
}
return Boolean((capabilities.platformName && capabilities.platformName.match(/iOS/i)) ||
(capabilities.deviceName && capabilities.deviceName.match(/(iPad|iPhone)/i)));
}
function isAndroid(capabilities) {
if (!capabilities) {
return false;
}
return Boolean((capabilities.platformName && capabilities.platformName.match(/Android/i)) ||
(capabilities.browserName && capabilities.browserName.match(/Android/i)));
}
function isSauce(capabilities) {
if (!capabilities) {
return false;
}
const caps = capabilities.alwaysMatch
? capabilities.alwaysMatch
: capabilities;
return Boolean(caps.extendedDebugging ||
(caps['sauce:options'] &&
caps['sauce:options'].extendedDebugging));
}
function isSeleniumStandalone(capabilities) {
if (!capabilities) {
return false;
}
return Boolean(capabilities['webdriver.remote.sessionid']);
}
function capabilitiesEnvironmentDetector(capabilities, automationProtocol) {
return automationProtocol === 'devtools'
? devtoolsEnvironmentDetector(capabilities)
: webdriverEnvironmentDetector(capabilities);
}
exports.capabilitiesEnvironmentDetector = capabilitiesEnvironmentDetector;
function sessionEnvironmentDetector({ capabilities, requestedCapabilities }) {
return {
isW3C: isW3C(capabilities),
isChrome: isChrome(capabilities),
isMobile: isMobile(capabilities),
isIOS: isIOS(capabilities),
isAndroid: isAndroid(capabilities),
isSauce: isSauce(requestedCapabilities),
isSeleniumStandalone: isSeleniumStandalone(capabilities)
};
}
exports.sessionEnvironmentDetector = sessionEnvironmentDetector;
function devtoolsEnvironmentDetector({ browserName }) {
return {
isDevTools: true,
isW3C: true,
isMobile: false,
isIOS: false,
isAndroid: false,
isChrome: browserName === 'chrome',
isSauce: false,
isSeleniumStandalone: false,
};
}
exports.devtoolsEnvironmentDetector = devtoolsEnvironmentDetector;
function webdriverEnvironmentDetector(capabilities) {
return {
isChrome: isChrome(capabilities),
isMobile: isMobile(capabilities),
isIOS: isIOS(capabilities),
isAndroid: isAndroid(capabilities),
isSauce: isSauce(capabilities)
};
}
exports.webdriverEnvironmentDetector = webdriverEnvironmentDetector;
+10
View File
@@ -0,0 +1,10 @@
import initialisePlugin from './initialisePlugin';
import { initialiseWorkerService, initialiseLauncherService } from './initialiseServices';
import webdriverMonad from './monad';
import { commandCallStructure, isValidParameter, getArgumentType, safeRequire, isFunctionAsync, transformCommandLogResult, canAccess, sleep } from './utils';
import { wrapCommand, runFnInFiberContext, executeHooksWithArgs, hasWdioSyncSupport, executeSync, executeAsync } from './shim';
import { testFnWrapper, runTestInFiberContext } from './test-framework';
import { isW3C, capabilitiesEnvironmentDetector, sessionEnvironmentDetector, devtoolsEnvironmentDetector } from './envDetector';
import type { DefaultPropertyType } from './types';
export { initialisePlugin, initialiseLauncherService, initialiseWorkerService, isFunctionAsync, transformCommandLogResult, webdriverMonad, commandCallStructure, isValidParameter, getArgumentType, safeRequire, canAccess, sleep, wrapCommand, executeSync, executeAsync, runFnInFiberContext, runTestInFiberContext, testFnWrapper, executeHooksWithArgs, hasWdioSyncSupport, isW3C, sessionEnvironmentDetector, capabilitiesEnvironmentDetector, devtoolsEnvironmentDetector, DefaultPropertyType };
//# sourceMappingURL=index.d.ts.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,gBAAgB,MAAM,oBAAoB,CAAA;AACjD,OAAO,EAAE,uBAAuB,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAA;AACzF,OAAO,cAAc,MAAM,SAAS,CAAA;AACpC,OAAO,EACH,oBAAoB,EAAE,gBAAgB,EAAE,eAAe,EAAE,WAAW,EACpE,eAAe,EAAE,yBAAyB,EAAE,SAAS,EAAE,KAAK,EAC/D,MAAM,SAAS,CAAA;AAChB,OAAO,EACH,WAAW,EAAE,mBAAmB,EAAE,oBAAoB,EACtD,kBAAkB,EAAE,WAAW,EAAE,YAAY,EAChD,MAAM,QAAQ,CAAA;AACf,OAAO,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAA;AACvE,OAAO,EACH,KAAK,EAAE,+BAA+B,EACtC,0BAA0B,EAAE,2BAA2B,EAC1D,MAAM,eAAe,CAAA;AACtB,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAA;AAElD,OAAO,EACH,gBAAgB,EAChB,yBAAyB,EACzB,uBAAuB,EACvB,eAAe,EACf,yBAAyB,EACzB,cAAc,EACd,oBAAoB,EACpB,gBAAgB,EAChB,eAAe,EACf,WAAW,EACX,SAAS,EACT,KAAK,EAKL,WAAW,EACX,WAAW,EACX,YAAY,EACZ,mBAAmB,EACnB,qBAAqB,EACrB,aAAa,EACb,oBAAoB,EACpB,kBAAkB,EAKlB,KAAK,EACL,0BAA0B,EAC1B,+BAA+B,EAC/B,2BAA2B,EAK3B,mBAAmB,EACtB,CAAA"}
+37
View File
@@ -0,0 +1,37 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.devtoolsEnvironmentDetector = exports.capabilitiesEnvironmentDetector = exports.sessionEnvironmentDetector = exports.isW3C = exports.hasWdioSyncSupport = exports.executeHooksWithArgs = exports.testFnWrapper = exports.runTestInFiberContext = exports.runFnInFiberContext = exports.executeAsync = exports.executeSync = exports.wrapCommand = exports.sleep = exports.canAccess = exports.safeRequire = exports.getArgumentType = exports.isValidParameter = exports.commandCallStructure = exports.webdriverMonad = exports.transformCommandLogResult = exports.isFunctionAsync = exports.initialiseWorkerService = exports.initialiseLauncherService = exports.initialisePlugin = void 0;
const initialisePlugin_1 = __importDefault(require("./initialisePlugin"));
exports.initialisePlugin = initialisePlugin_1.default;
const initialiseServices_1 = require("./initialiseServices");
Object.defineProperty(exports, "initialiseWorkerService", { enumerable: true, get: function () { return initialiseServices_1.initialiseWorkerService; } });
Object.defineProperty(exports, "initialiseLauncherService", { enumerable: true, get: function () { return initialiseServices_1.initialiseLauncherService; } });
const monad_1 = __importDefault(require("./monad"));
exports.webdriverMonad = monad_1.default;
const utils_1 = require("./utils");
Object.defineProperty(exports, "commandCallStructure", { enumerable: true, get: function () { return utils_1.commandCallStructure; } });
Object.defineProperty(exports, "isValidParameter", { enumerable: true, get: function () { return utils_1.isValidParameter; } });
Object.defineProperty(exports, "getArgumentType", { enumerable: true, get: function () { return utils_1.getArgumentType; } });
Object.defineProperty(exports, "safeRequire", { enumerable: true, get: function () { return utils_1.safeRequire; } });
Object.defineProperty(exports, "isFunctionAsync", { enumerable: true, get: function () { return utils_1.isFunctionAsync; } });
Object.defineProperty(exports, "transformCommandLogResult", { enumerable: true, get: function () { return utils_1.transformCommandLogResult; } });
Object.defineProperty(exports, "canAccess", { enumerable: true, get: function () { return utils_1.canAccess; } });
Object.defineProperty(exports, "sleep", { enumerable: true, get: function () { return utils_1.sleep; } });
const shim_1 = require("./shim");
Object.defineProperty(exports, "wrapCommand", { enumerable: true, get: function () { return shim_1.wrapCommand; } });
Object.defineProperty(exports, "runFnInFiberContext", { enumerable: true, get: function () { return shim_1.runFnInFiberContext; } });
Object.defineProperty(exports, "executeHooksWithArgs", { enumerable: true, get: function () { return shim_1.executeHooksWithArgs; } });
Object.defineProperty(exports, "hasWdioSyncSupport", { enumerable: true, get: function () { return shim_1.hasWdioSyncSupport; } });
Object.defineProperty(exports, "executeSync", { enumerable: true, get: function () { return shim_1.executeSync; } });
Object.defineProperty(exports, "executeAsync", { enumerable: true, get: function () { return shim_1.executeAsync; } });
const test_framework_1 = require("./test-framework");
Object.defineProperty(exports, "testFnWrapper", { enumerable: true, get: function () { return test_framework_1.testFnWrapper; } });
Object.defineProperty(exports, "runTestInFiberContext", { enumerable: true, get: function () { return test_framework_1.runTestInFiberContext; } });
const envDetector_1 = require("./envDetector");
Object.defineProperty(exports, "isW3C", { enumerable: true, get: function () { return envDetector_1.isW3C; } });
Object.defineProperty(exports, "capabilitiesEnvironmentDetector", { enumerable: true, get: function () { return envDetector_1.capabilitiesEnvironmentDetector; } });
Object.defineProperty(exports, "sessionEnvironmentDetector", { enumerable: true, get: function () { return envDetector_1.sessionEnvironmentDetector; } });
Object.defineProperty(exports, "devtoolsEnvironmentDetector", { enumerable: true, get: function () { return envDetector_1.devtoolsEnvironmentDetector; } });
+3
View File
@@ -0,0 +1,3 @@
/// <reference types="webdriverio/webdriverio-core" />
export default function initialisePlugin(name: string, type?: string): WebdriverIO.ServicePlugin | WebdriverIO.RunnerPlugin;
//# sourceMappingURL=initialisePlugin.d.ts.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"initialisePlugin.d.ts","sourceRoot":"","sources":["../src/initialisePlugin.ts"],"names":[],"mappings":";AASA,MAAM,CAAC,OAAO,UAAU,gBAAgB,CAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,WAAW,CAAC,aAAa,GAAG,WAAW,CAAC,YAAY,CAqC3H"}
+30
View File
@@ -0,0 +1,30 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const path_1 = __importDefault(require("path"));
const utils_1 = require("./utils");
function initialisePlugin(name, type) {
if (name[0] === '@' || path_1.default.isAbsolute(name)) {
const service = utils_1.safeRequire(name);
if (service) {
return service;
}
}
if (typeof type !== 'string') {
throw new Error('No plugin type provided');
}
const scopedPlugin = utils_1.safeRequire(`@wdio/${name.toLowerCase()}-${type}`);
if (scopedPlugin) {
return scopedPlugin;
}
const plugin = utils_1.safeRequire(`wdio-${name.toLowerCase()}-${type}`);
if (plugin) {
return plugin;
}
throw new Error(`Couldn't find plugin "${name}" ${type}, neither as wdio scoped package ` +
`"@wdio/${name.toLowerCase()}-${type}" nor as community package ` +
`"wdio-${name.toLowerCase()}-${type}". Please make sure you have it installed!`);
}
exports.default = initialisePlugin;
+8
View File
@@ -0,0 +1,8 @@
/// <reference types="webdriverio/webdriverio-core" />
/// <reference types="webdriver" />
export declare function initialiseLauncherService(config: Omit<WebdriverIO.Config, 'capabilities' | keyof WebdriverIO.HookFunctions>, caps: WebDriver.DesiredCapabilities): {
ignoredWorkerServices: string[];
launcherServices: WebdriverIO.ServiceInstance[];
};
export declare function initialiseWorkerService(config: WebdriverIO.Config, caps: WebDriver.DesiredCapabilities, ignoredWorkerServices?: string[]): WebdriverIO.ServiceInstance[];
//# sourceMappingURL=initialiseServices.d.ts.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"initialiseServices.d.ts","sourceRoot":"","sources":["../src/initialiseServices.ts"],"names":[],"mappings":";;AA4FA,wBAAgB,yBAAyB,CAAE,MAAM,EAAE,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,cAAc,GAAG,MAAM,WAAW,CAAC,aAAa,CAAC,EAAE,IAAI,EAAE,SAAS,CAAC,mBAAmB;;;EAiDjK;AAUD,wBAAgB,uBAAuB,CAAE,MAAM,EAAE,WAAW,CAAC,MAAM,EAAE,IAAI,EAAE,SAAS,CAAC,mBAAmB,EAAE,qBAAqB,GAAE,MAAM,EAAO,GAAG,WAAW,CAAC,eAAe,EAAE,CA6B7K"}
+83
View File
@@ -0,0 +1,83 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.initialiseWorkerService = exports.initialiseLauncherService = void 0;
const logger_1 = __importDefault(require("@wdio/logger"));
const initialisePlugin_1 = __importDefault(require("./initialisePlugin"));
const log = logger_1.default('@wdio/utils:initialiseServices');
function initialiseServices(services) {
const initialisedServices = [];
for (let [serviceName, serviceConfig = {}] of services) {
if (typeof serviceName === 'object') {
log.debug('initialise custom initiated service');
initialisedServices.push([serviceName, {}]);
continue;
}
if (typeof serviceName === 'function') {
log.debug(`initialise custom service "${serviceName.name}"`);
initialisedServices.push([serviceName, serviceConfig]);
continue;
}
log.debug(`initialise service "${serviceName}" as NPM package`);
const service = initialisePlugin_1.default(serviceName, 'service');
initialisedServices.push([service, serviceConfig, serviceName]);
}
return initialisedServices;
}
function sanitizeServiceArray(service) {
return Array.isArray(service) ? service : [service, {}];
}
function initialiseLauncherService(config, caps) {
const ignoredWorkerServices = [];
const launcherServices = [];
try {
const services = initialiseServices(config.services.map(sanitizeServiceArray));
for (const [service, serviceConfig, serviceName] of services) {
if (typeof service === 'object' && !serviceName) {
launcherServices.push(service);
continue;
}
const Launcher = service.launcher;
if (typeof Launcher === 'function' && serviceName) {
launcherServices.push(new Launcher(serviceConfig, caps, config));
}
if (typeof service === 'function' && !serviceName) {
launcherServices.push(new service(serviceConfig, caps, config));
}
if (serviceName &&
typeof service.default !== 'function' &&
typeof service !== 'function') {
ignoredWorkerServices.push(serviceName);
}
}
}
catch (err) {
log.error(err);
}
return { ignoredWorkerServices, launcherServices };
}
exports.initialiseLauncherService = initialiseLauncherService;
function initialiseWorkerService(config, caps, ignoredWorkerServices = []) {
const workerServices = config.services
.map(sanitizeServiceArray)
.filter(([serviceName]) => !ignoredWorkerServices.includes(serviceName));
try {
const services = initialiseServices(workerServices);
return services.map(([service, serviceConfig, serviceName]) => {
if (typeof service === 'object' && !serviceName) {
return service;
}
const Service = service.default || service;
if (typeof Service === 'function') {
return new Service(serviceConfig, caps, config);
}
}).filter((service) => Boolean(service));
}
catch (err) {
log.error(err);
return [];
}
}
exports.initialiseWorkerService = initialiseWorkerService;
+9
View File
@@ -0,0 +1,9 @@
interface PropertiesObject {
[key: string]: PropertyDescriptor;
}
export default function WebDriver(options: Record<string, any>, modifier?: Function, propertiesObject?: PropertiesObject): {
(this: void, sessionId: string, commandWrapper?: Function | undefined): any;
lift(name: string, func: Function, proto: Record<string, any>, origCommand?: Function | undefined): void;
};
export {};
//# sourceMappingURL=monad.d.ts.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"monad.d.ts","sourceRoot":"","sources":["../src/monad.ts"],"names":[],"mappings":"AAUA,UAAU,gBAAgB;IACtB,CAAC,GAAG,EAAE,MAAM,GAAG,kBAAkB,CAAA;CACpC;AAED,MAAM,CAAC,OAAO,UAAU,SAAS,CAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,QAAQ,CAAC,EAAE,QAAQ,EAAE,gBAAgB,GAAE,gBAAqB;WAkBpG,IAAI,aAAa,MAAM;eAsHhB,MAAM,QAAQ,QAAQ,SAAS,OAAO,MAAM,EAAE,GAAG,CAAC;EAsCjF"}
+111
View File
@@ -0,0 +1,111 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const events_1 = require("events");
const logger_1 = __importDefault(require("@wdio/logger"));
const utils_1 = require("./utils");
const SCOPE_TYPES = {
browser: function Browser() { },
element: function Element() { }
};
function WebDriver(options, modifier, propertiesObject = {}) {
var _a;
const scopeType = SCOPE_TYPES[((_a = propertiesObject.scope) === null || _a === void 0 ? void 0 : _a.value) || 'browser'];
delete propertiesObject.scope;
const prototype = Object.create(scopeType.prototype);
const log = logger_1.default('webdriver');
const eventHandler = new events_1.EventEmitter();
const EVENTHANDLER_FUNCTIONS = Object.getPrototypeOf(eventHandler);
function unit(sessionId, commandWrapper) {
propertiesObject.commandList = { value: Object.keys(propertiesObject) };
propertiesObject.options = { value: options };
propertiesObject.requestedCapabilities = { value: options.requestedCapabilities };
if (typeof commandWrapper === 'function') {
for (const [commandName, { value }] of Object.entries(propertiesObject)) {
if (typeof value !== 'function') {
continue;
}
propertiesObject[commandName].value = commandWrapper(commandName, value);
propertiesObject[commandName].configurable = true;
}
}
utils_1.overwriteElementCommands.call(this, propertiesObject);
const { puppeteer, ...propertiesObjectWithoutPuppeteer } = propertiesObject;
propertiesObject['__propertiesObject__'] = { value: propertiesObjectWithoutPuppeteer };
let client = Object.create(prototype, propertiesObject);
client.sessionId = sessionId;
if (scopeType.name === 'Browser') {
client.capabilities = options.capabilities;
}
if (typeof modifier === 'function') {
client = modifier(client, options);
}
client.addCommand = function (name, func, attachToElement = false, proto, instances) {
const customCommand = typeof commandWrapper === 'function'
? commandWrapper(name, func)
: func;
if (attachToElement) {
if (instances) {
Object.values(instances).forEach(instance => {
instance.__propertiesObject__[name] = {
value: customCommand
};
});
}
this.__propertiesObject__[name] = { value: customCommand };
}
else {
unit.lift(name, customCommand, proto);
}
};
client.overwriteCommand = function (name, func, attachToElement = false, proto, instances) {
let customCommand = typeof commandWrapper === 'function'
? commandWrapper(name, func)
: func;
if (attachToElement) {
if (instances) {
Object.values(instances).forEach(instance => {
instance.__propertiesObject__.__elementOverrides__.value[name] = customCommand;
});
}
else {
this.__propertiesObject__.__elementOverrides__.value[name] = customCommand;
}
}
else if (client[name]) {
const origCommand = client[name];
delete client[name];
unit.lift(name, customCommand, proto, (...args) => origCommand.apply(this, args));
}
else {
throw new Error('overwriteCommand: no command to be overwritten: ' + name);
}
};
return client;
}
unit.lift = function (name, func, proto, origCommand) {
(proto || prototype)[name] = function next(...args) {
log.info('COMMAND', utils_1.commandCallStructure(name, args));
Object.defineProperty(func, 'name', {
value: name,
writable: false,
});
const result = func.apply(this, origCommand ? [origCommand, ...args] : args);
Promise.resolve(result).then((res) => {
log.info('RESULT', res);
this.emit('result', { name, result: res });
}).catch(() => { });
return result;
};
};
for (let eventCommand in EVENTHANDLER_FUNCTIONS) {
prototype[eventCommand] = function (...args) {
eventHandler[eventCommand](...args);
return this;
};
}
return unit;
}
exports.default = WebDriver;
+14
View File
@@ -0,0 +1,14 @@
declare let hasWdioSyncSupport: boolean;
declare let runSync: (this: unknown, fn: Function, repeatTest: any, args: unknown[]) => (resolve: Function, reject: Function) => unknown;
interface Retries {
limit: number;
attempts: number;
}
declare let executeHooksWithArgs: <T>(hookName: string, hooks?: Function | Function[], args?: any[]) => Promise<(Error | T)[]>;
declare let runFnInFiberContext: (fn: Function) => (this: any, ...args: any[]) => Promise<any>;
declare let wrapCommand: <T>(commandName: string, fn: Function) => (...args: any) => Promise<T>;
declare function executeSyncFn(this: any, fn: Function, retries: Retries, args?: any[]): Promise<unknown>;
declare function executeAsync(this: any, fn: Function, retries: Retries, args?: any[]): Promise<unknown>;
declare let executeSync: typeof executeSyncFn;
export { executeHooksWithArgs, runFnInFiberContext, wrapCommand, hasWdioSyncSupport, executeSync, executeAsync, runSync };
//# sourceMappingURL=shim.d.ts.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"shim.d.ts","sourceRoot":"","sources":["../src/shim.ts"],"names":[],"mappings":"AAKA,QAAA,IAAI,kBAAkB,SAAQ,CAAA;AAC9B,QAAA,IAAI,OAAO,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,UAAU,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,KAAK,OAAO,CAAA;AAEhI,UAAU,OAAO;IACb,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,MAAM,CAAA;CACnB;AAED,QAAA,IAAI,oBAAoB,gBAAyD,MAAM,UAAS,QAAQ,GAAG,QAAQ,EAAE,SAAa,GAAG,EAAE,2BA6CtI,CAAA;AAED,QAAA,IAAI,mBAAmB,OAAiB,QAAQ,YACrB,GAAG,WAAW,GAAG,EAAE,iBAG7C,CAAA;AAOD,QAAA,IAAI,WAAW,mBAAwC,MAAM,MAAM,QAAQ,eAAa,GAAG,eA8B1F,CAAA;AAUD,iBAAe,aAAa,CAAE,IAAI,EAAE,GAAG,EAAE,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,GAAE,GAAG,EAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAuB3G;AAUD,iBAAe,YAAY,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,GAAE,GAAG,EAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAazG;AAED,QAAA,IAAI,WAAW,sBAAgB,CAAA;AA0B/B,OAAO,EACH,oBAAoB,EACpB,mBAAmB,EACnB,WAAW,EACX,kBAAkB,EAClB,WAAW,EACX,YAAY,EACZ,OAAO,EACV,CAAA"}
+127
View File
@@ -0,0 +1,127 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.runSync = exports.executeAsync = exports.executeSync = exports.hasWdioSyncSupport = exports.wrapCommand = exports.runFnInFiberContext = exports.executeHooksWithArgs = void 0;
const logger_1 = __importDefault(require("@wdio/logger"));
const log = logger_1.default('@wdio/utils:shim');
let inCommandHook = false;
let hasWdioSyncSupport = false;
exports.hasWdioSyncSupport = hasWdioSyncSupport;
let runSync;
exports.runSync = runSync;
let executeHooksWithArgs = async function executeHooksWithArgsShim(hookName, hooks = [], args = []) {
if (!Array.isArray(hooks)) {
hooks = [hooks];
}
if (!Array.isArray(args)) {
args = [args];
}
const hooksPromises = hooks.map((hook) => new Promise((resolve) => {
let result;
try {
result = hook.apply(null, args);
}
catch (e) {
log.error(e.stack);
return resolve(e);
}
if (result && typeof result.then === 'function') {
return result.then(resolve, (e) => {
log.error(e.stack);
resolve(e);
});
}
resolve(result);
}));
const start = Date.now();
const result = await Promise.all(hooksPromises);
if (hooksPromises.length) {
log.debug(`Finished to run "${hookName}" hook in ${Date.now() - start}ms`);
}
return result;
};
exports.executeHooksWithArgs = executeHooksWithArgs;
let runFnInFiberContext = function (fn) {
return function (...args) {
return Promise.resolve(fn.apply(this, args));
};
};
exports.runFnInFiberContext = runFnInFiberContext;
let wrapCommand = function wrapCommand(commandName, fn) {
return async function wrapCommandFn(...args) {
const beforeHookArgs = [commandName, args];
if (!inCommandHook && this.options.beforeCommand) {
inCommandHook = true;
await executeHooksWithArgs.call(this, 'beforeCommand', this.options.beforeCommand, beforeHookArgs);
inCommandHook = false;
}
let commandResult;
let commandError;
try {
commandResult = await fn.apply(this, args);
}
catch (err) {
commandError = err;
}
if (!inCommandHook && this.options.afterCommand) {
inCommandHook = true;
const afterHookArgs = [...beforeHookArgs, commandResult, commandError];
await executeHooksWithArgs.call(this, 'afterCommand', this.options.afterCommand, afterHookArgs);
inCommandHook = false;
}
if (commandError) {
throw commandError;
}
return commandResult;
};
};
exports.wrapCommand = wrapCommand;
async function executeSyncFn(fn, retries, args = []) {
this.wdioRetries = retries.attempts;
try {
let res = fn.apply(this, args);
if (res instanceof Promise) {
return await res;
}
return res;
}
catch (e) {
if (retries.limit > retries.attempts) {
retries.attempts++;
return await executeSync.call(this, fn, retries, args);
}
return Promise.reject(e);
}
}
async function executeAsync(fn, retries, args = []) {
this.wdioRetries = retries.attempts;
try {
return await fn.apply(this, args);
}
catch (e) {
if (retries.limit > retries.attempts) {
retries.attempts++;
return await executeAsync.call(this, fn, retries, args);
}
throw e;
}
}
exports.executeAsync = executeAsync;
let executeSync = executeSyncFn;
exports.executeSync = executeSync;
try {
if (!process.env.WDIO_NO_SYNC_SUPPORT) {
const packageName = '@wdio/sync';
const wdioSync = require(packageName);
exports.hasWdioSyncSupport = hasWdioSyncSupport = true;
exports.runFnInFiberContext = runFnInFiberContext = wdioSync.runFnInFiberContext;
exports.wrapCommand = wrapCommand = wdioSync.wrapCommand;
exports.executeHooksWithArgs = executeHooksWithArgs = wdioSync.executeHooksWithArgs;
exports.executeSync = executeSync = wdioSync.executeSync;
exports.runSync = runSync = wdioSync.runSync;
}
}
catch (_a) {
}
+2
View File
@@ -0,0 +1,2 @@
export declare const logHookError: (hookName: string, hookResults: any[] | undefined, cid: string) => void;
//# sourceMappingURL=errorHandler.d.ts.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"errorHandler.d.ts","sourceRoot":"","sources":["../../src/test-framework/errorHandler.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,YAAY,aAAc,MAAM,uCAAgC,MAAM,SAwBlF,CAAA"}
+22
View File
@@ -0,0 +1,22 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.logHookError = void 0;
exports.logHookError = (hookName, hookResults = [], cid) => {
const result = hookResults.find(result => result instanceof Error);
if (typeof result === 'undefined') {
return;
}
const error = { message: result.message };
const content = {
cid: cid,
error: error,
fullTitle: `${hookName} Hook`,
type: 'hook',
state: 'fail'
};
process.send({
origin: 'reporter',
name: 'printFailureMessage',
content
});
};
+4
View File
@@ -0,0 +1,4 @@
import { testFnWrapper } from './testFnWrapper';
import { runTestInFiberContext } from './testInterfaceWrapper';
export { testFnWrapper, runTestInFiberContext };
//# sourceMappingURL=index.d.ts.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/test-framework/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAA;AAE9D,OAAO,EAAE,aAAa,EAAE,qBAAqB,EAAE,CAAA"}
+7
View File
@@ -0,0 +1,7 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.runTestInFiberContext = exports.testFnWrapper = void 0;
const testFnWrapper_1 = require("./testFnWrapper");
Object.defineProperty(exports, "testFnWrapper", { enumerable: true, get: function () { return testFnWrapper_1.testFnWrapper; } });
const testInterfaceWrapper_1 = require("./testInterfaceWrapper");
Object.defineProperty(exports, "runTestInFiberContext", { enumerable: true, get: function () { return testInterfaceWrapper_1.runTestInFiberContext; } });
+4
View File
@@ -0,0 +1,4 @@
import type { WrapperMethods, SpecFunction, BeforeHookParam, AfterHookParam } from './types';
export declare const testFnWrapper: (this: unknown, args_0: string, args_1: SpecFunction, args_2: BeforeHookParam<unknown>, args_3: AfterHookParam<unknown>, args_4: string, args_5: number) => Promise<unknown>;
export declare const testFrameworkFnWrapper: (this: unknown, { executeHooksWithArgs, executeAsync, runSync }: WrapperMethods, type: string, { specFn, specFnArgs }: SpecFunction, { beforeFn, beforeFnArgs }: BeforeHookParam<unknown>, { afterFn, afterFnArgs }: AfterHookParam<unknown>, cid: string, repeatTest?: number) => Promise<unknown>;
//# sourceMappingURL=testFnWrapper.d.ts.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"testFnWrapper.d.ts","sourceRoot":"","sources":["../../src/test-framework/testFnWrapper.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACR,cAAc,EACd,YAAY,EACZ,eAAe,EACf,cAAc,EAEjB,MAAM,SAAS,CAAA;AAahB,eAAO,MAAM,aAAa,SAChB,OAAO,8JAWhB,CAAA;AAcD,eAAO,MAAM,sBAAsB,SACzB,OAAO,mDACoC,cAAc,QACzD,MAAM,0BACY,YAAY,8BACR,gBAAgB,OAAO,CAAC,4BAC1B,eAAe,OAAO,CAAC,OAC5C,MAAM,0CAmDd,CAAA"}
+47
View File
@@ -0,0 +1,47 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.testFrameworkFnWrapper = exports.testFnWrapper = void 0;
const utils_1 = require("../utils");
const errorHandler_1 = require("./errorHandler");
const shim_1 = require("../shim");
exports.testFnWrapper = function (...args) {
return exports.testFrameworkFnWrapper.call(this, { executeHooksWithArgs: shim_1.executeHooksWithArgs, executeAsync: shim_1.executeAsync, runSync: shim_1.runSync }, ...args);
};
exports.testFrameworkFnWrapper = async function ({ executeHooksWithArgs, executeAsync, runSync }, type, { specFn, specFnArgs }, { beforeFn, beforeFnArgs }, { afterFn, afterFnArgs }, cid, repeatTest = 0) {
const retries = { attempts: 0, limit: repeatTest };
const beforeArgs = beforeFnArgs(this);
await errorHandler_1.logHookError(`Before${type}`, await executeHooksWithArgs(`before${type}`, beforeFn, beforeArgs), cid);
let promise;
let result;
let error;
if (utils_1.isFunctionAsync(specFn) || !runSync) {
promise = executeAsync.call(this, specFn, retries, specFnArgs);
}
else {
promise = new Promise(runSync.call(this, specFn, retries, specFnArgs));
}
const testStart = Date.now();
try {
result = await promise;
}
catch (err) {
error = err;
}
const duration = Date.now() - testStart;
let afterArgs = afterFnArgs(this);
if (!error && afterArgs[0] && afterArgs[0].failedExpectations && afterArgs[0].failedExpectations.length) {
error = afterArgs[0].failedExpectations[0];
}
afterArgs.push({
retries,
error,
result,
duration,
passed: !error
});
await errorHandler_1.logHookError(`After${type}`, await executeHooksWithArgs(`after${type}`, afterFn, [...afterArgs]), cid);
if (error) {
throw error;
}
return result;
};
@@ -0,0 +1,7 @@
/// <reference types="node" />
import type { HookFnArgs, SpecArguments } from './types';
export declare const runHook: (this: unknown, hookFn: Function, origFn: Function, beforeFn: Function | Function[], beforeFnArgs: HookFnArgs<unknown>, afterFn: Function | Function[], afterFnArgs: HookFnArgs<unknown>, cid: string, repeatTest: number) => any;
export declare const runSpec: (this: unknown, specTitle: string, specFn: Function, origFn: Function, beforeFn: Function | Function[], beforeFnArgs: HookFnArgs<unknown>, afterFn: Function | Function[], afterFnArgs: HookFnArgs<unknown>, cid: string, repeatTest: number) => any;
export declare const wrapTestFunction: (this: unknown, origFn: Function, isSpec: boolean, beforeFn: Function | Function[], beforeArgsFn: HookFnArgs<unknown>, afterFn: Function | Function[], afterArgsFn: HookFnArgs<unknown>, cid: string) => (...specArguments: SpecArguments) => any;
export declare const runTestInFiberContext: (this: unknown, isSpec: boolean, beforeFn: Function | Function[], beforeArgsFn: HookFnArgs<unknown>, afterFn: Function | Function[], afterArgsFn: HookFnArgs<unknown>, fnName: string, cid: string, scope?: NodeJS.Global & typeof globalThis) => void;
//# sourceMappingURL=testInterfaceWrapper.d.ts.map
@@ -0,0 +1 @@
{"version":3,"file":"testInterfaceWrapper.d.ts","sourceRoot":"","sources":["../../src/test-framework/testInterfaceWrapper.ts"],"names":[],"mappings":";AAWA,OAAO,KAAK,EACR,UAAU,EAIV,aAAa,EAChB,MAAM,SAAS,CAAA;AAkBhB,eAAO,MAAM,OAAO,SACV,OAAO,UACL,QAAQ,UACR,QAAQ,YACN,QAAQ,GAAG,QAAQ,EAAE,gBACjB,WAAW,OAAO,CAAC,WACxB,QAAQ,GAAG,QAAQ,EAAE,eACjB,WAAW,OAAO,CAAC,OAC3B,MAAM,cACC,MAAM,QAgCrB,CAAA;AAgBD,eAAO,MAAM,OAAO,SACV,OAAO,aACF,MAAM,UACT,QAAQ,UACR,QAAQ,YACN,QAAQ,GAAG,QAAQ,EAAE,gBACjB,WAAW,OAAO,CAAC,WACxB,QAAQ,GAAG,QAAQ,EAAE,eACjB,WAAW,OAAO,CAAC,OAC3B,MAAM,cACC,MAAM,QAgCrB,CAAA;AAeD,eAAO,MAAM,gBAAgB,SACnB,OAAO,UACL,QAAQ,UACR,OAAO,YACL,QAAQ,GAAG,QAAQ,EAAE,gBACjB,WAAW,OAAO,CAAC,WACxB,QAAQ,GAAG,QAAQ,EAAE,eACjB,WAAW,OAAO,CAAC,OAC3B,MAAM,wBAEwB,aAAa,QAkCnD,CAAA;AAgBD,eAAO,MAAM,qBAAqB,SACxB,OAAO,UACL,OAAO,YACL,QAAQ,GAAG,QAAQ,EAAE,gBACjB,WAAW,OAAO,CAAC,WACxB,QAAQ,GAAG,QAAQ,EAAE,eACjB,WAAW,OAAO,CAAC,UACxB,MAAM,OACT,MAAM,oDAad,CAAA"}
+61
View File
@@ -0,0 +1,61 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.runTestInFiberContext = exports.wrapTestFunction = exports.runSpec = exports.runHook = void 0;
const utils_1 = require("../utils");
const testFnWrapper_1 = require("./testFnWrapper");
const MOCHA_COMMANDS = ['skip', 'only'];
exports.runHook = function (hookFn, origFn, beforeFn, beforeFnArgs, afterFn, afterFnArgs, cid, repeatTest) {
return origFn(function (...hookFnArgs) {
return testFnWrapper_1.testFnWrapper.call(this, 'Hook', {
specFn: hookFn,
specFnArgs: utils_1.filterSpecArgs(hookFnArgs)
}, {
beforeFn,
beforeFnArgs
}, {
afterFn,
afterFnArgs
}, cid, repeatTest);
});
};
exports.runSpec = function (specTitle, specFn, origFn, beforeFn, beforeFnArgs, afterFn, afterFnArgs, cid, repeatTest) {
return origFn(specTitle, function (...specFnArgs) {
return testFnWrapper_1.testFnWrapper.call(this, 'Test', {
specFn,
specFnArgs: utils_1.filterSpecArgs(specFnArgs)
}, {
beforeFn,
beforeFnArgs
}, {
afterFn,
afterFnArgs
}, cid, repeatTest);
});
};
exports.wrapTestFunction = function (origFn, isSpec, beforeFn, beforeArgsFn, afterFn, afterArgsFn, cid) {
return function (...specArguments) {
let retryCnt = typeof specArguments[specArguments.length - 1] === 'number' ? specArguments.pop() : 0;
const specFn = typeof specArguments[0] === 'function' ? specArguments.shift()
: (typeof specArguments[1] === 'function' ? specArguments.pop() : undefined);
const specTitle = specArguments[0];
if (isSpec) {
if (specFn) {
return exports.runSpec(specTitle, specFn, origFn, beforeFn, beforeArgsFn, afterFn, afterArgsFn, cid, retryCnt);
}
return origFn(specTitle);
}
return exports.runHook(specFn, origFn, beforeFn, beforeArgsFn, afterFn, afterArgsFn, cid, retryCnt);
};
};
exports.runTestInFiberContext = function (isSpec, beforeFn, beforeArgsFn, afterFn, afterArgsFn, fnName, cid, scope = global) {
const origFn = scope[fnName];
scope[fnName] = exports.wrapTestFunction(origFn, isSpec, beforeFn, beforeArgsFn, afterFn, afterArgsFn, cid);
addMochaCommands(origFn, scope[fnName]);
};
function addMochaCommands(origFn, newFn) {
MOCHA_COMMANDS.forEach((commandName) => {
if (typeof origFn[commandName] === 'function') {
newFn[commandName] = origFn[commandName];
}
});
}
+36
View File
@@ -0,0 +1,36 @@
import type { executeHooksWithArgs, executeAsync, runSync } from '../shim';
export declare type HookFnArgs<T> = (ctx: T) => [unknown, T];
export interface WrapperMethods {
executeHooksWithArgs: typeof executeHooksWithArgs;
executeAsync: typeof executeAsync;
runSync: typeof runSync;
}
export interface SpecFunction {
specFn: Function;
specFnArgs: any[];
}
export interface BeforeHookParam<T> {
beforeFn: Function | Function[];
beforeFnArgs: HookFnArgs<T>;
}
export interface AfterHookParam<T> {
afterFn: Function | Function[];
afterFnArgs: HookFnArgs<T>;
}
export interface JasmineContext {
failedExpectations: Array<Record<string, unknown>>;
}
export declare type SpecArguments = ([
Function
] | [
Function,
number
] | [
string,
Function
] | [
string,
Function,
number
]);
//# sourceMappingURL=types.d.ts.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/test-framework/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAE1E,oBAAY,UAAU,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAA;AAEpD,MAAM,WAAW,cAAc;IAC3B,oBAAoB,EAAE,OAAO,oBAAoB,CAAA;IACjD,YAAY,EAAE,OAAO,YAAY,CAAA;IACjC,OAAO,EAAE,OAAO,OAAO,CAAA;CAC1B;AAED,MAAM,WAAW,YAAY;IACzB,MAAM,EAAE,QAAQ,CAAA;IAChB,UAAU,EAAE,GAAG,EAAE,CAAA;CACpB;AAED,MAAM,WAAW,eAAe,CAAC,CAAC;IAC9B,QAAQ,EAAE,QAAQ,GAAG,QAAQ,EAAE,CAAA;IAC/B,YAAY,EAAE,UAAU,CAAC,CAAC,CAAC,CAAA;CAC9B;AAED,MAAM,WAAW,cAAc,CAAC,CAAC;IAC7B,OAAO,EAAE,QAAQ,GAAG,QAAQ,EAAE,CAAA;IAC9B,WAAW,EAAE,UAAU,CAAC,CAAC,CAAC,CAAA;CAC7B;AAED,MAAM,WAAW,cAAc;IAC3B,kBAAkB,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAA;CACrD;AAED,oBAAY,aAAa,GAAG,CAIxB;IAAC,QAAQ;CAAC,GAIV;IAAC,QAAQ;IAAE,MAAM;CAAC,GAIlB;IAAC,MAAM;IAAE,QAAQ;CAAC,GAIlB;IAAC,MAAM;IAAE,QAAQ;IAAE,MAAM;CAAC,CAC7B,CAAA"}
+2
View File
@@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
+8
View File
@@ -0,0 +1,8 @@
export declare type DefaultPropertyType = {
type: string;
validate?: (param: any) => void;
required?: boolean;
default?: any;
match?: RegExp;
};
//# sourceMappingURL=types.d.ts.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,oBAAY,mBAAmB,GAAG;IAC9B,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,IAAI,CAAA;IAC/B,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,OAAO,CAAC,EAAE,GAAG,CAAA;IACb,KAAK,CAAC,EAAE,MAAM,CAAA;CACjB,CAAA"}
+2
View File
@@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
+22
View File
@@ -0,0 +1,22 @@
/// <reference types="webdriverio/webdriverio-core" />
export declare function overwriteElementCommands(propertiesObject: {
'__elementOverrides__'?: {
value: any;
};
[key: string]: any;
}): void;
export declare function commandCallStructure(commandName: string, args: any[]): string;
export declare function transformCommandLogResult(result: {
file?: string;
}): "\"<Screenshot[base64]>\"" | {
file?: string | undefined;
};
export declare function isValidParameter(arg: any, expectedType: string): boolean;
export declare function getArgumentType(arg: any): "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" | "null";
export declare function safeRequire(name: string): WebdriverIO.ServicePlugin | null;
export declare function isFunctionAsync(fn: Function): boolean;
export declare function filterSpecArgs(args: any[]): any[];
export declare function isBase64(str: string): boolean;
export declare const canAccess: (file: string) => boolean;
export declare const sleep: (ms?: number) => Promise<unknown>;
//# sourceMappingURL=utils.d.ts.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";AASA,wBAAgB,wBAAwB,CAAC,gBAAgB,EAAE;IAAE,sBAAsB,CAAC,EAAE;QAAE,KAAK,EAAE,GAAG,CAAA;KAAE,CAAC;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,QAsCzH;AAMD,wBAAgB,oBAAoB,CAAE,WAAW,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,UA+BrE;AAOD,wBAAgB,yBAAyB,CAAE,MAAM,EAAE;IAAE,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE;;EAMnE;AASD,wBAAgB,gBAAgB,CAAE,GAAG,EAAE,GAAG,EAAE,YAAY,EAAE,MAAM,WA8B/D;AAKD,wBAAgB,eAAe,CAAE,GAAG,EAAE,GAAG,wGAExC;AAQD,wBAAgB,WAAW,CAAE,IAAI,EAAE,MAAM,GAAG,WAAW,CAAC,aAAa,GAAG,IAAI,CAoC3E;AAOD,wBAAgB,eAAe,CAAE,EAAE,EAAE,QAAQ,WAE5C;AAMD,wBAAgB,cAAc,CAAE,IAAI,EAAE,GAAG,EAAE,SAE1C;AAOD,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,WAanC;AAOD,eAAO,MAAM,SAAS,SAAU,MAAM,YAWrC,CAAA;AAMD,eAAO,MAAM,KAAK,mCAAoD,CAAA"}
+169
View File
@@ -0,0 +1,169 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.sleep = exports.canAccess = exports.isBase64 = exports.filterSpecArgs = exports.isFunctionAsync = exports.safeRequire = exports.getArgumentType = exports.isValidParameter = exports.transformCommandLogResult = exports.commandCallStructure = exports.overwriteElementCommands = void 0;
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
const SCREENSHOT_REPLACEMENT = '"<Screenshot[base64]>"';
function overwriteElementCommands(propertiesObject) {
const elementOverrides = propertiesObject['__elementOverrides__'] ? propertiesObject['__elementOverrides__'].value : {};
for (const [commandName, userDefinedCommand] of Object.entries(elementOverrides)) {
if (typeof userDefinedCommand !== 'function') {
throw new Error('overwriteCommand: commands be overwritten only with functions, command: ' + commandName);
}
if (!propertiesObject[commandName]) {
throw new Error('overwriteCommand: no command to be overwritten: ' + commandName);
}
if (typeof propertiesObject[commandName].value !== 'function') {
throw new Error('overwriteCommand: only functions can be overwritten, command: ' + commandName);
}
const origCommand = propertiesObject[commandName].value;
delete propertiesObject[commandName];
const newCommand = function (...args) {
const element = this;
return userDefinedCommand.apply(element, [
function origCommandFunction() {
const context = this || element;
return origCommand.apply(context, arguments);
},
...args
]);
};
propertiesObject[commandName] = {
value: newCommand,
configurable: true
};
}
delete propertiesObject['__elementOverrides__'];
propertiesObject['__elementOverrides__'] = { value: {} };
}
exports.overwriteElementCommands = overwriteElementCommands;
function commandCallStructure(commandName, args) {
const callArgs = args.map((arg) => {
if (typeof arg === 'string' && (arg.startsWith('!function(') || arg.startsWith('return (function'))) {
arg = '<fn>';
}
else if (typeof arg === 'string' &&
!commandName.startsWith('findElement') &&
isBase64(arg)) {
arg = SCREENSHOT_REPLACEMENT;
}
else if (typeof arg === 'string') {
arg = `"${arg}"`;
}
else if (typeof arg === 'function') {
arg = '<fn>';
}
else if (arg === null) {
arg = 'null';
}
else if (typeof arg === 'object') {
arg = '<object>';
}
else if (typeof arg === 'undefined') {
arg = typeof arg;
}
return arg;
}).join(', ');
return `${commandName}(${callArgs})`;
}
exports.commandCallStructure = commandCallStructure;
function transformCommandLogResult(result) {
if (typeof result.file === 'string' && isBase64(result.file)) {
return SCREENSHOT_REPLACEMENT;
}
return result;
}
exports.transformCommandLogResult = transformCommandLogResult;
function isValidParameter(arg, expectedType) {
let shouldBeArray = false;
if (expectedType.slice(-2) === '[]') {
expectedType = expectedType.slice(0, -2);
shouldBeArray = true;
}
if (shouldBeArray) {
if (!Array.isArray(arg)) {
return false;
}
}
else {
arg = [arg];
}
for (const argEntity of arg) {
const argEntityType = getArgumentType(argEntity);
if (!argEntityType.match(expectedType)) {
return false;
}
}
return true;
}
exports.isValidParameter = isValidParameter;
function getArgumentType(arg) {
return arg === null ? 'null' : typeof arg;
}
exports.getArgumentType = getArgumentType;
function safeRequire(name) {
var _a, _b, _c;
let requirePath;
try {
const localNodeModules = path_1.default.join(process.cwd(), '/node_modules');
if (!((_a = require === null || require === void 0 ? void 0 : require.main) === null || _a === void 0 ? void 0 : _a.paths.includes(localNodeModules))) {
(_b = require === null || require === void 0 ? void 0 : require.main) === null || _b === void 0 ? void 0 : _b.paths.push(localNodeModules);
const requireOpts = process.env.JEST_WORKER_ID
? {}
: { paths: (_c = require === null || require === void 0 ? void 0 : require.main) === null || _c === void 0 ? void 0 : _c.paths };
requirePath = require.resolve(name, requireOpts);
}
else {
requirePath = require.resolve(name);
}
}
catch (e) {
return null;
}
try {
return require(requirePath);
}
catch (e) {
throw new Error(`Couldn't initialise "${name}".\n${e.stack}`);
}
}
exports.safeRequire = safeRequire;
function isFunctionAsync(fn) {
return (fn.constructor && fn.constructor.name === 'AsyncFunction') || fn.name === 'async';
}
exports.isFunctionAsync = isFunctionAsync;
function filterSpecArgs(args) {
return args.filter((arg) => typeof arg !== 'function');
}
exports.filterSpecArgs = filterSpecArgs;
function isBase64(str) {
var notBase64 = new RegExp('[^A-Z0-9+\\/=]', 'i');
if (typeof str !== 'string') {
throw new Error('Expected string but received invalid type.');
}
const len = str.length;
if (!len || len % 4 !== 0 || notBase64.test(str)) {
return false;
}
const firstPaddingChar = str.indexOf('=');
return firstPaddingChar === -1 ||
firstPaddingChar === len - 1 ||
(firstPaddingChar === len - 2 && str[len - 1] === '=');
}
exports.isBase64 = isBase64;
exports.canAccess = (file) => {
if (!file) {
return false;
}
try {
fs_1.default.accessSync(file);
return true;
}
catch (e) {
return false;
}
};
exports.sleep = (ms = 0) => new Promise((r) => setTimeout(r, ms));