Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow testCaseId to default to codeRef which is not affected by process path as prefix #218

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions lib/ReporterOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: ""};
}
36 changes: 36 additions & 0 deletions lib/__tests__/startSuite.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
});
});
2 changes: 1 addition & 1 deletion lib/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down