mirror of
https://github.com/appium/appium.git
synced 2026-02-21 10:49:52 -06:00
chore(base-driver,base-plugin,execute-driver-plugin,fake-driver,fake-plugin,images-plugin): update some types for typedoc
This commit is contained in:
@@ -34,9 +34,9 @@ export function ExecuteMixin(Base) {
|
||||
}
|
||||
|
||||
const Driver = /** @type {DriverClass} */ (this.constructor);
|
||||
const availableScripts = _.keys(Driver.executeMethodMap);
|
||||
const commandMetadata = Driver.executeMethodMap[script];
|
||||
if (!commandMetadata) {
|
||||
const commandMetadata = {...Driver.executeMethodMap?.[script]};
|
||||
if (!commandMetadata.command) {
|
||||
const availableScripts = _.keys(Driver.executeMethodMap);
|
||||
throw new errors.UnsupportedOperationError(
|
||||
`Unsupported execute method '${script}'. Available methods ` +
|
||||
`are: ${availableScripts.join(', ')}`
|
||||
@@ -51,7 +51,7 @@ export function ExecuteMixin(Base) {
|
||||
checkParams(commandMetadata.params, args, null);
|
||||
}
|
||||
argsToApply = makeArgs({}, args, commandMetadata.params, null);
|
||||
return await this[Driver.executeMethodMap[script].command](...argsToApply);
|
||||
return await this[commandMetadata.command](...argsToApply);
|
||||
}
|
||||
}
|
||||
return ExecuteCommands;
|
||||
|
||||
@@ -29,7 +29,7 @@ class DriverCore {
|
||||
*/
|
||||
static baseVersion = BASEDRIVER_VER;
|
||||
|
||||
/** @type {ExecuteMethodMap} */
|
||||
/** @type {import('@appium/types').ExecuteMethodMap<DriverCore>} */
|
||||
static executeMethodMap = {};
|
||||
|
||||
/**
|
||||
@@ -420,7 +420,6 @@ export {DriverCore};
|
||||
/**
|
||||
* @typedef {import('@appium/types').Driver} Driver
|
||||
* @typedef {import('@appium/types').Constraints} Constraints
|
||||
* @typedef {import('@appium/types').ExecuteMethodMap} ExecuteMethodMap
|
||||
* @typedef {import('@appium/types').ServerArgs} ServerArgs
|
||||
* @typedef {import('@appium/types').EventHistory} EventHistory
|
||||
* @typedef {import('@appium/types').AppiumLogger} AppiumLogger
|
||||
|
||||
@@ -18,9 +18,8 @@ const SET_ALERT_TEXT_PAYLOAD_PARAMS = {
|
||||
* define the routes, mapping of HTTP methods to particular driver commands, and
|
||||
* any parameters that are expected in a request parameters can be `required` or
|
||||
* `optional`
|
||||
* @type {MethodMap}
|
||||
*/
|
||||
const METHOD_MAP = {
|
||||
const METHOD_MAP = /** @type {const} */ ({
|
||||
'/status': {
|
||||
GET: {command: 'getStatus'},
|
||||
},
|
||||
@@ -915,7 +914,7 @@ const METHOD_MAP = {
|
||||
},
|
||||
|
||||
//endregion
|
||||
};
|
||||
});
|
||||
|
||||
// driver command names
|
||||
let ALL_COMMANDS = [];
|
||||
@@ -1005,8 +1004,3 @@ function routeToCommandName(endpoint, method, basePath = DEFAULT_BASE_PATH) {
|
||||
const NO_SESSION_ID_COMMANDS = ['createSession', 'getStatus', 'getSessions'];
|
||||
|
||||
export {METHOD_MAP, ALL_COMMANDS, NO_SESSION_ID_COMMANDS, routeToCommandName};
|
||||
|
||||
/**
|
||||
* @typedef {import('@appium/types').Driver} Driver
|
||||
* @typedef {import('@appium/types').MethodMap} MethodMap
|
||||
*/
|
||||
|
||||
@@ -4,11 +4,11 @@ import {PROTOCOLS} from '../../../lib/constants';
|
||||
import {util} from '@appium/support';
|
||||
|
||||
class FakeDriver extends BaseDriver {
|
||||
static newMethodMap = {
|
||||
static newMethodMap = /** @type {const} */ ({
|
||||
'/session/:sessionId/noproxy': {
|
||||
GET: {command: 'notProxiedCommand', neverProxy: true},
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
@@ -10,10 +10,12 @@ class BasePlugin {
|
||||
* This will verify that the commands in the `newMethodMap` property are
|
||||
* valid. It is impossible to use a generic type param here; the type of this should really
|
||||
* be something like `MethodMap<T extends BasePlugin>` but that isn't a thing TS does.
|
||||
*
|
||||
* @type {import('@appium/types').MethodMap<any>}
|
||||
*/
|
||||
static newMethodMap = {};
|
||||
static newMethodMap = /** @type {const} */ ({
|
||||
'/session/:sessionId/plugin': {
|
||||
GET: {command: 'getPlugin'},
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
* @param {string} name
|
||||
|
||||
@@ -9,14 +9,14 @@ const DEFAULT_SCRIPT_TIMEOUT_MS = 1000 * 60 * 60; // default to 1 hour timeout
|
||||
const SCRIPT_TYPE_WDIO = 'webdriverio';
|
||||
|
||||
export default class ExecuteDriverPlugin extends BasePlugin {
|
||||
static newMethodMap = {
|
||||
static newMethodMap = /** @type {const} */ ({
|
||||
'/session/:sessionId/appium/execute_driver': {
|
||||
POST: {
|
||||
command: 'executeDriverScript',
|
||||
payloadParams: {required: ['script'], optional: ['type', 'timeout']},
|
||||
},
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
/**
|
||||
* This method takes a string which is executed as javascript in the context of
|
||||
|
||||
@@ -1,9 +1,22 @@
|
||||
// @ts-check
|
||||
|
||||
import B from 'bluebird';
|
||||
import _ from 'lodash';
|
||||
import {BaseDriver, errors} from 'appium/driver';
|
||||
import {FakeApp} from './fake-app';
|
||||
import commands from './commands';
|
||||
|
||||
const CONSTRAINTS = /** @type {const} */ ({
|
||||
app: {
|
||||
presence: true,
|
||||
isString: true,
|
||||
},
|
||||
uniqueApp: {
|
||||
isBoolean: true,
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
*/
|
||||
class FakeDriver extends BaseDriver {
|
||||
constructor(opts = {}, shouldValidateCaps = true) {
|
||||
super(opts, shouldValidateCaps);
|
||||
@@ -12,17 +25,11 @@ class FakeDriver extends BaseDriver {
|
||||
this.elMap = {};
|
||||
this.focusedElId = null;
|
||||
this.maxElId = 0;
|
||||
this.caps = {};
|
||||
this.fakeThing = null;
|
||||
this.cliArgs = {};
|
||||
this._proxyActive = false;
|
||||
|
||||
this.desiredCapConstraints = {
|
||||
app: {
|
||||
presence: true,
|
||||
isString: true,
|
||||
},
|
||||
};
|
||||
this.desiredCapConstraints = CONSTRAINTS;
|
||||
}
|
||||
|
||||
proxyActive() {
|
||||
@@ -46,6 +53,14 @@ class FakeDriver extends BaseDriver {
|
||||
return 'proxied via proxyCommand';
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {W3CCapabilities} jsonwpDesiredCapabilities
|
||||
* @param {W3CCapabilities} [jsonwpRequiredCaps]
|
||||
* @param {W3CCapabilities} [w3cCapabilities]
|
||||
* @param {import('@appium/types').DriverData[]} [otherSessionData]
|
||||
* @returns {Promise<[string, any]>}
|
||||
*/
|
||||
async createSession(
|
||||
jsonwpDesiredCapabilities,
|
||||
jsonwpRequiredCaps,
|
||||
@@ -66,16 +81,16 @@ class FakeDriver extends BaseDriver {
|
||||
}
|
||||
}
|
||||
|
||||
let [sessionId, caps] = await super.createSession(
|
||||
jsonwpDesiredCapabilities,
|
||||
jsonwpRequiredCaps,
|
||||
w3cCapabilities,
|
||||
otherSessionData
|
||||
);
|
||||
let [sessionId, caps] =
|
||||
/** @type {[string, import('@appium/types').DriverCaps<FakeDriver>]} */ (
|
||||
await super.createSession(
|
||||
jsonwpDesiredCapabilities,
|
||||
jsonwpRequiredCaps,
|
||||
w3cCapabilities,
|
||||
otherSessionData
|
||||
)
|
||||
);
|
||||
this.appModel = new FakeApp();
|
||||
if (_.isArray(caps) === true && caps.length === 1) {
|
||||
caps = caps[0];
|
||||
}
|
||||
this.caps = caps;
|
||||
await this.appModel.loadApp(caps.app);
|
||||
return [sessionId, caps];
|
||||
@@ -116,7 +131,7 @@ class FakeDriver extends BaseDriver {
|
||||
return this.cliArgs;
|
||||
}
|
||||
|
||||
static newMethodMap = {
|
||||
static newMethodMap = /** @type {const} */ ({
|
||||
'/session/:sessionId/fakedriver': {
|
||||
GET: {command: 'getFakeThing'},
|
||||
POST: {command: 'setFakeThing', payloadParams: {required: ['thing']}},
|
||||
@@ -124,9 +139,9 @@ class FakeDriver extends BaseDriver {
|
||||
'/session/:sessionId/fakedriverargs': {
|
||||
GET: {command: 'getFakeDriverArgs'},
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
static executeMethodMap = {
|
||||
static executeMethodMap = /** @type {const} */ ({
|
||||
'fake: addition': {
|
||||
command: 'fakeAddition',
|
||||
params: {required: ['num1', 'num2'], optional: ['num3']},
|
||||
@@ -138,7 +153,10 @@ class FakeDriver extends BaseDriver {
|
||||
command: 'setFakeThing',
|
||||
params: {required: ['thing']},
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
async fakeAddition(num1, num2, num3 = 0) {}
|
||||
|
||||
static fakeRoute(req, res) {
|
||||
res.send(JSON.stringify({fakedriver: 'fakeResponse'}));
|
||||
@@ -156,3 +174,13 @@ class FakeDriver extends BaseDriver {
|
||||
Object.assign(FakeDriver.prototype, commands);
|
||||
|
||||
export {FakeDriver};
|
||||
|
||||
/**
|
||||
* @typedef {import('@appium/types').W3CCapabilities} W3CCapabilities
|
||||
* @typedef {import('@appium/types').ExternalDriver} ExternalDriver
|
||||
*/
|
||||
|
||||
/**
|
||||
* @template {import('@appium/types').Driver} D
|
||||
* @typedef {import('@appium/types').DriverClass<D>} DriverClass
|
||||
*/
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
import * as driver from './driver';
|
||||
import * as server from './server';
|
||||
|
||||
const {FakeDriver} = driver;
|
||||
const {startServer} = server;
|
||||
import {FakeDriver} from './driver';
|
||||
import {startServer} from './server';
|
||||
|
||||
const DEFAULT_HOST = 'localhost';
|
||||
const DEFAULT_PORT = 4774;
|
||||
|
||||
@@ -79,6 +79,9 @@
|
||||
"fake-success": "./build/lib/scripts/fake-success.js"
|
||||
}
|
||||
},
|
||||
"typedoc": {
|
||||
"entryPoint": "./build/lib/index.js"
|
||||
},
|
||||
"types": "./build/lib/index.d.ts",
|
||||
"gitHead": "5c7af8ee73078018e4ec52fccf19fe3f77249d72"
|
||||
}
|
||||
|
||||
@@ -10,10 +10,7 @@ class FakePlugin extends BasePlugin {
|
||||
return this.cliArgs;
|
||||
}
|
||||
|
||||
/**
|
||||
* @type {import('@appium/types').MethodMap<FakePlugin>}
|
||||
*/
|
||||
static newMethodMap = {
|
||||
static newMethodMap = /** @type {const} */ ({
|
||||
'/session/:sessionId/fake_data': {
|
||||
GET: {command: 'getFakeSessionData', neverProxy: true},
|
||||
POST: {
|
||||
@@ -25,7 +22,7 @@ class FakePlugin extends BasePlugin {
|
||||
'/session/:sessionId/fakepluginargs': {
|
||||
GET: {command: 'getFakePluginArgs', neverProxy: true},
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
/** @type {string?} */
|
||||
static _unexpectedData = null;
|
||||
|
||||
@@ -24,7 +24,7 @@ export default class ImageElementPlugin extends BasePlugin {
|
||||
}
|
||||
|
||||
// this plugin supports a non-standard 'compare images' command
|
||||
static newMethodMap = {
|
||||
static newMethodMap = /** @type {const} */ ({
|
||||
'/session/:sessionId/appium/compare_images': {
|
||||
POST: {
|
||||
command: 'compareImages',
|
||||
@@ -35,7 +35,7 @@ export default class ImageElementPlugin extends BasePlugin {
|
||||
neverProxy: true,
|
||||
},
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
async compareImages(next, driver, ...args) {
|
||||
return await compareImages(...args);
|
||||
|
||||
Reference in New Issue
Block a user