Skip to content

Commit 499f65e

Browse files
authored
fix: start session should return caps that chromedriver returns (#362)
1 parent 44c757d commit 499f65e

File tree

1 file changed

+28
-21
lines changed

1 file changed

+28
-21
lines changed

lib/chromedriver.js

+28-21
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ export class Chromedriver extends events.EventEmitter {
138138
});
139139
this.log.debug(
140140
`Found ${util.pluralize('executable', executables.length, true)} ` +
141-
`in '${this.executableDir}'`
141+
`in '${this.executableDir}'`,
142142
);
143143
const cds = (
144144
await asyncmap(executables, async (executable) => {
@@ -148,7 +148,7 @@ export class Chromedriver extends events.EventEmitter {
148148
const logError = ({message, stdout, stderr}) => {
149149
let errMsg =
150150
`Cannot retrieve version number from '${path.basename(
151-
executable
151+
executable,
152152
)}' Chromedriver binary. ` +
153153
`Make sure it returns a valid version string in response to '--version' command line argument. ${message}`;
154154
if (stdout) {
@@ -219,7 +219,7 @@ export class Chromedriver extends events.EventEmitter {
219219
this.log.debug(
220220
` '${cd.executable}' (version '${cd.version}', minimum Chrome version '${
221221
cd.minChromeVersion ? cd.minChromeVersion : 'Unknown'
222-
}')`
222+
}')`,
223223
);
224224
}
225225
return cds;
@@ -313,7 +313,7 @@ export class Chromedriver extends events.EventEmitter {
313313
const err = /** @type {Error} */ (e);
314314
this.log.warn(
315315
`Cannot store the updated chromedrivers mapping into '${this.mappingPath}'. ` +
316-
`This may reduce the performance of further executions. Original error: ${err.message}`
316+
`This may reduce the performance of further executions. Original error: ${err.message}`,
317317
);
318318
}
319319
}
@@ -348,7 +348,7 @@ export class Chromedriver extends events.EventEmitter {
348348
const retrievedMapping = await this.storageClient.retrieveMapping();
349349
this.log.debug(
350350
'Got chromedrivers mapping from the storage: ' +
351-
_.truncate(JSON.stringify(retrievedMapping, null, 2), {length: 500})
351+
_.truncate(JSON.stringify(retrievedMapping, null, 2), {length: 500}),
352352
);
353353
const driverKeys = await this.storageClient.syncDrivers({
354354
minBrowserVersion: chromeVersion.major,
@@ -388,7 +388,7 @@ export class Chromedriver extends events.EventEmitter {
388388
`which ${
389389
_.size(missingVersions) === 1 ? 'is' : 'are'
390390
} missing in the list of known versions: ` +
391-
JSON.stringify(missingVersions)
391+
JSON.stringify(missingVersions),
392392
);
393393
await this.updateDriversMapping(Object.assign(mapping, missingVersions));
394394
}
@@ -397,15 +397,15 @@ export class Chromedriver extends events.EventEmitter {
397397
if (_.isEmpty(cds)) {
398398
this.log.errorAndThrow(
399399
`There must be at least one Chromedriver executable available for use if ` +
400-
`'chromedriverDisableBuildCheck' capability is set to 'true'`
400+
`'chromedriverDisableBuildCheck' capability is set to 'true'`,
401401
);
402402
}
403403
const {version, executable} = cds[0];
404404
this.log.warn(
405-
`Chrome build check disabled. Using most recent Chromedriver version (${version}, at '${executable}')`
405+
`Chrome build check disabled. Using most recent Chromedriver version (${version}, at '${executable}')`,
406406
);
407407
this.log.warn(
408-
`If this is wrong, set 'chromedriverDisableBuildCheck' capability to 'false'`
408+
`If this is wrong, set 'chromedriverDisableBuildCheck' capability to 'false'`,
409409
);
410410
return executable;
411411
}
@@ -416,12 +416,12 @@ export class Chromedriver extends events.EventEmitter {
416416
if (_.isEmpty(cds)) {
417417
this.log.errorAndThrow(
418418
`There must be at least one Chromedriver executable available for use if ` +
419-
`the current Chrome version cannot be determined`
419+
`the current Chrome version cannot be determined`,
420420
);
421421
}
422422
const {version, executable} = cds[0];
423423
this.log.warn(
424-
`Unable to discover Chrome version. Using Chromedriver ${version} at '${executable}'`
424+
`Unable to discover Chrome version. Using Chromedriver ${version} at '${executable}'`,
425425
);
426426
return executable;
427427
}
@@ -446,7 +446,7 @@ export class Chromedriver extends events.EventEmitter {
446446
} catch (e) {
447447
const err = /** @type {Error} */ (e);
448448
this.log.warn(
449-
`Cannot synchronize local chromedrivers with the remote storage: ${err.message}`
449+
`Cannot synchronize local chromedrivers with the remote storage: ${err.message}`,
450450
);
451451
this.log.debug(err.stack);
452452
}
@@ -456,18 +456,18 @@ export class Chromedriver extends events.EventEmitter {
456456
'a possible workaround.';
457457
throw new Error(
458458
`No Chromedriver found that can automate Chrome '${chromeVersion}'.` +
459-
(this.storageClient ? '' : ` ${autodownloadSuggestion}`)
459+
(this.storageClient ? '' : ` ${autodownloadSuggestion}`),
460460
);
461461
}
462462

463463
const binPath = matchingDrivers[0].executable;
464464
this.log.debug(
465465
`Found ${util.pluralize('executable', matchingDrivers.length, true)} ` +
466-
`capable of automating Chrome '${chromeVersion}'.\nChoosing the most recent, '${binPath}'.`
466+
`capable of automating Chrome '${chromeVersion}'.\nChoosing the most recent, '${binPath}'.`,
467467
);
468468
this.log.debug(
469469
'If a specific version is required, specify it with the `chromedriverExecutable`' +
470-
'desired capability.'
470+
'desired capability.',
471471
);
472472
return binPath;
473473
// eslint-disable-next-line no-constant-condition
@@ -492,7 +492,7 @@ export class Chromedriver extends events.EventEmitter {
492492
if (!(await fs.exists(chromedriver))) {
493493
throw new Error(
494494
`Trying to use a chromedriver binary at the path ` +
495-
`${this.chromedriver}, but it doesn't exist!`
495+
`${this.chromedriver}, but it doesn't exist!`,
496496
);
497497
}
498498
this.executableVerified = true;
@@ -514,7 +514,7 @@ export class Chromedriver extends events.EventEmitter {
514514
if (!coercedVersion || coercedVersion.major < MIN_CD_VERSION_WITH_W3C_SUPPORT) {
515515
this.log.debug(
516516
`The WebDriver v. ${this.driverVersion} does not fully support ${PROTOCOLS.W3C} protocol. ` +
517-
`Defaulting to ${PROTOCOLS.MJSONWP}`
517+
`Defaulting to ${PROTOCOLS.MJSONWP}`,
518518
);
519519
return;
520520
}
@@ -524,7 +524,7 @@ export class Chromedriver extends events.EventEmitter {
524524
if (chromeOptions.w3c === false) {
525525
this.log.info(
526526
`The WebDriver v. ${this.driverVersion} supports ${PROTOCOLS.W3C} protocol, ` +
527-
`but ${PROTOCOLS.MJSONWP} one has been explicitly requested`
527+
`but ${PROTOCOLS.MJSONWP} one has been explicitly requested`,
528528
);
529529
return;
530530
}
@@ -664,7 +664,7 @@ export class Chromedriver extends events.EventEmitter {
664664
// start subproc and wait for startDetector
665665
await this.proc.start(startDetector);
666666
await this.waitForOnline();
667-
await this.startSession();
667+
return await this.startSession();
668668
} catch (e) {
669669
const err = /** @type {Error} */ (e);
670670
this.log.debug(err);
@@ -737,11 +737,14 @@ export class Chromedriver extends events.EventEmitter {
737737
: {desiredCapabilities: this.capabilities};
738738
this.log.info(
739739
`Starting ${this.desiredProtocol} Chromedriver session with capabilities: ` +
740-
JSON.stringify(sessionCaps, null, 2)
740+
JSON.stringify(sessionCaps, null, 2),
741+
);
742+
const {capabilities} = /** @type {NewSessionResponse} */ (
743+
await this.jwproxy.command('/session', 'POST', sessionCaps)
741744
);
742-
await this.jwproxy.command('/session', 'POST', sessionCaps);
743745
this.log.prefix = generateLogPrefix(this, this.jwproxy.sessionId);
744746
this.changeState(Chromedriver.STATE_ONLINE);
747+
return capabilities;
745748
}
746749

747750
async stop(emitStates = true) {
@@ -864,3 +867,7 @@ Chromedriver.STATE_RESTARTING = 'restarting';
864867
/**
865868
* @typedef {import('./types').ChromedriverVersionMapping} ChromedriverVersionMapping
866869
*/
870+
871+
/**
872+
* @typedef {{capabilities: Record<string, any>}} NewSessionResponse
873+
*/

0 commit comments

Comments
 (0)