Skip to content

Commit

Permalink
Feat/to integration (#18)
Browse files Browse the repository at this point in the history
* session capabilities fix for parallel in cucumber

(cherry picked from commit a787b37b37307d8e30ce2539721697c611235bb8)

* code refactoring
  • Loading branch information
harshit-bs committed Jul 25, 2023
1 parent e0f71e0 commit 03810e8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
4 changes: 3 additions & 1 deletion lib/runner/test-runners/cucumber/_setup_cucumber_runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ const NightwatchFormat = require('./nightwatch-format.js');

setDefaultTimeout(-1);

Before(function({pickle}) {
Before(function({pickle, testCaseStartedId}) {
const webdriver = {};

process.env.CUCUMBER_TEST_CASE_STARTED_ID = testCaseStartedId;

if (this.parameters['webdriver-host']) {
webdriver.host = this.parameters['webdriver-host'];
}
Expand Down
23 changes: 8 additions & 15 deletions lib/runner/test-runners/cucumber/nightwatch-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,23 @@ module.exports = class NightwatchFormatter extends Formatter {
}

static setCapabilities(data) {
data = {...data, testCaseStartedId: process.env.CUCUMBER_TEST_CASE_STARTED_ID};

if (isFunction(process.send)) {
process.send({'jsonEnvelope': SafeJSON.stringify({session: {...data, workerId: process.env.CUCUMBER_WORKER_ID}})});
process.send({'jsonEnvelope': SafeJSON.stringify({
session: {
...data,
workerId: process.env.CUCUMBER_WORKER_ID
}})});
} else {
NightwatchFormatter.eventBroadcaster?.emit('envelope', {session: data});
}
}

onSessionCapabilities(envelope) {
let testCaseStartedId;

if (envelope.workerId) {
const testStartedObj = Object.values(this.report.testCaseStarted).find(obj => obj.workerId === envelope.workerId);
testCaseStartedId = testStartedObj.id;
} else {
testCaseStartedId = NightwatchFormatter.testCaseStartedId;
}

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

this.report.session[testCaseStartedId] = {
...envelope,
testCaseStartedId: testCaseStartedId
};
this.report.session[envelope.testCaseStartedId] = envelope;
}

onMeta(meta) {
Expand Down Expand Up @@ -97,7 +91,6 @@ module.exports = class NightwatchFormatter extends Formatter {
onTestCaseStarted(result) {
this.report.testCaseStarted = this.report.testCaseStarted || {};
this.report.testCaseStarted[result.id] = result;
NightwatchFormatter.testCaseStartedId = result.id;

NightwatchEventHub.emit(TestCaseStarted, {
envelope: result,
Expand Down

0 comments on commit 03810e8

Please sign in to comment.