|
49 | 49 | * @author Serhii Zharskyi
|
50 | 50 | */
|
51 | 51 | 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; |
55 | 55 |
|
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 | + } |
62 | 62 |
|
| 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 | + } |
63 | 74 |
|
64 |
| - @Override |
65 |
| - protected Maybe<String> getRootItemId() { |
66 |
| - return null; |
67 |
| - } |
| 75 | + @Override |
| 76 | + protected Maybe<String> getRootItemId() { |
| 77 | + return null; |
| 78 | + } |
68 | 79 |
|
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 | + } |
79 | 90 |
|
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 | + } |
86 | 97 |
|
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"); |
93 | 104 |
|
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 | + } |
97 | 108 |
|
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 | + } |
103 | 114 |
|
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 | + } |
109 | 120 |
|
110 |
| - @Override |
111 |
| - protected String getFeatureTestItemType() { |
112 |
| - return "SUITE"; |
113 |
| - } |
| 121 | + @Override |
| 122 | + protected String getFeatureTestItemType() { |
| 123 | + return "SUITE"; |
| 124 | + } |
114 | 125 |
|
115 |
| - @Override |
116 |
| - protected String getScenarioTestItemType() { |
117 |
| - return "SCENARIO"; |
118 |
| - } |
| 126 | + @Override |
| 127 | + protected String getScenarioTestItemType() { |
| 128 | + return "SCENARIO"; |
| 129 | + } |
119 | 130 | }
|
0 commit comments