Skip to content

Commit

Permalink
Merge pull request #21 from henriheimann/master
Browse files Browse the repository at this point in the history
Add before and after scenario and step hook messages
  • Loading branch information
sriv authored Jun 16, 2021
2 parents 8e895ae + d391c7e commit 1bda6b3
Show file tree
Hide file tree
Showing 3 changed files with 206 additions and 86 deletions.
16 changes: 16 additions & 0 deletions _testdata/sample.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
],
"table": null,
"beforeStepHookFailure": null,
"beforeStepHookMessages": [],
"afterStepHookFailure": null,
"afterStepHookMessages": [],
"result": {
"status": "pass",
"stackTrace": "",
Expand Down Expand Up @@ -69,7 +71,9 @@
],
"table": null,
"beforeStepHookFailure": null,
"beforeStepHookMessages": [],
"afterStepHookFailure": null,
"afterStepHookMessages": [],
"result": {
"status": "pass",
"stackTrace": "",
Expand All @@ -83,7 +87,9 @@
}
],
"beforeScenarioHookFailure": null,
"beforeScenarioHookMessages": [],
"afterScenarioHookFailure": null,
"afterScenarioHookMessages": [],
"skipErrors": [],
"tableRowIndex": -1
},
Expand All @@ -106,7 +112,9 @@
],
"table": null,
"beforeStepHookFailure": null,
"beforeStepHookMessages": [],
"afterStepHookFailure": null,
"afterStepHookMessages": [],
"result": {
"status": "pass",
"stackTrace": "",
Expand Down Expand Up @@ -208,7 +216,9 @@
]
},
"beforeStepHookFailure": null,
"beforeStepHookMessages": [],
"afterStepHookFailure": null,
"afterStepHookMessages": [],
"result": {
"status": "pass",
"stackTrace": "",
Expand All @@ -222,22 +232,28 @@
}
],
"beforeScenarioHookFailure": null,
"beforeScenarioHookMessages": [],
"afterScenarioHookFailure": null,
"afterScenarioHookMessages": [],
"skipErrors": [],
"tableRowIndex": -1
}
],
"isTableDriven": false,
"datatable": null,
"beforeSpecHookFailure": null,
"beforeSpecHookMessages": [],
"afterSpecHookFailure": null,
"afterSpecHookMessages": [],
"passedScenarioCount": 2,
"failedScenarioCount": 0,
"skippedScenarioCount": 0
}
],
"beforeSuiteHookFailure": null,
"beforeSuiteHookMessages": [],
"afterSuiteHookFailure": null,
"afterSuiteHookMessages": [],
"passedSpecsCount": 1,
"failedSpecsCount": 0,
"skippedSpecsCount": 0,
Expand Down
212 changes: 126 additions & 86 deletions generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,62 +32,70 @@ type item interface {
}

type suiteResult struct {
ProjectName string `json:"projectName"`
Timestamp string `json:"timestamp"`
SuccessRate int `json:"successRate"`
Environment string `json:"environment"`
Tags string `json:"tags"`
ExecutionTime int64 `json:"executionTime"`
ExecutionStatus status `json:"executionStatus"`
SpecResults []spec `json:"specResults"`
BeforeSuiteHookFailure *hookFailure `json:"beforeSuiteHookFailure"`
AfterSuiteHookFailure *hookFailure `json:"afterSuiteHookFailure"`
PassedSpecsCount int `json:"passedSpecsCount"`
FailedSpecsCount int `json:"failedSpecsCount"`
SkippedSpecsCount int `json:"skippedSpecsCount"`
PassedScenariosCount int `json:"passedScenariosCount"`
FailedScenariosCount int `json:"failedScenariosCount"`
SkippedScenariosCount int `json:"skippedScenariosCount"`
ProjectName string `json:"projectName"`
Timestamp string `json:"timestamp"`
SuccessRate int `json:"successRate"`
Environment string `json:"environment"`
Tags string `json:"tags"`
ExecutionTime int64 `json:"executionTime"`
ExecutionStatus status `json:"executionStatus"`
SpecResults []spec `json:"specResults"`
BeforeSuiteHookFailure *hookFailure `json:"beforeSuiteHookFailure"`
BeforeSuiteHookMessages []string `json:"beforeSuiteHookMessages"`
AfterSuiteHookFailure *hookFailure `json:"afterSuiteHookFailure"`
AfterSuiteHookMessages []string `json:"afterSuiteHookMessages"`
PassedSpecsCount int `json:"passedSpecsCount"`
FailedSpecsCount int `json:"failedSpecsCount"`
SkippedSpecsCount int `json:"skippedSpecsCount"`
PassedScenariosCount int `json:"passedScenariosCount"`
FailedScenariosCount int `json:"failedScenariosCount"`
SkippedScenariosCount int `json:"skippedScenariosCount"`
}

