diff --git a/README.md b/README.md index 8cd9891..b63ba1f 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,7 @@ const conf = { cucumberNestedSteps: false, // report cucumber steps as Report Portal steps autoAttachCucumberFeatureToScenario: false, // requires cucumberNestedSteps to be true for use sanitizeErrorMessages: true, // strip color ascii characters from error stacktrace + useScenarioNameAsCodeRef: false, // For cucumber, opt to set codeRef and testCaseId to scenario name sauceLabOptions : { enabled: true, // automatically add SauseLab ID to rp tags. sldc: "US" // automatically add SauseLab region to rp tags. diff --git a/lib/ReporterOptions.ts b/lib/ReporterOptions.ts index f2bf220..d404df5 100644 --- a/lib/ReporterOptions.ts +++ b/lib/ReporterOptions.ts @@ -31,5 +31,6 @@ export default class ReporterOptions { public cucumberNestedSteps = false; public autoAttachCucumberFeatureToScenario = false; public sanitizeErrorMessages = true; + public useScenarioNameAsCodeRef = false; public reportPortalClientConfig = {mode: MODE.DEFAULT, attributes: [Attribute], description: ""}; } diff --git a/lib/__tests__/startSuite.spec.ts b/lib/__tests__/startSuite.spec.ts index 664de18..ec8030f 100644 --- a/lib/__tests__/startSuite.spec.ts +++ b/lib/__tests__/startSuite.spec.ts @@ -182,4 +182,40 @@ describe("startSuite", () => { id, ); }); + + test("should set codeRef to scenario name when useScenarioNameAsCodeRef option set to true", () => { + Object.assign(reporter.reporterOptions, {useScenarioNameAsCodeRef: true}); + reporter.sessionId = "bar"; + reporter.onSuiteStart(Object.assign(suiteStartEvent(), {type: CUCUMBER_TYPE.FEATURE})); + reporter.onSuiteStart(Object.assign(suiteStartEvent(), {type: CUCUMBER_TYPE.SCENARIO})); + + expect(reporter.client.startTestItem).toBeCalledTimes(2); + expect(reporter.client.startTestItem).toHaveBeenNthCalledWith( + 1, + { + description: "", + attributes: [], + name: "foo", + type: TYPE.TEST, + retry: false + }, + reporter.tempLaunchId, + null, + ); + + const {id} = reporter.storage.getCurrentSuite(); + expect(reporter.client.startTestItem).toHaveBeenNthCalledWith( + 2, + { + description: "", + attributes: [], + name: "foo", + type: TYPE.STEP, + retry: false, + codeRef: "" + }, + reporter.tempLaunchId, + id, + ); + }); }); diff --git a/lib/reporter.ts b/lib/reporter.ts index b9f30d7..323d248 100644 --- a/lib/reporter.ts +++ b/lib/reporter.ts @@ -133,7 +133,7 @@ class ReportPortalReporter extends Reporter { addSauceLabAttributes(this.reporterOptions, suiteStartObj, this.sessionId); } if (isCucumberScenario) { - suiteStartObj.codeRef = getRelativePath(this.specFilePath) + ':' + suite.uid.replace(suite.title, '').trim(); + suiteStartObj.codeRef = this.reporterOptions.useScenarioNameAsCodeRef ? suite.title : getRelativePath(this.specFilePath) + ':' + suite.uid.replace(suite.title, '').trim(); } if (this.reporterOptions.cucumberNestedSteps && this.reporterOptions.autoAttachCucumberFeatureToScenario) { switch (suite.type) {