Skip to content

Commit

Permalink
capabilities session issue fix
Browse files Browse the repository at this point in the history
  • Loading branch information
harshit-bs committed Aug 8, 2023
1 parent 9842ff7 commit be6a6ec
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 37 deletions.
65 changes: 28 additions & 37 deletions lib/runner/test-runners/cucumber/nightwatch-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ module.exports = class NightwatchFormatter extends Formatter {
static setCapabilities(data) {
data = {...data, testCaseStartedId: process.env.CUCUMBER_TEST_CASE_STARTED_ID};

// eslint-disable-next-line no-console
console.log('nightwatch_format_set_capability', 'PID:', process.pid, 'testCaseStartedId:', process.env.CUCUMBER_TEST_CASE_STARTED_ID);

if (isFunction(process.send)) {
process.send({'jsonEnvelope': SafeJSON.stringify({
session: {
Expand All @@ -42,9 +39,6 @@ module.exports = class NightwatchFormatter extends Formatter {
}

onSessionCapabilities(envelope) {
// eslint-disable-next-line no-console
console.log('nightwatch_format_onSessionCapabilities', 'PID:', process.pid, 'testCaseStartedId:', envelope.testCaseStartedId);

this.report.session = this.report.session || {};

this.report.session[envelope.testCaseStartedId] = envelope;
Expand Down Expand Up @@ -88,13 +82,6 @@ module.exports = class NightwatchFormatter extends Formatter {
this.report.testCaseFinished = this.report.testCaseFinished || {};
this.report.testCaseFinished[result.testCaseStartedId] = result;

if (!this.report.session[result.testCaseStartedId]) {
throw new Error('Session capabilities not found for', result.testCaseStartedId);
}

// eslint-disable-next-line no-console
console.log('nightwatch_format_onTestCaseFinished', 'PID:', process.pid, 'testCaseStartedId:', result.testCaseStartedId);

NightwatchEventHub.emit(TestCaseFinished, {
envelope: result,
report: this.report
Expand Down Expand Up @@ -152,31 +139,35 @@ module.exports = class NightwatchFormatter extends Formatter {
}

reportHandler(envelope) {
if (!NightwatchEventHub.isAvailable) {
return;
}

const handlers = {
meta: this.onMeta,
gherkinDocument: this.onGherkinDocument,
parseError: this.onParseError,
pickle: this.onPickle,
source: this.onSource,
stepDefinition: this.onStepDefinition,
testCase: this.onTestCase,
hook: this.onHook,
testCaseFinished: this.onTestCaseFinished,
testCaseStarted: this.onTestCaseStarted,
testRunFinished: this.onTestRunFinished,
testRunStarted: this.onTestRunStarted,
testStepFinished: this.onTestStepFinished,
testStepStarted: this.onTestStepStarted,
session: this.onSessionCapabilities
};
try {
if (!NightwatchEventHub.isAvailable) {
return;
}

const cucumberEvent = Object.keys(envelope)[0];
if (cucumberEvent && handlers[cucumberEvent]) {
handlers[cucumberEvent].call(this, envelope[cucumberEvent]);
const handlers = {
meta: this.onMeta,
gherkinDocument: this.onGherkinDocument,
parseError: this.onParseError,
pickle: this.onPickle,
source: this.onSource,
stepDefinition: this.onStepDefinition,
testCase: this.onTestCase,
hook: this.onHook,
testCaseFinished: this.onTestCaseFinished,
testCaseStarted: this.onTestCaseStarted,
testRunFinished: this.onTestRunFinished,
testRunStarted: this.onTestRunStarted,
testStepFinished: this.onTestStepFinished,
testStepStarted: this.onTestStepStarted,
session: this.onSessionCapabilities
};

const cucumberEvent = Object.keys(envelope)[0];
if (cucumberEvent && handlers[cucumberEvent]) {
handlers[cucumberEvent].call(this, envelope[cucumberEvent]);
}
} catch (err) {
Logger.error(err);
}
}
};
8 changes: 8 additions & 0 deletions lib/transport/selenium-webdriver/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,14 @@ class Transport extends BaseTransport {
const error = this.handleConnectError(err);
this.showConnectSpinner(colors.red(`Failed to connect to ${this.serviceName} on ${host} with ${colors.stack_trace(portStr)}.`), 'warn');

if (this.settings.test_runner?.type === 'cucumber' && NightwatchEventHub.isAvailable) {
const NightwatchFormatter = require('../../runner/test-runners/cucumber/nightwatch-format.js');

NightwatchFormatter.setCapabilities({
error: error
});
}

throw error;
}
}
Expand Down

0 comments on commit be6a6ec

Please sign in to comment.