type spec struct {
SpecHeading string `json:"specHeading"`
FileName string `json:"fileName"`
Tags []string `json:"tags"`
ExecutionTime int64 `json:"executionTime"`
ExecutionStatus status `json:"executionStatus"`
Scenarios []scenario `json:"scenarios"`
IsTableDriven bool `json:"isTableDriven"`
Datatable *table `json:"datatable"`
BeforeSpecHookFailure *hookFailure `json:"beforeSpecHookFailure"`
AfterSpecHookFailure *hookFailure `json:"afterSpecHookFailure"`
PassedScenarioCount int `json:"passedScenarioCount"`
FailedScenarioCount int `json:"failedScenarioCount"`
SkippedScenarioCount int `json:"skippedScenarioCount"`
SpecHeading string `json:"specHeading"`
FileName string `json:"fileName"`
Tags []string `json:"tags"`
ExecutionTime int64 `json:"executionTime"`
ExecutionStatus status `json:"executionStatus"`
Scenarios []scenario `json:"scenarios"`
IsTableDriven bool `json:"isTableDriven"`
Datatable *table `json:"datatable"`
BeforeSpecHookFailure *hookFailure `json:"beforeSpecHookFailure"`
BeforeSpecHookMessages []string `json:"beforeSpecHookMessages"`
AfterSpecHookFailure *hookFailure `json:"afterSpecHookFailure"`
AfterSpecHookMessages []string `json:"afterSpecHookMessages"`
PassedScenarioCount int `json:"passedScenarioCount"`
FailedScenarioCount int `json:"failedScenarioCount"`
SkippedScenarioCount int `json:"skippedScenarioCount"`
}

type scenario struct {
Heading string `json:"scenarioHeading"`
Tags []string `json:"tags"`
ExecutionTime int64 `json:"executionTime"`
ExecutionStatus status `json:"executionStatus"`
Contexts []item `json:"contexts"`
Teardowns []item `json:"teardowns"`
Items []item `json:"items"`
BeforeScenarioHookFailure *hookFailure `json:"beforeScenarioHookFailure"`
AfterScenarioHookFailure *hookFailure `json:"afterScenarioHookFailure"`
SkipErrors []string `json:"skipErrors"`
TableRowIndex int `json:"tableRowIndex"`
Heading string `json:"scenarioHeading"`
Tags []string `json:"tags"`
ExecutionTime int64 `json:"executionTime"`
ExecutionStatus status `json:"executionStatus"`
Contexts []item `json:"contexts"`
Teardowns []item `json:"teardowns"`
Items []item `json:"items"`
BeforeScenarioHookFailure *hookFailure `json:"beforeScenarioHookFailure"`
BeforeScenarioHookMessages []string `json:"beforeScenarioHookMessages"`
AfterScenarioHookFailure *hookFailure `json:"afterScenarioHookFailure"`
AfterScenarioHookMessages []string `json:"afterScenarioHookMessages"`
SkipErrors []string `json:"skipErrors"`
TableRowIndex int `json:"tableRowIndex"`
}

type step struct {
ItemType tokenKind `json:"itemType"`
StepText string `json:"stepText"`
Parameters []Parameter `json:"parameters"`
Table *table `json:"table"`
BeforeStepHookFailure *hookFailure `json:"beforeStepHookFailure"`
AfterStepHookFailure *hookFailure `json:"afterStepHookFailure"`
Result *result `json:"result"`
ItemType tokenKind `json:"itemType"`
StepText string `json:"stepText"`
Parameters []Parameter `json:"parameters"`
Table *table `json:"table"`
BeforeStepHookFailure *hookFailure `json:"beforeStepHookFailure"`
BeforeStepHookMessages []string `json:"beforeStepHookMessages"`
AfterStepHookFailure *hookFailure `json:"afterStepHookFailure"`
AfterStepHookMessages []string `json:"afterStepHookMessages"`
Result *result `json:"result"`
}

