appium-chromedriver
Version:
Node.js wrapper around chromedriver.
48 lines • 1.95 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.toW3cCapName = toW3cCapName;
exports.getCapValue = getCapValue;
exports.toW3cCapNames = toW3cCapNames;
const lodash_1 = __importDefault(require("lodash"));
const base_driver_1 = require("@appium/base-driver");
const W3C_PREFIX = 'goog:';
/**
* Converts a capability name to W3C format by adding the 'goog:' prefix if needed.
* @param capName - The capability name to convert.
* @returns The W3C-formatted capability name.
*/
function toW3cCapName(capName) {
return lodash_1.default.isString(capName) && !capName.includes(':') && !(0, base_driver_1.isStandardCap)(capName)
? `${W3C_PREFIX}${capName}`
: capName;
}
/**
* Gets a capability value from a capabilities object, handling both standard and W3C format names.
* @param allCaps - The capabilities object to search in.
* @param rawCapName - The capability name to look for (can be in either format).
* @param defaultValue - Optional default value to return if the capability is not found.
* @returns The capability value or the default value.
*/
function getCapValue(allCaps = {}, rawCapName, defaultValue) {
for (const [capName, capValue] of lodash_1.default.toPairs(allCaps)) {
if (toW3cCapName(capName) === toW3cCapName(rawCapName)) {
return capValue;
}
}
return defaultValue;
}
/**
* Converts all capability names in an object to W3C format.
* @param originalCaps - The original capabilities object.
* @returns A new object with W3C-formatted capability names.
*/
function toW3cCapNames(originalCaps = {}) {
return lodash_1.default.reduce(originalCaps, (acc, value, key) => {
acc[toW3cCapName(key)] = value;
return acc;
}, {});
}
//# sourceMappingURL=protocol-helpers.js.map