Skip to content

Commit f974c53

Browse files
authored
Programmatic skip scenario feature (#2502)
* Use local gauge-proto Signed-off-by: Piotr Nestorow <[email protected]> * Handle skip scenario during execution Signed-off-by: Piotr Nestorow <[email protected]> * Handle message when skip scenario Signed-off-by: Piotr Nestorow <[email protected]> * Handle skip scenario message Signed-off-by: Piotr Nestorow <[email protected]> * Golang version update Signed-off-by: Piotr Nestorow <[email protected]> * Update using gauge-proto from git Signed-off-by: Piotr Nestorow <[email protected]> --------- Signed-off-by: Piotr Nestorow <[email protected]>
1 parent 522443e commit f974c53

File tree

6 files changed

+58
-5
lines changed

6 files changed

+58
-5
lines changed

execution/result/scenarioResult.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ func (s ScenarioResult) GetFailed() bool {
3131
return s.ProtoScenario.GetExecutionStatus() == gauge_messages.ExecutionStatus_FAILED
3232
}
3333

34+
func (s ScenarioResult) SetSkippedScenario() {
35+
s.ProtoScenario.ExecutionStatus = gauge_messages.ExecutionStatus_SKIPPED
36+
}
37+
38+
func (s ScenarioResult) GetSkippedScenario() bool {
39+
return s.ProtoScenario.GetExecutionStatus() == gauge_messages.ExecutionStatus_SKIPPED
40+
}
41+
3442
func (s ScenarioResult) AddItems(protoItems []*gauge_messages.ProtoItem) {
3543
s.ProtoScenario.ScenarioItems = append(s.ProtoScenario.ScenarioItems, protoItems...)
3644
}

execution/result/stepResult.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ func (s *StepResult) GetStepFailed() bool {
5656
return s.StepFailed
5757
}
5858

59+
func (s *StepResult) GetSkippedScenario() bool {
60+
return s.ProtoStep.StepExecutionResult.ExecutionResult.GetSkipScenario()
61+
}
62+
5963
// GetStackTrace returns the stacktrace for step failure
6064
func (s *StepResult) GetStackTrace() string {
6165
return s.ProtoStep.GetStepExecutionResult().GetExecutionResult().GetStackTrace()

execution/scenarioExecutor.go

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,25 @@ func (e *scenarioExecutor) execute(i gauge.Item, r result.Result) {
7373
}
7474
e.notifyBeforeScenarioHook(scenarioResult)
7575

76-
if !scenarioResult.GetFailed() {
76+
if !(scenarioResult.GetFailed() || scenarioResult.GetSkippedScenario()) {
7777
protoContexts := scenarioResult.ProtoScenario.GetContexts()
7878
protoScenItems := scenarioResult.ProtoScenario.GetScenarioItems()
7979
// context and steps are not appended together since sometime it cause the issue and the steps in step list and proto step list differs.
8080
// This is done to fix https://github.com/getgauge/gauge/issues/1629
8181
if e.executeSteps(e.contexts, protoContexts, scenarioResult) {
82-
e.executeSteps(scenario.Steps, protoScenItems, scenarioResult)
82+
if !scenarioResult.GetSkippedScenario() {
83+
e.executeSteps(scenario.Steps, protoScenItems, scenarioResult)
84+
}
8385
}
8486
// teardowns are not appended to previous call to executeSteps to ensure they are run irrespective of context/step failure
8587
e.executeSteps(e.teardowns, scenarioResult.ProtoScenario.GetTearDownSteps(), scenarioResult)
8688
}
8789

90+
if scenarioResult.GetSkippedScenario() {
91+
e.skippedScenarioUpdateErrMap(i, r)
92+
setSkipInfoInResult(scenarioResult, scenario, e.errMap)
93+
}
94+
8895
e.notifyAfterScenarioHook(scenarioResult)
8996
scenarioResult.UpdateExecutionTime()
9097
}
@@ -123,6 +130,10 @@ func (e *scenarioExecutor) notifyBeforeScenarioHook(scenarioResult *result.Scena
123130
setScenarioFailure(e.currentExecutionInfo)
124131
handleHookFailure(scenarioResult, res, result.AddPreHook)
125132
}
133+
if res.GetSkipScenario() {
134+
scenarioResult.SetSkippedScenario()
135+
scenarioResult.ProtoScenario.PreHookMessages = []string{res.ErrorMessage}
136+
}
126137
message.ScenarioExecutionStartingRequest.ScenarioResult = gauge.ConvertToProtoScenarioResult(scenarioResult)
127138
e.pluginHandler.NotifyPlugins(message)
128139
}
@@ -205,6 +216,11 @@ func (e *scenarioExecutor) executeSteps(steps []*gauge.Step, protoItems []*gauge
205216
return false
206217
}
207218
}
219+
if scenarioResult.GetSkippedScenario() {
220+
// The step execution resulted in SkipScenario.
221+
// The rest of steps execution is skipped
222+
break;
223+
}
208224
}
209225
}
210226
return true
@@ -222,6 +238,9 @@ func (e *scenarioExecutor) executeStep(step *gauge.Step, protoItem *gauge_messag
222238
se := &stepExecutor{runner: e.runner, pluginHandler: e.pluginHandler, currentExecutionInfo: e.currentExecutionInfo, stream: e.stream}
223239
res := se.executeStep(step, protoItem.GetStep())
224240
protoItem.GetStep().StepExecutionResult = res.ProtoStepExecResult()
241+
if res.ProtoStepExecResult().ExecutionResult.GetSkipScenario() {
242+
scenarioResult.SetSkippedScenario()
243+
}
225244
failed = res.GetFailed()
226245
recoverable = res.ProtoStepExecResult().GetExecutionResult().GetRecoverableError()
227246
}
@@ -262,6 +281,11 @@ func (e *scenarioExecutor) executeConcept(item *gauge.Step, protoConcept *gauge_
262281

263282
return cptResult
264283
}
284+
if scenarioResult.GetSkippedScenario() {
285+
// The step execution resulted in SkipScenario.
286+
// The rest of steps execution is skipped
287+
break;
288+
}
265289
}
266290
}
267291
cptResult.UpdateConceptExecResult()
@@ -296,3 +320,15 @@ func setScenarioFailure(executionInfo *gauge_messages.ExecutionInfo) {
296320
setSpecFailure(executionInfo)
297321
executionInfo.CurrentScenario.IsFailed = true
298322
}
323+
324+
func (e *scenarioExecutor) skippedScenarioUpdateErrMap(i gauge.Item, r result.Result) {
325+
scenario := i.(*gauge.Scenario)
326+
scenarioResult := r.(*result.ScenarioResult)
327+
if len(scenarioResult.ProtoScenario.PreHookMessages) > 0 {
328+
e.errMap.ScenarioErrs[scenario] = append([]error{errors.New(scenarioResult.ProtoScenario.PreHookMessages[0])}, e.errMap.ScenarioErrs[scenario]...)
329+
scenarioResult.ProtoScenario.SkipErrors = scenarioResult.ProtoScenario.PreHookMessages
330+
} else {
331+
e.errMap.ScenarioErrs[scenario] = append([]error{errors.New(e.currentExecutionInfo.CurrentStep.ErrorMessage)}, e.errMap.ScenarioErrs[scenario]...)
332+
scenarioResult.ProtoScenario.SkipErrors = []string{e.currentExecutionInfo.CurrentStep.ErrorMessage}
333+
}
334+
}

