systelab-components-wdio-test
Version:
Widgets to be use in the E2E Tests based in WDIO
49 lines (48 loc) • 1.84 kB
JavaScript
import allureReporter from '@wdio/allure-reporter';
import { Status } from "allure-js-commons";
export class ReportUtility {
static setDescription(description) {
allureReporter.addDescription(description, "text");
}
static setFeature(feature) {
allureReporter.addFeature(feature);
}
static addLabel(label, value) {
allureReporter.addLabel(label, value);
}
static addLink(url, name, type) {
allureReporter.addLink(url, name, type);
}
static async addExpectedResult(description, expectationFunction) {
const testCaseReporter = (jasmine.getEnv().testCaseReporter);
try {
if (testCaseReporter) {
testCaseReporter.onAssertStart(description);
}
allureReporter.startStep(description);
const initialFailedCount = jasmine.getEnv().currentJasmineSpec?.failedExpectations?.length || 0;
await expectationFunction();
const finalFailedCount = jasmine.getEnv().currentJasmineSpec?.failedExpectations?.length || 0;
const hasNewFailures = finalFailedCount > initialFailedCount;
if (hasNewFailures) {
allureReporter.endStep(Status.FAILED);
if (testCaseReporter) {
testCaseReporter.onAssertEnd(description, true);
}
}
else {
allureReporter.endStep(Status.PASSED);
if (testCaseReporter) {
testCaseReporter.onAssertEnd(description, false);
}
}
}
catch (error) {
allureReporter.endStep(Status.FAILED);
if (testCaseReporter) {
testCaseReporter.onAssertEnd(description, true);
}
throw (error);
}
}
}