Skip to content

Commit

Permalink
sessionid and capabilities setup if auto_start_session set as false
Browse files Browse the repository at this point in the history
  • Loading branch information
harshit-bs committed Jun 30, 2023
1 parent 8b4d38d commit abfb459
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
1 change: 0 additions & 1 deletion cucumber-js/_setup_cucumber_runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ Before(function({pickle}) {
if (options.auto_start_session || typeof options.auto_start_session == 'undefined') {
return this.client.launchBrowser().then(browser => {
this.browser = browser;
NightwatchFormat.setBrowser(this.browser);
});
}
});
Expand Down
24 changes: 11 additions & 13 deletions cucumber-js/nightwatch-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ module.exports = class NightwatchFormatter extends Formatter {
this.report = {};

options.eventBroadcaster.on('envelope', (envelope) => {
if (NightwatchFormatter.browser && (!this.report.sessionId || NightwatchFormatter.browser?.sessionId !== this.report.sessionId)) {
this.setCapabilities();
if (NightwatchFormatter.sessionId && (!this.report.sessionId || NightwatchFormatter.sessionId !== this.report.sessionId)) {
this.report.sessionId = NightwatchFormatter.sessionId;
this.report.sessionCapabilities = NightwatchFormatter.sessionCapabilities;
}

this.reportHandler(envelope);
Expand All @@ -32,17 +33,9 @@ module.exports = class NightwatchFormatter extends Formatter {
NightwatchFormatter.client = client;
}

static setBrowser(browser) {
NightwatchFormatter.browser = browser;
}

setCapabilities() {
this.report = {
...this.report,
seleniumLogs: NightwatchFormatter.client?.transport?.driverService?.getSeleniumOutputFilePath(),
sessionCapabilities: NightwatchFormatter.browser?.capabilities,
sessionId: NightwatchFormatter.browser?.sessionId
};
static setCapabilities({sessionId, capabilities}) {
NightwatchFormatter.sessionId = sessionId;
NightwatchFormatter.sessionCapabilities = capabilities;
}

onMeta(meta) {
Expand All @@ -61,6 +54,10 @@ module.exports = class NightwatchFormatter extends Formatter {
this.report.pickle = [...(this.report.pickle || []), pickle];
}

onHook(hook) {
this.report.hooks = [...(this.report.hook || []), hook];
}

onSource(source) {
this.report.source = source;
}
Expand Down Expand Up @@ -169,6 +166,7 @@ module.exports = class NightwatchFormatter extends Formatter {
source: this.onSource,
stepDefinition: this.onStepDefinition,
testCase: this.onTestCase,
hook: this.onHook,
testCaseFinished: this.onTestCaseFinished,
testCaseStarted: this.onTestCaseStarted,
testRunFinished: this.onTestRunFinished,
Expand Down
9 changes: 9 additions & 0 deletions lib/transport/selenium-webdriver/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const CDP = require('./cdp.js');
const {colors} = Logger;
const {isErrorResponse, checkLegacyResponse, throwDecodedError, WebDriverError} = error;
const {IosSessionErrors} = require('../errors');
const NightwatchFormatter = require('../../../cucumber-js/nightwatch-format.js');
const {NightwatchEventHub} = require('../../runner/eventHub.js');

let _driverService = null;
let _driver = null;
Expand Down Expand Up @@ -296,6 +298,13 @@ class Transport extends BaseTransport {

this.__elementKey = elementKey;
await this.showConnectInfo({startTime, host, port, start_process, sessionInfo});

if (this.settings.test_runner?.type === 'cucumber' && NightwatchEventHub.isAvailable) {
NightwatchFormatter.setCapabilities({
sessionId,
capabilities
});
}

return {
sessionId,
Expand Down

0 comments on commit abfb459

Please sign in to comment.