Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
syncProtocol (cdVersion = null) {
const coercedVersion = semver.coerce(cdVersion);
if (!coercedVersion || coercedVersion.major < MIN_CD_VERSION_WITH_W3C_SUPPORT) {
log.debug(`Chromedriver v. ${cdVersion} does not fully support ${PROTOCOLS.W3C} protocol. ` +
`Defaulting to ${PROTOCOLS.MJSONWP}`);
return;
}
const chromeOptions = getCapValue(this.capabilities, 'chromeOptions', {});
if (chromeOptions.w3c === false) {
log.info(`Chromedriver v. ${cdVersion} supports ${PROTOCOLS.W3C} protocol, ` +
`but ${PROTOCOLS.MJSONWP} one has been explicitly requested`);
return;
}
this.desiredProtocol = PROTOCOLS.W3C;
// given caps might not be properly prefixed
// so we try to fix them in order to properly init
// the new W3C session
this.capabilities = toW3cCapNames(this.capabilities);
}
syncProtocol (cdVersion = null) {
const coercedVersion = semver.coerce(cdVersion);
if (!coercedVersion || coercedVersion.major < MIN_CD_VERSION_WITH_W3C_SUPPORT) {
log.debug(`Chromedriver v. ${cdVersion} does not fully support ${PROTOCOLS.W3C} protocol. ` +
`Defaulting to ${PROTOCOLS.MJSONWP}`);
return;
}
const chromeOptions = getCapValue(this.capabilities, 'chromeOptions', {});
if (chromeOptions.w3c === false) {
log.info(`Chromedriver v. ${cdVersion} supports ${PROTOCOLS.W3C} protocol, ` +
`but ${PROTOCOLS.MJSONWP} one has been explicitly requested`);
return;
}
this.desiredProtocol = PROTOCOLS.W3C;
// given caps might not be properly prefixed
// so we try to fix them in order to properly init
// the new W3C session
this.capabilities = toW3cCapNames(this.capabilities);
}
async startSession () {
const sessionCaps = this.desiredProtocol === PROTOCOLS.W3C
? {capabilities: {alwaysMatch: this.capabilities}}
: {desiredCapabilities: this.capabilities};
log.info(`Starting ${this.desiredProtocol} Chromedriver session with capabilities: ` +
JSON.stringify(sessionCaps, null, 2));
// retry session start 4 times, sometimes this fails due to adb
await retryInterval(4, 200, async () => {
try {
await this.jwproxy.command('/session', 'POST', sessionCaps);
} catch (err) {
log.warn(`Failed to start Chromedriver session: ${err.message}`);
throw err;
}
});
this.changeState(Chromedriver.STATE_ONLINE);
}
function parseCapsForInnerDriver (jsonwpCapabilities, w3cCapabilities, constraints = {}, defaultCapabilities = {}) {
// Check if the caller sent JSONWP caps, W3C caps, or both
const hasW3CCaps = _.isPlainObject(w3cCapabilities) &&
(_.has(w3cCapabilities, 'alwaysMatch') || _.has(w3cCapabilities, 'firstMatch'));
const hasJSONWPCaps = _.isPlainObject(jsonwpCapabilities);
let protocol = null;
let desiredCaps = {};
let processedW3CCapabilities = null;
let processedJsonwpCapabilities = null;
if (!hasJSONWPCaps && !hasW3CCaps) {
return {
protocol: PROTOCOLS.W3C,
error: new Error('Either JSONWP or W3C capabilities should be provided'),
};
}
const {W3C, MJSONWP} = PROTOCOLS;
// Make sure we don't mutate the original arguments
jsonwpCapabilities = _.cloneDeep(jsonwpCapabilities);
w3cCapabilities = _.cloneDeep(w3cCapabilities);
defaultCapabilities = _.cloneDeep(defaultCapabilities);
if (!_.isEmpty(defaultCapabilities)) {
if (hasW3CCaps) {
const {firstMatch = [], alwaysMatch = {}} = w3cCapabilities;
for (const [defaultCapKey, defaultCapValue] of _.toPairs(defaultCapabilities)) {
let isCapAlreadySet = false;
syncProtocol (cdVersion = null) {
const coercedVersion = semver.coerce(cdVersion);
if (!coercedVersion || coercedVersion.major < MIN_CD_VERSION_WITH_W3C_SUPPORT) {
log.debug(`Chromedriver v. ${cdVersion} does not fully support ${PROTOCOLS.W3C} protocol. ` +
`Defaulting to ${PROTOCOLS.MJSONWP}`);
return;
}
const chromeOptions = getCapValue(this.capabilities, 'chromeOptions', {});
if (chromeOptions.w3c === false) {
log.info(`Chromedriver v. ${cdVersion} supports ${PROTOCOLS.W3C} protocol, ` +
`but ${PROTOCOLS.MJSONWP} one has been explicitly requested`);
return;
}
this.desiredProtocol = PROTOCOLS.W3C;
// given caps might not be properly prefixed
// so we try to fix them in order to properly init
// the new W3C session
this.capabilities = toW3cCapNames(this.capabilities);
}