Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
mykola-mokhnach committed Jan 24, 2025
1 parent 581c679 commit 83bbccb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
24 changes: 11 additions & 13 deletions lib/chromedriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -527,16 +527,6 @@ export class Chromedriver extends events.EventEmitter {
* @returns {keyof PROTOCOLS}
*/
syncProtocol() {
if (_.includes(this._onlineStatus?.message, 'OperaDriver')) {
this.log.info(
`OperaDriver is known to not support ${PROTOCOLS.W3C} protocol, ` +
`defaulting to ${PROTOCOLS.MJSONWP}. ` +
`See https://github.com/operasoftware/operachromiumdriver/issues/88`
);
this._desiredProtocol = PROTOCOLS.MJSONWP;
return this._desiredProtocol;
}

if (this.driverVersion) {
const coercedVersion = semver.coerce(this.driverVersion);
if (!coercedVersion || coercedVersion.major < MIN_CD_VERSION_WITH_W3C_SUPPORT) {
Expand All @@ -549,15 +539,23 @@ export class Chromedriver extends events.EventEmitter {
}
}

// Check only chromeOptions for now.
const chromeOptions = getCapValue(this.capabilities, 'chromeOptions', {});
if (chromeOptions.w3c === false) {
const isOperaDriver = _.includes(this._onlineStatus?.message, 'OperaDriver');
const chromeOptions = getCapValue(this.capabilities, 'chromeOptions');
if (_.isPlainObject(chromeOptions) && chromeOptions.w3c === false) {
this.log.info(
`The ChromeDriver v. ${this.driverVersion} supports ${PROTOCOLS.W3C} protocol, ` +
`but ${PROTOCOLS.MJSONWP} one has been explicitly requested`,
);
this._desiredProtocol = PROTOCOLS.MJSONWP;
return this._desiredProtocol;
} else if (isOperaDriver) {
// OperaDriver needs the W3C protocol to be requested explcitly,
// otherwise it defaults to JWP
if (_.isPlainObject(chromeOptions)) {
chromeOptions.w3c = true;
} else {
this.capabilities['goog:chromeOptions'].w3c = true;
}
}

this._desiredProtocol = PROTOCOLS.W3C;
Expand Down
4 changes: 2 additions & 2 deletions lib/protocol-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ function toW3cCapName (capName) {
*
* @param {Record<string,any>} allCaps
* @param {string} rawCapName
* @param {any} defaultValue
* @returns
* @param {any} [defaultValue]
* @returns {any}
*/
function getCapValue (allCaps = {}, rawCapName, defaultValue) {
for (const [capName, capValue] of _.toPairs(allCaps)) {
Expand Down

0 comments on commit 83bbccb

Please sign in to comment.