github.com/getgauge/gauge@v1.6.9/execution/result/stepResult.go (about) 1 /*---------------------------------------------------------------- 2 * Copyright (c) ThoughtWorks, Inc. 3 * Licensed under the Apache License, Version 2.0 4 * See LICENSE in the project root for license information. 5 *----------------------------------------------------------------*/ 6 7 package result 8 9 import "github.com/getgauge/gauge-proto/go/gauge_messages" 10 11 // StepResult represents the result of step execution 12 type StepResult struct { 13 ProtoStep *gauge_messages.ProtoStep 14 StepFailed bool 15 } 16 17 // NewStepResult is a constructor for StepResult 18 func NewStepResult(ps *gauge_messages.ProtoStep) *StepResult { 19 return &StepResult{ProtoStep: ps} 20 } 21 22 func (s *StepResult) GetPreHook() []*gauge_messages.ProtoHookFailure { 23 if s.ProtoStep.StepExecutionResult.PreHookFailure == nil { 24 return []*gauge_messages.ProtoHookFailure{} 25 } 26 return []*gauge_messages.ProtoHookFailure{s.ProtoStep.StepExecutionResult.PreHookFailure} 27 } 28 29 func (s *StepResult) GetPostHook() []*gauge_messages.ProtoHookFailure { 30 if s.ProtoStep.StepExecutionResult.PostHookFailure == nil { 31 return []*gauge_messages.ProtoHookFailure{} 32 } 33 return []*gauge_messages.ProtoHookFailure{s.ProtoStep.StepExecutionResult.PostHookFailure} 34 } 35 36 func (s *StepResult) AddPreHook(f ...*gauge_messages.ProtoHookFailure) { 37 s.ProtoStep.StepExecutionResult.PreHookFailure = f[0] 38 } 39 40 func (s *StepResult) AddPostHook(f ...*gauge_messages.ProtoHookFailure) { 41 s.ProtoStep.StepExecutionResult.PostHookFailure = f[0] 42 } 43 44 // SetFailure sets the result to failed 45 func (s *StepResult) SetFailure() { 46 s.ProtoStep.StepExecutionResult.ExecutionResult.Failed = true 47 } 48 49 // GetFailed returns the state of the result 50 func (s *StepResult) GetFailed() bool { 51 return s.ProtoStep.StepExecutionResult.ExecutionResult.GetFailed() 52 } 53 54 // GetFailed returns true if the actual step failed, and not step hook. 55 func (s *StepResult) GetStepFailed() bool { 56 return s.StepFailed 57 } 58 59 func (s *StepResult) GetSkippedScenario() bool { 60 return s.ProtoStep.StepExecutionResult.ExecutionResult.GetSkipScenario() 61 } 62 63 // GetStackTrace returns the stacktrace for step failure 64 func (s *StepResult) GetStackTrace() string { 65 return s.ProtoStep.GetStepExecutionResult().GetExecutionResult().GetStackTrace() 66 } 67 68 // GetErrorMessage returns the error message for step failure 69 func (s *StepResult) GetErrorMessage() string { 70 return s.ProtoStep.GetStepExecutionResult().GetExecutionResult().GetErrorMessage() 71 } 72 73 // GetStepActualText returns the Actual text of step from step result 74 func (s *StepResult) GetStepActualText() string { 75 return s.ProtoStep.GetActualText() 76 } 77 78 // SetStepFailure sets the actual step as failed. StepResult.ProtoStep.GetFailed() returns true even if hook failed and not actual step. 79 func (s *StepResult) SetStepFailure() { 80 s.StepFailed = true 81 } 82 83 func (s *StepResult) Item() interface{} { 84 return s.ProtoStep 85 } 86 87 // ExecTime returns the time taken to execute the step 88 func (s *StepResult) ExecTime() int64 { 89 return s.ProtoStep.StepExecutionResult.ExecutionResult.GetExecutionTime() 90 } 91 92 // AddExecTime increments the execution time by the given value 93 func (s *StepResult) AddExecTime(t int64) { 94 if s.ProtoStep.StepExecutionResult.ExecutionResult == nil { 95 s.ProtoStep.StepExecutionResult.ExecutionResult = &gauge_messages.ProtoExecutionResult{Failed: false} 96 } 97 currentTime := s.ProtoStep.StepExecutionResult.ExecutionResult.GetExecutionTime() 98 s.ProtoStep.StepExecutionResult.ExecutionResult.ExecutionTime = currentTime + t 99 } 100 101 // ProtoStepExecResult returns the step execution result used at the proto layer 102 func (s *StepResult) ProtoStepExecResult() *gauge_messages.ProtoStepExecutionResult { 103 return s.ProtoStep.StepExecutionResult 104 } 105 106 // SetProtoExecResult sets the execution result 107 func (s *StepResult) SetProtoExecResult(r *gauge_messages.ProtoExecutionResult) { 108 s.ProtoStep.StepExecutionResult.ExecutionResult = r 109 }