execution/stepExecutor.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ func (e *stepExecutor) executeStep(step *gauge.Step, protoStep *gauge_messages.P
4646
e.currentExecutionInfo.CurrentStep.StackTrace = stepExecutionStatus.GetStackTrace()
4747
setStepFailure(e.currentExecutionInfo)
4848
stepResult.SetStepFailure()
49+
} else if stepResult.GetSkippedScenario() {
50+
e.currentExecutionInfo.CurrentStep.ErrorMessage = stepExecutionStatus.GetErrorMessage()
51+
e.currentExecutionInfo.CurrentStep.StackTrace = stepExecutionStatus.GetStackTrace()
4952
}
5053
stepResult.SetProtoExecResult(stepExecutionStatus)
5154
}
@@ -95,3 +98,5 @@ func (e *stepExecutor) notifyAfterStepHook(stepResult *result.StepResult) {
9598
m.StepExecutionEndingRequest.StepResult = gauge.ConvertToProtoStepResult(stepResult)
9699
e.pluginHandler.NotifyPlugins(m)
97100
}
101+
102+

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ require (
77
github.com/daviddengcn/go-colortext v1.0.0
88
github.com/fsnotify/fsnotify v1.7.0
99
github.com/getgauge/common v0.0.0-20240331100109-225c78ec8f30
10-
github.com/getgauge/gauge-proto/go/gauge_messages v0.0.0-20240331094732-ac276d4db3b9
10+
github.com/getgauge/gauge-proto/go/gauge_messages v0.0.0-20240402072853-303b17b7c486
1111
github.com/golang/protobuf v1.5.4
1212
github.com/magiconair/properties v1.8.7
1313
github.com/natefinch/lumberjack v2.0.0+incompatible

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nos
1414
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
1515
github.com/getgauge/common v0.0.0-20240331100109-225c78ec8f30 h1:pGrxY3IZb/1wwlSUSKYplmQ9kEh4rRpcAvQYI2WcxX0=
1616
github.com/getgauge/common v0.0.0-20240331100109-225c78ec8f30/go.mod h1:q7UW1tDojJwCQPUHaE1ny71IZIDuKlsgh3Tyr5wAZDk=
17-
github.com/getgauge/gauge-proto/go/gauge_messages v0.0.0-20240331094732-ac276d4db3b9 h1:g3Qhoj4ho3txgMcOJ3ivvEhfahaR6t8XTkf5K5M1VSA=
18-
github.com/getgauge/gauge-proto/go/gauge_messages v0.0.0-20240331094732-ac276d4db3b9/go.mod h1:ZOT57PjvIqY31eGcwhj/LSi/K6ULBE1AhFcIMzWkmPg=
17+
github.com/getgauge/gauge-proto/go/gauge_messages v0.0.0-20240402072853-303b17b7c486 h1:kb/Ey0fFX+EHPmFcOEZDa0s4bgsRpRF8iDJEcbZPgLU=
18+
github.com/getgauge/gauge-proto/go/gauge_messages v0.0.0-20240402072853-303b17b7c486/go.mod h1:ZOT57PjvIqY31eGcwhj/LSi/K6ULBE1AhFcIMzWkmPg=
1919
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
2020
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
2121
github.com/golangplus/bytes v0.0.0-20160111154220-45c989fe5450/go.mod h1:Bk6SMAONeMXrxql8uvOKuAZSu8aM5RUGv+1C6IJaEho=

0 commit comments

Comments
 (0)