-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Lifecycle event hooks support for v2 (#3817)
* Feat/to integration (#15) * implement lifecycle event hooks --------- Co-authored-by: Binayak Ghosh <[email protected]> (cherry picked from commit 5b3df0c) * remove suport for parallelism from cucumber (cherry picked from commit 45b4e24) * add tests (cherry picked from commit 687ab5c) * refactor (cherry picked from commit cf315db) * refactor usingCucumber param Co-authored-by: Harshit Agrawal <[email protected]> (cherry picked from commit dc35eaf) * modified tests (cherry picked from commit f5c482e) * SessionCapabilities handling in parallel mode (cherry picked from commit 4d2e57d) * bug fix: require cucumber only when needed * session capabilities fix for parallel in cucumber (cherry picked from commit a787b37b37307d8e30ce2539721697c611235bb8) * code refactoring (cherry picked from commit 315a2f1) * logs session capability logs (cherry picked from commit 9842ff7) * capabilities session issue fix (cherry picked from commit be6a6ec) * capabilities issue fix (cherry picked from commit 323c3940b9a57a6c750bc1ffc168de1cca711c1a) * handling the case when auto_start_session will be false (cherry picked from commit 0d5a9a0) * code refactoring for capabilities issue --------- Co-authored-by: Ravi Sawlani <[email protected]> Co-authored-by: Binayak Ghosh <[email protected]>
- Loading branch information
1 parent
2b8a604
commit 31902ee
Showing
29 changed files
with
1,053 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const EventEmitter = require('events'); | ||
const {Logger, createFolder} = require('../utils'); | ||
|
||
class NightwatchEventHub extends EventEmitter { | ||
emit(eventName, data) { | ||
if (this.isAvailable) { | ||
try { | ||
super.emit(eventName, data); | ||
} catch (err) { | ||
Logger.error(err); | ||
} | ||
} | ||
|
||
if (eventName === 'TestFinished' && this.output_folder && this.runner === 'cucumber') { | ||
let {output_folder} = this; | ||
output_folder = path.join(output_folder, 'cucumber'); | ||
const filename = path.join(output_folder, 'cucumber-report.json'); | ||
|
||
this.writeReportFile(filename, JSON.stringify(data.report, null, 2), true, output_folder) | ||
.then(_ => { | ||
Logger.info(Logger.colors.stack_trace(`Wrote JSON report file to: ${path.resolve(filename)}`)); | ||
}); | ||
} | ||
} | ||
|
||
get isAvailable() { | ||
return this.eventFnExist; | ||
} | ||
|
||
set isAvailable(eventFnExist) { | ||
this.eventFnExist = eventFnExist; | ||
} | ||
|
||
set runner(type) { | ||
this.runnerType = type; | ||
} | ||
|
||
get runner() { | ||
return this.runnerType; | ||
} | ||
|
||
writeReportFile(filename, rendered, shouldCreateFolder, output_folder) { | ||
return (shouldCreateFolder ? createFolder(output_folder) : Promise.resolve()) | ||
.then(() => { | ||
return new Promise((resolve, reject) => { | ||
fs.writeFile(filename, rendered, function(err) { | ||
if (err) { | ||
return reject(err); | ||
} | ||
|
||
resolve(); | ||
}); | ||
}); | ||
}); | ||
} | ||
} | ||
|
||
const instance = new NightwatchEventHub(); | ||
|
||
module.exports = { | ||
NightwatchEventHub: instance, | ||
COMMON_EVENTS: { | ||
ScreenshotCreated: 'ScreenshotCreated' | ||
}, | ||
DEFAULT_RUNNER_EVENTS: { | ||
GlobalHook: { | ||
before: { | ||
started: 'GlobalBeforeStarted', | ||
finished: 'GlobalBeforeFinished' | ||
}, | ||
|
||
beforeChildProcess: { | ||
started: 'GlobalBeforeChildProcessStarted', | ||
finished: 'GlobalBeforeChildProcessFinished' | ||
}, | ||
|
||
beforeEach: { | ||
started: 'GlobalBeforeEachStarted', | ||
finished: 'GlobalBeforeEachFinished' | ||
}, | ||
|
||
afterEach: { | ||
started: 'GlobalAfterEachStarted', | ||
finished: 'GlobalAfterEachFinished' | ||
}, | ||
|
||
afterChildProcess: { | ||
started: 'GlobalAfterChildProcessStarted', | ||
finished: 'GlobalAfterChildProcessFinished' | ||
}, | ||
|
||
after: { | ||
started: 'GlobalAfterStarted', | ||
finished: 'GlobalAfterFinished' | ||
} | ||
}, | ||
|
||
TestSuiteHook: { | ||
started: 'TestSuiteStarted', | ||
finished: 'TestSuiteFinished', | ||
|
||
before: { | ||
started: 'BeforeStarted', | ||
finished: 'BeforeFinished' | ||
}, | ||
|
||
beforeEach: { | ||
started: 'BeforeEachStarted', | ||
finished: 'BeforeEachFinished' | ||
}, | ||
|
||
test: { | ||
started: 'TestRunStarted', | ||
finished: 'TestRunFinished' | ||
}, | ||
|
||
afterEach: { | ||
started: 'AfterEachStarted', | ||
finished: 'AfterEachFinished' | ||
}, | ||
|
||
after: { | ||
started: 'AfterStarted', | ||
finished: 'AfterFinished' | ||
} | ||
}, | ||
|
||
LogCreated: 'LogCreated' | ||
}, | ||
CUCUMBER_RUNNER_EVENTS: { | ||
TestStarted: 'TestStarted', | ||
TestFinished: 'TestFinished', | ||
TestCaseStarted: 'TestCaseStarted', | ||
TestCaseFinished: 'TestCaseFinished', | ||
TestStepStarted: 'TestStepStarted', | ||
TestStepFinished: 'TestStepFinished' | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.