wdio-agent-reporter
Version:
Report Portal agent for WebdriverIO
111 lines (89 loc) • 3.05 kB
JavaScript
const WDIOReporter = require('@wdio/reporter');
const RPClient = require('reportportal-client-restler');
const { getClientInitObject, getStartLaunchObject, getSuiteStartObject, getTestStartObject } = require('./objectsUtils');
const promiseErrorHandler = promise => {
promise.catch(err => {
console.error(err);
});
};
class ReportPortalReporter extends WDIOReporter.default {
constructor (options) {
/**
* make reporter to write to output stream by default
*/
options = Object.assign(options, { stdout: true });
super(options);
this.reportOptions = getClientInitObject(options);
this.client = new RPClient(this.reportOptions);
this.objects = {};
this.tempLaunchId = null;
this.tempSuiteId = null;
this.tempTestId = null;
}
onRunnerStart () {
const startLaunchObj = getStartLaunchObject(this.reportOptions);
let { tempId, promise } = this.client.startLaunch(startLaunchObj);
this.tempLaunchId = tempId;
promiseErrorHandler(promise);
}
onScreenshot () {
// TODO: make it fun :)
}
onSuiteStart () {
const { tempId, promise } = this.client.startTestItem(getSuiteStartObject(suiteName),
this.tempLaunchId);
this.tempSuiteId = tempId;
promiseErrorHandler(promise);
}
onTestStart (test) {
const testName = test.title;
const testStartObj = getTestStartObject(testName),
{ tempId, promise } = this.client.startTestItem(testStartObj,
this.tempLaunchId,
this.tempSuiteId);
promiseErrorHandler(promise);
this.tempTestId = tempId;
}
onTestPass (test) {
console.log(test)
this.objects[test.id] = {
status: testItemStatuses.PASSED
}
}
onTestFail (test) {
console.log(test)
const failureMessage = "test.failureMessage";
this.objects[test.id] = {
status: testItemStatuses.FAILED
}
this._sendLog(failureMessage);
}
onTestSkip (test) {
this.objects[test.id] = {
status: 'skipped',
issue: { issue_type: 'NOT_ISSUE' }
}
}
onTestEnd (test) {
const finishTestObj = this.objects[test.id];
const { promise } = this.client.finishTestItem(this.tempTestId, finishTestObj);
promiseErrorHandler(promise);
}
onSuiteEnd () {
const { promise } = this.client.finishTestItem(this.tempSuiteId, {});
promiseErrorHandler(promise);
}
onRunnerEnd () {
const { promise } = this.client.finishLaunch(this.tempLaunchId);
promiseErrorHandler(promise);
}
_sendLog (message) {
let logObject = {
message: message,
level: logLevels.ERROR
};
const { promise } = this.client.sendLog(this.tempTestId, logObject);
promiseErrorHandler(promise);
}
};
module.exports = ReportPortalReporter;