func (s *step) kind() tokenKind {
Expand Down Expand Up @@ -141,18 +149,26 @@ type row struct {

func toSuiteResult(psr *gauge_messages.ProtoSuiteResult) suiteResult {
suiteResult := suiteResult{
ProjectName: psr.GetProjectName(),
Environment: psr.GetEnvironment(),
Tags: psr.GetTags(),
ExecutionTime: psr.GetExecutionTime(),
PassedSpecsCount: len(psr.GetSpecResults()) - int(psr.GetSpecsFailedCount()) - int(psr.GetSpecsSkippedCount()),
FailedSpecsCount: int(psr.GetSpecsFailedCount()),
SkippedSpecsCount: int(psr.GetSpecsSkippedCount()),
BeforeSuiteHookFailure: toHookFailure(psr.GetPreHookFailure()),
AfterSuiteHookFailure: toHookFailure(psr.GetPostHookFailure()),
SuccessRate: int(psr.GetSuccessRate()),
Timestamp: psr.GetTimestamp(),
ExecutionStatus: pass,
ProjectName: psr.GetProjectName(),
Environment: psr.GetEnvironment(),
Tags: psr.GetTags(),
ExecutionTime: psr.GetExecutionTime(),
PassedSpecsCount: len(psr.GetSpecResults()) - int(psr.GetSpecsFailedCount()) - int(psr.GetSpecsSkippedCount()),
FailedSpecsCount: int(psr.GetSpecsFailedCount()),
SkippedSpecsCount: int(psr.GetSpecsSkippedCount()),
BeforeSuiteHookFailure: toHookFailure(psr.GetPreHookFailure()),
BeforeSuiteHookMessages: make([]string, 0),
AfterSuiteHookFailure: toHookFailure(psr.GetPostHookFailure()),
AfterSuiteHookMessages: make([]string, 0),
SuccessRate: int(psr.GetSuccessRate()),
Timestamp: psr.GetTimestamp(),
ExecutionStatus: pass,
}
if psr.GetPreHookMessages() != nil {
suiteResult.BeforeSuiteHookMessages = psr.GetPreHookMessages()
}
if psr.GetPostHookMessages() != nil {
suiteResult.AfterSuiteHookMessages = psr.GetPostHookMessages()
}
if psr.GetFailed() {
suiteResult.ExecutionStatus = fail
Expand All @@ -170,17 +186,25 @@ func toSuiteResult(psr *gauge_messages.ProtoSuiteResult) suiteResult {

func toSpec(psr *gauge_messages.ProtoSpecResult) spec {
spec := spec{
SpecHeading: psr.GetProtoSpec().GetSpecHeading(),
IsTableDriven: psr.GetProtoSpec().GetIsTableDriven(),
FileName: psr.GetProtoSpec().GetFileName(),
Tags: make([]string, 0),
FailedScenarioCount: int(psr.GetScenarioFailedCount()),
SkippedScenarioCount: int(psr.GetScenarioSkippedCount()),
PassedScenarioCount: int(psr.GetScenarioCount() - psr.GetScenarioFailedCount() - psr.GetScenarioSkippedCount()),
ExecutionTime: psr.GetExecutionTime(),
ExecutionStatus: getStatus(psr.GetFailed(), psr.GetSkipped()),
BeforeSpecHookFailure: toSpecHookFailure(psr.GetProtoSpec().GetPreHookFailures()),
AfterSpecHookFailure: toSpecHookFailure(psr.GetProtoSpec().GetPostHookFailures()),
SpecHeading: psr.GetProtoSpec().GetSpecHeading(),
IsTableDriven: psr.GetProtoSpec().GetIsTableDriven(),
FileName: psr.GetProtoSpec().GetFileName(),
Tags: make([]string, 0),
FailedScenarioCount: int(psr.GetScenarioFailedCount()),
SkippedScenarioCount: int(psr.GetScenarioSkippedCount()),
PassedScenarioCount: int(psr.GetScenarioCount() - psr.GetScenarioFailedCount() - psr.GetScenarioSkippedCount()),
ExecutionTime: psr.GetExecutionTime(),
ExecutionStatus: getStatus(psr.GetFailed(), psr.GetSkipped()),
BeforeSpecHookFailure: toSpecHookFailure(psr.GetProtoSpec().GetPreHookFailures()),
BeforeSpecHookMessages: make([]string, 0),
AfterSpecHookFailure: toSpecHookFailure(psr.GetProtoSpec().GetPostHookFailures()),
AfterSpecHookMessages: make([]string, 0),
}
if psr.GetProtoSpec().GetPreHookMessages() != nil {
spec.BeforeSpecHookMessages = psr.GetProtoSpec().GetPreHookMessages()
}
if psr.GetProtoSpec().GetPostHookMessages() != nil {
spec.AfterSpecHookMessages = psr.GetProtoSpec().GetPostHookMessages()
}
if psr.GetProtoSpec().GetTags() != nil {
spec.Tags = psr.GetProtoSpec().GetTags()
Expand All @@ -201,17 +225,25 @@ func toSpec(psr *gauge_messages.ProtoSpecResult) spec {

func toScenario(protoSce *gauge_messages.ProtoScenario, tableRowIndex int) scenario {
sce := scenario{
Heading: protoSce.GetScenarioHeading(),
ExecutionTime: protoSce.GetExecutionTime(),
Tags: make([]string, 0),
ExecutionStatus: getScenarioStatus(protoSce),
Contexts: make([]item, 0),
Items: make([]item, 0),
Teardowns: make([]item, 0),
BeforeScenarioHookFailure: toHookFailure(protoSce.GetPreHookFailure()),
AfterScenarioHookFailure: toHookFailure(protoSce.GetPostHookFailure()),
TableRowIndex: tableRowIndex,
SkipErrors: make([]string, 0),
Heading: protoSce.GetScenarioHeading(),
ExecutionTime: protoSce.GetExecutionTime(),
Tags: make([]string, 0),
ExecutionStatus: getScenarioStatus(protoSce),
Contexts: make([]item, 0),
Items: make([]item, 0),
Teardowns: make([]item, 0),
BeforeScenarioHookFailure: toHookFailure(protoSce.GetPreHookFailure()),
BeforeScenarioHookMessages: make([]string, 0),
AfterScenarioHookFailure: toHookFailure(protoSce.GetPostHookFailure()),
AfterScenarioHookMessages: make([]string, 0),
TableRowIndex: tableRowIndex,
SkipErrors: make([]string, 0),
}
if protoSce.GetPreHookMessages() != nil {
sce.BeforeScenarioHookMessages = protoSce.GetPreHookMessages()
}
if protoSce.GetPostHookMessages() != nil {
sce.AfterScenarioHookMessages = protoSce.GetPostHookMessages()
}
if protoSce.GetSkipErrors() != nil {
sce.SkipErrors = protoSce.GetSkipErrors()
Expand Down Expand Up @@ -290,11 +322,19 @@ func toStep(protoStep *gauge_messages.ProtoStep) *step {
result.Messages = res.GetMessage()
}
step := &step{
ItemType: stepKind,
StepText: protoStep.GetActualText(),
Result: result,
BeforeStepHookFailure: toHookFailure(protoStep.GetStepExecutionResult().GetPreHookFailure()),
AfterStepHookFailure: toHookFailure(protoStep.GetStepExecutionResult().GetPostHookFailure()),
ItemType: stepKind,
StepText: protoStep.GetActualText(),
Result: result,
BeforeStepHookFailure: toHookFailure(protoStep.GetStepExecutionResult().GetPreHookFailure()),
BeforeStepHookMessages: make([]string, 0),
AfterStepHookFailure: toHookFailure(protoStep.GetStepExecutionResult().GetPostHookFailure()),
AfterStepHookMessages: make([]string, 0),
}
if protoStep.GetPreHookMessages() != nil {
step.BeforeStepHookMessages = protoStep.GetPreHookMessages()
}
if protoStep.GetPostHookMessages() != nil {
step.AfterStepHookMessages = protoStep.GetPostHookMessages()
}

params := make([]Parameter, 0)
Expand Down
Loading

0 comments on commit 1bda6b3

Please sign in to comment.