Skip to content
This repository was archived by the owner on Nov 15, 2024. It is now read-only.

Commit 585a2b4

Browse files
committed
Merge remote-tracking branch 'origin/HotFixV4' into v4-hotfix
2 parents 69b4aa4 + 290d96a commit 585a2b4

File tree

1 file changed

+67
-56
lines changed

1 file changed

+67
-56
lines changed

src/main/java/com/epam/reportportal/cucumber/StepReporter.java

Lines changed: 67 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -49,71 +49,82 @@
4949
* @author Serhii Zharskyi
5050
*/
5151
public class StepReporter extends AbstractReporter {
52-
protected Maybe<String> currentStepId;
53-
protected Maybe<String> hookStepId;
54-
protected String hookStatus;
52+
protected Maybe<String> currentStepId;
53+
protected Maybe<String> hookStepId;
54+
protected String hookStatus;
5555

56-
public StepReporter() {
57-
super();
58-
currentStepId = null;
59-
hookStepId = null;
60-
hookStatus = null;
61-
}
56+
public StepReporter() {
57+
super();
58+
currentStepId = null;
59+
hookStepId = null;
60+
hookStatus = null;
61+
}
6262

63+
private String getType(RunningContext.FeatureContext context, Step step) {
64+
if (context.getBackground() != null) {
65+
if (context.getBackground().getSteps() == null) {
66+
return "STEP";
67+
} else {
68+
return context.getBackground().getSteps().contains(step) ? "BEFORE_TEST" : "STEP";
69+
}
70+
} else {
71+
return "STEP";
72+
}
73+
}
6374

64-
@Override
65-
protected Maybe<String> getRootItemId() {
66-
return null;
67-
}
75+
@Override
76+
protected Maybe<String> getRootItemId() {
77+
return null;
78+
}
6879

69-
@Override
70-
protected void beforeStep(TestStep testStep) {
71-
Step step = currentScenarioContext.getStep(testStep);
72-
StartTestItemRQ rq = new StartTestItemRQ();
73-
rq.setName(Utils.buildNodeName(currentScenarioContext.getStepPrefix(), step.getKeyword(), testStep.getStepText(), " "));
74-
rq.setDescription(Utils.buildMultilineArgument(testStep));
75-
rq.setStartTime(Calendar.getInstance().getTime());
76-
rq.setType("STEP");
77-
currentStepId = RP.get().startTestItem(currentScenarioContext.getId(), rq);
78-
}
80+
@Override
81+
protected void beforeStep(TestStep testStep) {
82+
Step step = currentScenarioContext.getStep(testStep);
83+
StartTestItemRQ rq = new StartTestItemRQ();
84+
rq.setName(Utils.buildNodeName(currentScenarioContext.getStepPrefix(), step.getKeyword(), testStep.getStepText(), " "));
85+
rq.setDescription(Utils.buildMultilineArgument(testStep));
86+
rq.setStartTime(Calendar.getInstance().getTime());
87+
rq.setType(getType(currentFeatureContext, step));
88+
currentStepId = RP.get().startTestItem(currentScenarioContext.getId(), rq);
89+
}
7990

80-
@Override
81-
protected void afterStep(Result result) {
82-
reportResult(result, null);
83-
Utils.finishTestItem(RP.get(), currentStepId, result.getStatus().toString().toUpperCase());
84-
currentStepId = null;
85-
}
91+
@Override
92+
protected void afterStep(Result result) {
93+
reportResult(result, null);
94+
Utils.finishTestItem(RP.get(), currentStepId, result.getStatus().toString().toUpperCase());
95+
currentStepId = null;
96+
}
8697

87-
@Override
88-
protected void beforeHooks(Boolean isBefore) {
89-
StartTestItemRQ rq = new StartTestItemRQ();
90-
rq.setName(isBefore ? "Before hooks" : "After hooks");
91-
rq.setStartTime(Calendar.getInstance().getTime());
92-
rq.setType(isBefore ? "BEFORE_TEST" : "AFTER_TEST");
98+
@Override
99+
protected void beforeHooks(Boolean isBefore) {
100+
StartTestItemRQ rq = new StartTestItemRQ();
101+
rq.setName(isBefore ? "Before hooks" : "After hooks");
102+
rq.setStartTime(Calendar.getInstance().getTime());
103+
rq.setType(isBefore ? "BEFORE_TEST" : "AFTER_TEST");
93104

94-
hookStepId = RP.get().startTestItem(currentScenarioContext.getId(), rq);
95-
hookStatus = Statuses.PASSED;
96-
}
105+
hookStepId = RP.get().startTestItem(currentScenarioContext.getId(), rq);
106+
hookStatus = Statuses.PASSED;
107+
}
97108

98-
@Override
99-
protected void afterHooks(Boolean isBefore) {
100-
Utils.finishTestItem(RP.get(), hookStepId, hookStatus);
101-
hookStepId = null;
102-
}
109+
@Override
110+
protected void afterHooks(Boolean isBefore) {
111+
Utils.finishTestItem(RP.get(), hookStepId, hookStatus);
112+
hookStepId = null;
113+
}
103114

104-
@Override
105-
protected void hookFinished(TestStep step, Result result, Boolean isBefore) {
106-
reportResult(result, (isBefore ? "Before" : "After") + " hook: " + step.getCodeLocation());
107-
hookStatus = result.getStatus().toString();
108-
}
115+
@Override
116+
protected void hookFinished(TestStep step, Result result, Boolean isBefore) {
117+
reportResult(result, (isBefore ? "Before" : "After") + " hook: " + step.getCodeLocation());
118+
hookStatus = result.getStatus().toString();
119+
}
109120

110-
@Override
111-
protected String getFeatureTestItemType() {
112-
return "SUITE";
113-
}
121+
@Override
122+
protected String getFeatureTestItemType() {
123+
return "SUITE";
124+
}
114125

115-
@Override
116-
protected String getScenarioTestItemType() {
117-
return "SCENARIO";
118-
}
126+
@Override
127+
protected String getScenarioTestItemType() {
128+
return "SCENARIO";
129+
}
119130
}

0 commit comments

Comments
 (0)