Best Gauge code snippet using execution.scenarioHeading
integration_test.go
Source:integration_test.go
1// +build linux darwin2/*----------------------------------------------------------------3 * Copyright (c) ThoughtWorks, Inc.4 * Licensed under the Apache License, Version 2.05 * See LICENSE in the project root for license information.6 *----------------------------------------------------------------*/7package builder8import (9 "encoding/xml"10 "path/filepath"11 "io/ioutil"12 "strings"13 "github.com/getgauge/xml-report/gauge_messages"14 "github.com/lestrrat-go/libxml2"15 "github.com/lestrrat-go/libxml2/xsd"16 . "gopkg.in/check.v1"17)18var junitSchema *xsd.Schema19func init() {20 schema, err := ioutil.ReadFile(filepath.Join("_testdata", "junit.xsd"))21 if err != nil {22 panic(err)23 }24 junitSchema, err = xsd.Parse(schema)25 if err != nil {26 panic(err)27 }28}29func (s *MySuite) TestToVerifyXmlContent(c *C) {30 value := gauge_messages.ProtoItem_Scenario31 item := &gauge_messages.ProtoItem{Scenario: &gauge_messages.ProtoScenario{Failed: false, ScenarioHeading: "Scenario1"}, ItemType: value}32 spec := &gauge_messages.ProtoSpec{SpecHeading: "HEADING", FileName: "FILENAME", Items: []*gauge_messages.ProtoItem{item}}33 specResult := &gauge_messages.ProtoSpecResult{ProtoSpec: spec, ScenarioCount: 1, Failed: false}34 suiteResult := &gauge_messages.ProtoSuiteResult{SpecResults: []*gauge_messages.ProtoSpecResult{specResult}}35 message := &gauge_messages.SuiteExecutionResult{SuiteResult: suiteResult}36 builder := &XmlBuilder{currentId: 0}37 bytes, err := builder.GetXmlContent(message)38 assertXmlValidation(bytes, c)39 var suites JUnitTestSuites40 xml.Unmarshal(bytes, &suites)41 c.Assert(err, Equals, nil)42 c.Assert(len(suites.Suites), Equals, 1)43 c.Assert(suites.Suites[0].Errors, Equals, 0)44 c.Assert(suites.Suites[0].Failures, Equals, 0)45 c.Assert(suites.Suites[0].Package, Equals, "FILENAME")46 c.Assert(suites.Suites[0].Name, Equals, "HEADING")47 c.Assert(suites.Suites[0].Tests, Equals, 1)48 c.Assert(suites.Suites[0].Timestamp, Equals, builder.suites.Suites[0].Timestamp)49 c.Assert(suites.Suites[0].SystemError.Contents, Equals, "")50 c.Assert(suites.Suites[0].SystemOutput.Contents, Equals, "")51 c.Assert(len(suites.Suites[0].TestCases), Equals, 1)52}53func (s *MySuite) TestToVerifyXmlContentForFailingExecutionResult(c *C) {54 value := gauge_messages.ProtoItem_Scenario55 stepType := gauge_messages.ProtoItem_Step56 result := &gauge_messages.ProtoExecutionResult{Failed: true, ErrorMessage: "something", StackTrace: "nice little stacktrace"}57 step := &gauge_messages.ProtoStep{StepExecutionResult: &gauge_messages.ProtoStepExecutionResult{ExecutionResult: result}}58 steps := []*gauge_messages.ProtoItem{{Step: step, ItemType: stepType}}59 item := &gauge_messages.ProtoItem{Scenario: &gauge_messages.ProtoScenario{Failed: true,60 ScenarioHeading: "Scenario1", ScenarioItems: steps}, ItemType: value}61 spec := &gauge_messages.ProtoSpec{SpecHeading: "HEADING", FileName: "FILENAME", Items: []*gauge_messages.ProtoItem{item}}62 specResult := &gauge_messages.ProtoSpecResult{ProtoSpec: spec, ScenarioCount: 1, Failed: true, ScenarioFailedCount: 1}63 suiteResult := &gauge_messages.ProtoSuiteResult{SpecResults: []*gauge_messages.ProtoSpecResult{specResult}}64 message := &gauge_messages.SuiteExecutionResult{SuiteResult: suiteResult}65 builder := &XmlBuilder{currentId: 0}66 bytes, err := builder.GetXmlContent(message)67 assertXmlValidation(bytes, c)68 var suites JUnitTestSuites69 xml.Unmarshal(bytes, &suites)70 c.Assert(err, Equals, nil)71 c.Assert(len(suites.Suites), Equals, 1)72 // spec1 || testSuite73 c.Assert(suites.Suites[0].Errors, Equals, 0)74 c.Assert(suites.Suites[0].Failures, Equals, 1)75 c.Assert(suites.Suites[0].Package, Equals, "FILENAME")76 c.Assert(suites.Suites[0].Name, Equals, "HEADING")77 c.Assert(suites.Suites[0].Tests, Equals, 1)78 c.Assert(suites.Suites[0].Timestamp, Equals, builder.suites.Suites[0].Timestamp)79 c.Assert(suites.Suites[0].SystemError.Contents, Equals, "")80 c.Assert(suites.Suites[0].SystemOutput.Contents, Equals, "")81 // scenario1 of spec1 || testCase82 c.Assert(len(suites.Suites[0].TestCases), Equals, 1)83 c.Assert(suites.Suites[0].TestCases[0].Classname, Equals, "HEADING")84 c.Assert(suites.Suites[0].TestCases[0].Name, Equals, "Scenario1")85 c.Assert(suites.Suites[0].TestCases[0].Failure.Message, Equals, "Step Execution Failure: 'something'")86 c.Assert(suites.Suites[0].TestCases[0].Failure.Contents, Equals, "nice little stacktrace")87}88func (s *MySuite) TestToVerifyXmlContentForMultipleFailuresInExecutionResult(c *C) {89 value := gauge_messages.ProtoItem_Scenario90 stepType := gauge_messages.ProtoItem_Step91 result1 := &gauge_messages.ProtoExecutionResult{Failed: true, ErrorMessage: "fail but don't stop", StackTrace: "nice little stacktrace", RecoverableError: true}92 result2 := &gauge_messages.ProtoExecutionResult{Failed: true, ErrorMessage: "stop here", StackTrace: "very easy to trace"}93 step1 := &gauge_messages.ProtoStep{StepExecutionResult: &gauge_messages.ProtoStepExecutionResult{ExecutionResult: result1}}94 step2 := &gauge_messages.ProtoStep{StepExecutionResult: &gauge_messages.ProtoStepExecutionResult{ExecutionResult: result2}}95 steps := []*gauge_messages.ProtoItem{{Step: step1, ItemType: stepType}, {Step: step2, ItemType: stepType}}96 item := &gauge_messages.ProtoItem{Scenario: &gauge_messages.ProtoScenario{Failed: true,97 ScenarioHeading: "Scenario1", ScenarioItems: steps}, ItemType: value}98 spec := &gauge_messages.ProtoSpec{SpecHeading: "HEADING", FileName: "FILENAME", Items: []*gauge_messages.ProtoItem{item}}99 specResult := &gauge_messages.ProtoSpecResult{ProtoSpec: spec, ScenarioCount: 1, Failed: true, ScenarioFailedCount: 1}100 suiteResult := &gauge_messages.ProtoSuiteResult{SpecResults: []*gauge_messages.ProtoSpecResult{specResult}}101 message := &gauge_messages.SuiteExecutionResult{SuiteResult: suiteResult}102 builder := &XmlBuilder{currentId: 0}103 bytes, _ := builder.GetXmlContent(message)104 assertXmlValidation(bytes, c)105 var suites JUnitTestSuites106 xml.Unmarshal(bytes, &suites)107 c.Assert(len(suites.Suites[0].TestCases), Equals, 1)108 c.Assert(suites.Suites[0].TestCases[0].Classname, Equals, "HEADING")109 c.Assert(suites.Suites[0].TestCases[0].Name, Equals, "Scenario1")110 failure := `Step Execution Failure: 'fail but don't stop'111nice little stacktrace112Step Execution Failure: 'stop here'113very easy to trace`114 c.Assert(suites.Suites[0].TestCases[0].Failure.Message, Equals, "Multiple failures")115 c.Assert(suites.Suites[0].TestCases[0].Failure.Contents, Equals, failure)116}117func (s *MySuite) TestToVerifyXmlContentForMultipleFailuresWithNestedConcept(c *C) {118 scenType := gauge_messages.ProtoItem_Scenario119 stepType := gauge_messages.ProtoItem_Step120 cptType := gauge_messages.ProtoItem_Concept121 result1 := &gauge_messages.ProtoExecutionResult{Failed: true, ErrorMessage: "fail but don't stop", StackTrace: "nice little stacktrace"}122 result2 := &gauge_messages.ProtoExecutionResult{Failed: true, ErrorMessage: "continue on failure", StackTrace: "very easy to trace"}123 step1 := &gauge_messages.ProtoStep{StepExecutionResult: &gauge_messages.ProtoStepExecutionResult{ExecutionResult: result1}}124 step2 := &gauge_messages.ProtoStep{StepExecutionResult: &gauge_messages.ProtoStepExecutionResult{ExecutionResult: result2}}125 steps := []*gauge_messages.ProtoItem{{Step: step1, ItemType: stepType}, {Step: step2, ItemType: stepType}}126 cpt1 := &gauge_messages.ProtoItem{Concept: &gauge_messages.ProtoConcept{Steps: steps}, ItemType: cptType}127 cpt2 := &gauge_messages.ProtoItem{Concept: &gauge_messages.ProtoConcept{Steps: append(steps, cpt1)}, ItemType: cptType}128 scenario := &gauge_messages.ProtoScenario{Failed: true, ScenarioHeading: "Scenario1", ScenarioItems: append(steps, cpt2)}129 scenItem := &gauge_messages.ProtoItem{Scenario: scenario, ItemType: scenType}130 spec := &gauge_messages.ProtoSpec{SpecHeading: "HEADING", FileName: "FILENAME", Items: []*gauge_messages.ProtoItem{scenItem}}131 specResult := &gauge_messages.ProtoSpecResult{ProtoSpec: spec, ScenarioCount: 1, Failed: true, ScenarioFailedCount: 1}132 suiteResult := &gauge_messages.ProtoSuiteResult{SpecResults: []*gauge_messages.ProtoSpecResult{specResult}}133 message := &gauge_messages.SuiteExecutionResult{SuiteResult: suiteResult}134 builder := &XmlBuilder{currentId: 0}135 bytes, _ := builder.GetXmlContent(message)136 assertXmlValidation(bytes, c)137 var suites JUnitTestSuites138 xml.Unmarshal(bytes, &suites)139 c.Assert(len(suites.Suites[0].TestCases), Equals, 1)140 c.Assert(suites.Suites[0].TestCases[0].Classname, Equals, "HEADING")141 c.Assert(suites.Suites[0].TestCases[0].Name, Equals, "Scenario1")142 failure := `Step Execution Failure: 'fail but don't stop'143nice little stacktrace144Step Execution Failure: 'continue on failure'145very easy to trace146Concept Execution Failure: 'fail but don't stop'147nice little stacktrace148Concept Execution Failure: 'continue on failure'149very easy to trace150Concept Execution Failure: 'fail but don't stop'151nice little stacktrace152Concept Execution Failure: 'continue on failure'153very easy to trace`154 c.Assert(suites.Suites[0].TestCases[0].Failure.Message, Equals, "Multiple failures")155 c.Assert(suites.Suites[0].TestCases[0].Failure.Contents, Equals, failure)156}157func (s *MySuite) TestToVerifyXmlContentForFailingHookExecutionResult(c *C) {158 builder := &XmlBuilder{currentId: 0}159 info := builder.getFailureFromExecutionResult("", nil, nil, nil, "PREFIX ")160 c.Assert(info.Message, Equals, "")161 c.Assert(info.Err, Equals, "")162 failure := &gauge_messages.ProtoHookFailure{StackTrace: "StackTrace", ErrorMessage: "ErrorMessage"}163 hookInfo := builder.getFailureFromExecutionResult("", failure, nil, nil, "PREFIX ")164 c.Assert(hookInfo.Message, Equals, "PREFIX "+preHookFailureMsg+": 'ErrorMessage'")165 c.Assert(hookInfo.Err, Equals, "StackTrace")166 hookInfo = builder.getFailureFromExecutionResult("", nil, failure, nil, "PREFIX ")167 c.Assert(hookInfo.Message, Equals, "PREFIX "+postHookFailureMsg+": 'ErrorMessage'")168 c.Assert(hookInfo.Err, Equals, "StackTrace")169 hookInfo = builder.getFailureFromExecutionResult("Foo", nil, failure, nil, "PREFIX ")170 c.Assert(hookInfo.Message, Equals, "Foo\nPREFIX "+postHookFailureMsg+": 'ErrorMessage'")171 c.Assert(hookInfo.Err, Equals, "StackTrace")172 executionFailure := &gauge_messages.ProtoExecutionResult{StackTrace: "StackTrace", ErrorMessage: "ErrorMessage", Failed: true}173 execInfo := builder.getFailureFromExecutionResult("Foo", nil, nil, executionFailure, "PREFIX ")174 c.Assert(execInfo.Message, Equals, "Foo\nPREFIX "+executionFailureMsg+": 'ErrorMessage'")175 c.Assert(execInfo.Err, Equals, "StackTrace")176}177func (s *MySuite) TestToVerifyXmlContentForDataTableDrivenExecution(c *C) {178 value := gauge_messages.ProtoItem_TableDrivenScenario179 scenario1 := gauge_messages.ProtoScenario{Failed: false, ScenarioHeading: "Scenario"}180 scenario2 := gauge_messages.ProtoScenario{Failed: false, ScenarioHeading: "Scenario"}181 item1 := &gauge_messages.ProtoItem{TableDrivenScenario: &gauge_messages.ProtoTableDrivenScenario{Scenario: &scenario1, TableRowIndex: 1}, ItemType: value}182 item2 := &gauge_messages.ProtoItem{TableDrivenScenario: &gauge_messages.ProtoTableDrivenScenario{Scenario: &scenario2, TableRowIndex: 2}, ItemType: value}183 spec1 := &gauge_messages.ProtoSpec{SpecHeading: "HEADING", FileName: "FILENAME", Items: []*gauge_messages.ProtoItem{item1, item2}}184 specResult := &gauge_messages.ProtoSpecResult{ProtoSpec: spec1, ScenarioCount: 1, Failed: false}185 suiteResult := &gauge_messages.ProtoSuiteResult{SpecResults: []*gauge_messages.ProtoSpecResult{specResult}}186 message := &gauge_messages.SuiteExecutionResult{SuiteResult: suiteResult}187 builder := &XmlBuilder{currentId: 0}188 bytes, err := builder.GetXmlContent(message)189 assertXmlValidation(bytes, c)190 var suites JUnitTestSuites191 xml.Unmarshal(bytes, &suites)192 c.Assert(err, Equals, nil)193 c.Assert(len(suites.Suites), Equals, 1)194 c.Assert(suites.Suites[0].Errors, Equals, 0)195 c.Assert(suites.Suites[0].Failures, Equals, 0)196 c.Assert(suites.Suites[0].Package, Equals, "FILENAME")197 c.Assert(suites.Suites[0].Name, Equals, "HEADING")198 c.Assert(suites.Suites[0].Tests, Equals, 1)199 c.Assert(suites.Suites[0].Timestamp, Equals, builder.suites.Suites[0].Timestamp)200 c.Assert(suites.Suites[0].SystemError.Contents, Equals, "")201 c.Assert(suites.Suites[0].SystemOutput.Contents, Equals, "")202 c.Assert(len(suites.Suites[0].TestCases), Equals, 2)203 c.Assert(suites.Suites[0].TestCases[0].Name, Equals, "Scenario 2")204 c.Assert(suites.Suites[0].TestCases[1].Name, Equals, "Scenario 3")205}206func (s *MySuite) TestToVerifyXmlContentForErroredSpec(c *C) {207 value := gauge_messages.ProtoItem_TableDrivenScenario208 scenario1 := gauge_messages.ProtoScenario{Failed: false, ScenarioHeading: "Scenario"}209 item1 := &gauge_messages.ProtoItem{TableDrivenScenario: &gauge_messages.ProtoTableDrivenScenario{Scenario: &scenario1, TableRowIndex: 1}, ItemType: value}210 spec1 := &gauge_messages.ProtoSpec{SpecHeading: "HEADING", FileName: "FILENAME", Items: []*gauge_messages.ProtoItem{item1}}211 specResult := &gauge_messages.ProtoSpecResult{ProtoSpec: spec1, ScenarioCount: 1, Failed: true, Errors: []*gauge_messages.Error{{Type: gauge_messages.Error_PARSE_ERROR, Message: "message"}}}212 suiteResult := &gauge_messages.ProtoSuiteResult{SpecResults: []*gauge_messages.ProtoSpecResult{specResult}}213 message := &gauge_messages.SuiteExecutionResult{SuiteResult: suiteResult}214 builder := &XmlBuilder{currentId: 0}215 bytes, err := builder.GetXmlContent(message)216 assertXmlValidation(bytes, c)217 var suites JUnitTestSuites218 xml.Unmarshal(bytes, &suites)219 c.Assert(err, Equals, nil)220 c.Assert(*suites.Suites[0].TestCases[0].Failure, Equals, JUnitFailure{221 Message: "Parse/Validation Errors",222 Type: "Parse/Validation Errors",223 Contents: "[Parse Error] message",224 })225}226func assertXmlValidation(xml []byte, c *C) {227 doc, err := libxml2.Parse(xml)228 c.Assert(err, Equals, nil)229 err = junitSchema.Validate(doc)230 if err != nil {231 var errors []string232 for _, e := range err.(xsd.SchemaValidationError).Errors() {233 errors = append(errors, e.Error())234 }235 c.Assert(err, Equals, nil, Commentf(strings.Join(errors, "\n")))236 }237}...
merge_test.go
Source:merge_test.go
1// Copyright 2015 ThoughtWorks, Inc.2// This file is part of Gauge.3// Gauge is free software: you can redistribute it and/or modify4// it under the terms of the GNU General Public License as published by5// the Free Software Foundation, either version 3 of the License, or6// (at your option) any later version.7// Gauge is distributed in the hope that it will be useful,8// but WITHOUT ANY WARRANTY; without even the implied warranty of9// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the10// GNU General Public License for more details.11// You should have received a copy of the GNU General Public License12// along with Gauge. If not, see <http://www.gnu.org/licenses/>.13package execution14import (15 "testing"16 "reflect"17 "github.com/getgauge/gauge/execution/result"18 gm "github.com/getgauge/gauge/gauge_messages"19)20type stat struct {21 failed int22 skipped int23 total int24}25var statsTests = []struct {26 status gm.ExecutionStatus27 want stat28 message string29}{30 {gm.ExecutionStatus_FAILED, stat{failed: 1, total: 1}, "Scenario Failure"},31 {gm.ExecutionStatus_SKIPPED, stat{skipped: 1, total: 1}, "Scenario Skipped"},32 {gm.ExecutionStatus_PASSED, stat{total: 1}, "Scenario Passed"},33}34func TestModifySpecStats(t *testing.T) {35 for _, test := range statsTests {36 res := &result.SpecResult{}37 modifySpecStats(&gm.ProtoScenario{ExecutionStatus: test.status}, res)38 got := stat{failed: res.ScenarioFailedCount, skipped: res.ScenarioSkippedCount, total: res.ScenarioCount}39 if !reflect.DeepEqual(got, test.want) {40 t.Errorf("Modify spec stats failed for %s. Want: %v , Got: %v", test.message, test.want, got)41 }42 }43}44func TestAggregateDataTableScnStats(t *testing.T) {45 res := &result.SpecResult{}46 scns := map[string][]*gm.ProtoTableDrivenScenario{47 "heading1": []*gm.ProtoTableDrivenScenario{48 {Scenario: &gm.ProtoScenario{ExecutionStatus: gm.ExecutionStatus_PASSED}},49 {Scenario: &gm.ProtoScenario{ExecutionStatus: gm.ExecutionStatus_FAILED}},50 {Scenario: &gm.ProtoScenario{51 ExecutionStatus: gm.ExecutionStatus_SKIPPED,52 SkipErrors: []string{"--table-rows"},53 }},54 },55 "heading2": []*gm.ProtoTableDrivenScenario{{Scenario: &gm.ProtoScenario{56 ExecutionStatus: gm.ExecutionStatus_SKIPPED,57 SkipErrors: []string{""},58 }}},59 "heading3": []*gm.ProtoTableDrivenScenario{{Scenario: &gm.ProtoScenario{ExecutionStatus: gm.ExecutionStatus_PASSED}}},60 "heading4": []*gm.ProtoTableDrivenScenario{{Scenario: &gm.ProtoScenario{ExecutionStatus: gm.ExecutionStatus_FAILED}}},61 }62 aggregateDataTableScnStats(scns, res)63 got := stat{failed: res.ScenarioFailedCount, skipped: res.ScenarioSkippedCount, total: res.ScenarioCount}64 want := stat{failed: 2, skipped: 1, total: 5}65 if !reflect.DeepEqual(got, want) {66 t.Errorf("Aggregate data table scenario stats failed. Want: %v , Got: %v", want, got)67 }68}69func TestMergeResults(t *testing.T) {70 got := mergeResults([]*result.SpecResult{71 {72 ProtoSpec: &gm.ProtoSpec{73 PreHookFailures: []*gm.ProtoHookFailure{{StackTrace: "stacktrace"}},74 SpecHeading: "heading", FileName: "filename", Tags: []string{"tags"},75 PostHookFailures: []*gm.ProtoHookFailure{{StackTrace: "stacktrace"}},76 Items: []*gm.ProtoItem{77 {ItemType: gm.ProtoItem_Table, Table: &gm.ProtoTable{Headers: &gm.ProtoTableRow{Cells: []string{"a"}}, Rows: []*gm.ProtoTableRow{{Cells: []string{"b"}}}}},78 {ItemType: gm.ProtoItem_Scenario, Scenario: &gm.ProtoScenario{ExecutionStatus: gm.ExecutionStatus_PASSED, ScenarioHeading: "scenario Heading1"}},79 {80 ItemType: gm.ProtoItem_TableDrivenScenario, TableDrivenScenario: &gm.ProtoTableDrivenScenario{81 Scenario: &gm.ProtoScenario{ExecutionStatus: gm.ExecutionStatus_PASSED, ScenarioHeading: "scenario Heading2"},82 TableRowIndex: 0,83 },84 },85 },86 }, ExecutionTime: int64(1),87 },88 {89 ProtoSpec: &gm.ProtoSpec{90 PreHookFailures: []*gm.ProtoHookFailure{{StackTrace: "stacktrace1"}},91 SpecHeading: "heading", FileName: "filename", Tags: []string{"tags"},92 PostHookFailures: []*gm.ProtoHookFailure{{StackTrace: "stacktrace1"}},93 Items: []*gm.ProtoItem{94 {ItemType: gm.ProtoItem_Table, Table: &gm.ProtoTable{Headers: &gm.ProtoTableRow{Cells: []string{"a"}}, Rows: []*gm.ProtoTableRow{{Cells: []string{"c"}}}}},95 {96 ItemType: gm.ProtoItem_TableDrivenScenario, TableDrivenScenario: &gm.ProtoTableDrivenScenario{97 Scenario: &gm.ProtoScenario{ExecutionStatus: gm.ExecutionStatus_PASSED, ScenarioHeading: "scenario Heading2"},98 TableRowIndex: 1,99 },100 },101 },102 }, ExecutionTime: int64(2),103 },104 })105 want := &result.SpecResult{106 ProtoSpec: &gm.ProtoSpec{107 PreHookFailures: []*gm.ProtoHookFailure{{StackTrace: "stacktrace"}, {StackTrace: "stacktrace1", TableRowIndex: 1}},108 SpecHeading: "heading", FileName: "filename", Tags: []string{"tags"},109 PostHookFailures: []*gm.ProtoHookFailure{{StackTrace: "stacktrace"}, {StackTrace: "stacktrace1", TableRowIndex: 1}},110 Items: []*gm.ProtoItem{111 {ItemType: gm.ProtoItem_Table, Table: &gm.ProtoTable{Headers: &gm.ProtoTableRow{Cells: []string{"a"}}, Rows: []*gm.ProtoTableRow{{Cells: []string{"b"}}, {Cells: []string{"c"}}}}},112 {ItemType: gm.ProtoItem_Scenario, Scenario: &gm.ProtoScenario{ExecutionStatus: gm.ExecutionStatus_PASSED, ScenarioHeading: "scenario Heading1"}},113 {114 ItemType: gm.ProtoItem_TableDrivenScenario, TableDrivenScenario: &gm.ProtoTableDrivenScenario{115 Scenario: &gm.ProtoScenario{ExecutionStatus: gm.ExecutionStatus_PASSED, ScenarioHeading: "scenario Heading2"},116 TableRowIndex: 0,117 },118 },119 {120 ItemType: gm.ProtoItem_TableDrivenScenario, TableDrivenScenario: &gm.ProtoTableDrivenScenario{121 Scenario: &gm.ProtoScenario{ExecutionStatus: gm.ExecutionStatus_PASSED, ScenarioHeading: "scenario Heading2"},122 TableRowIndex: 1,123 },124 },125 }, IsTableDriven: true,126 },127 ScenarioCount: 3, ScenarioSkippedCount: 0, ScenarioFailedCount: 0, IsFailed: false, Skipped: false, ExecutionTime: int64(3),128 }129 if !reflect.DeepEqual(got, want) {130 t.Errorf("Merge data table spec results failed.\n\tWant: %v\n\tGot: %v", want, got)131 }132}133func TestMergeSkippedResults(t *testing.T) {134 got := mergeResults([]*result.SpecResult{135 {136 ProtoSpec: &gm.ProtoSpec{137 PreHookFailures: []*gm.ProtoHookFailure{{StackTrace: "stacktrace"}},138 SpecHeading: "heading", FileName: "filename", Tags: []string{"tags"},139 PostHookFailures: []*gm.ProtoHookFailure{{StackTrace: "stacktrace"}},140 Items: []*gm.ProtoItem{141 {ItemType: gm.ProtoItem_Table, Table: &gm.ProtoTable{Headers: &gm.ProtoTableRow{Cells: []string{"a"}}, Rows: []*gm.ProtoTableRow{{Cells: []string{"b"}}}}},142 {ItemType: gm.ProtoItem_Scenario, Scenario: &gm.ProtoScenario{ExecutionStatus: gm.ExecutionStatus_SKIPPED, ScenarioHeading: "scenario Heading1", SkipErrors: []string{"error"}}},143 {144 ItemType: gm.ProtoItem_TableDrivenScenario, TableDrivenScenario: &gm.ProtoTableDrivenScenario{145 Scenario: &gm.ProtoScenario{ExecutionStatus: gm.ExecutionStatus_SKIPPED, ScenarioHeading: "scenario Heading2", SkipErrors: []string{"error"}},146 TableRowIndex: 0,147 },148 },149 },150 }, ExecutionTime: int64(1),151 Skipped: true,152 },153 {154 ProtoSpec: &gm.ProtoSpec{155 PreHookFailures: []*gm.ProtoHookFailure{{StackTrace: "stacktrace1"}},156 SpecHeading: "heading", FileName: "filename", Tags: []string{"tags"},157 PostHookFailures: []*gm.ProtoHookFailure{{StackTrace: "stacktrace1"}},158 Items: []*gm.ProtoItem{159 {ItemType: gm.ProtoItem_Table, Table: &gm.ProtoTable{Headers: &gm.ProtoTableRow{Cells: []string{"a"}}, Rows: []*gm.ProtoTableRow{{Cells: []string{"c"}}}}},160 {161 ItemType: gm.ProtoItem_TableDrivenScenario, TableDrivenScenario: &gm.ProtoTableDrivenScenario{162 Scenario: &gm.ProtoScenario{ExecutionStatus: gm.ExecutionStatus_SKIPPED, ScenarioHeading: "scenario Heading2", SkipErrors: []string{"error"}},163 TableRowIndex: 1,164 },165 },166 },167 }, ExecutionTime: int64(2),168 Skipped: true,169 },170 })171 want := &result.SpecResult{172 ProtoSpec: &gm.ProtoSpec{173 PreHookFailures: []*gm.ProtoHookFailure{{StackTrace: "stacktrace"}, {StackTrace: "stacktrace1", TableRowIndex: 1}},174 SpecHeading: "heading", FileName: "filename", Tags: []string{"tags"},175 PostHookFailures: []*gm.ProtoHookFailure{{StackTrace: "stacktrace"}, {StackTrace: "stacktrace1", TableRowIndex: 1}},176 Items: []*gm.ProtoItem{177 {ItemType: gm.ProtoItem_Table, Table: &gm.ProtoTable{Headers: &gm.ProtoTableRow{Cells: []string{"a"}}, Rows: []*gm.ProtoTableRow{{Cells: []string{"b"}}, {Cells: []string{"c"}}}}},178 {ItemType: gm.ProtoItem_Scenario, Scenario: &gm.ProtoScenario{ExecutionStatus: gm.ExecutionStatus_SKIPPED, SkipErrors: []string{"error"}, ScenarioHeading: "scenario Heading1"}},179 {180 ItemType: gm.ProtoItem_TableDrivenScenario, TableDrivenScenario: &gm.ProtoTableDrivenScenario{181 Scenario: &gm.ProtoScenario{ExecutionStatus: gm.ExecutionStatus_SKIPPED, SkipErrors: []string{"error"}, ScenarioHeading: "scenario Heading2"},182 TableRowIndex: 0,183 },184 },185 {186 ItemType: gm.ProtoItem_TableDrivenScenario, TableDrivenScenario: &gm.ProtoTableDrivenScenario{187 Scenario: &gm.ProtoScenario{ExecutionStatus: gm.ExecutionStatus_SKIPPED, SkipErrors: []string{"error"}, ScenarioHeading: "scenario Heading2"},188 TableRowIndex: 1,189 },190 },191 }, IsTableDriven: true,192 },193 ScenarioCount: 3, ScenarioSkippedCount: 3, ScenarioFailedCount: 0, IsFailed: false, Skipped: true, ExecutionTime: int64(3),194 }195 if !reflect.DeepEqual(got, want) {196 t.Errorf("Merge data table spec results failed.\n\tWant: %v\n\tGot: %v", want, got)197 }198}199func TestMergeResultsExecutionTimeInParallel(t *testing.T) {200 InParallel = true201 got := mergeResults([]*result.SpecResult{202 {203 ProtoSpec: &gm.ProtoSpec{204 SpecHeading: "heading", FileName: "filename", Tags: []string{"tags"},205 }, ExecutionTime: int64(1),206 },207 {208 ProtoSpec: &gm.ProtoSpec{209 SpecHeading: "heading", FileName: "filename", Tags: []string{"tags"},210 }, ExecutionTime: int64(2),211 },212 })213 want := int64(2)214 InParallel = false215 if !reflect.DeepEqual(got.ExecutionTime, want) {216 t.Errorf("Execution time in parallel data table spec results.\n\tWant: %v\n\tGot: %v", want, got.ExecutionTime)217 }218}219func TestMergeDataTableSpecResults(t *testing.T) {220 res := &result.SuiteResult{221 Environment: "env",222 ProjectName: "name",223 Tags: "tags",224 SpecResults: []*result.SpecResult{225 {226 ProtoSpec: &gm.ProtoSpec{227 SpecHeading: "heading", FileName: "filename", Tags: []string{"tags"},228 Items: []*gm.ProtoItem{229 {ItemType: gm.ProtoItem_Scenario, Scenario: &gm.ProtoScenario{ExecutionStatus: gm.ExecutionStatus_PASSED, ScenarioHeading: "scenario Heading1"}},230 },231 },232 },233 },234 }235 got := mergeDataTableSpecResults(res)236 want := &result.SuiteResult{237 Environment: "env",238 ProjectName: "name",239 Tags: "tags",240 SpecResults: []*result.SpecResult{241 {242 ProtoSpec: &gm.ProtoSpec{243 SpecHeading: "heading", FileName: "filename", Tags: []string{"tags"},244 Items: []*gm.ProtoItem{245 {ItemType: gm.ProtoItem_Scenario, Scenario: &gm.ProtoScenario{ExecutionStatus: gm.ExecutionStatus_PASSED, ScenarioHeading: "scenario Heading1"}},246 },247 },248 },249 },250 }251 if !reflect.DeepEqual(got, want) {252 t.Errorf("Merge data table spec results failed.\n\tWant: %v\n\tGot: %v", want, got)253 }254}255func TestGetItems(t *testing.T) {256 table := &gm.ProtoTable{Headers: &gm.ProtoTableRow{Cells: []string{"a"}}}257 res := []*result.SpecResult{{258 ProtoSpec: &gm.ProtoSpec{259 Items: []*gm.ProtoItem{260 {ItemType: gm.ProtoItem_Table},261 {ItemType: gm.ProtoItem_Scenario},262 {ItemType: gm.ProtoItem_TableDrivenScenario},263 },264 },265 }}266 scnRes := []*gm.ProtoItem{267 {ItemType: gm.ProtoItem_Scenario}, {ItemType: gm.ProtoItem_TableDrivenScenario}, {ItemType: gm.ProtoItem_Scenario},268 }269 got := getItems(table, scnRes, res)270 want := []*gm.ProtoItem{{ItemType: gm.ProtoItem_Table, Table: table}, {ItemType: gm.ProtoItem_Scenario}, {ItemType: gm.ProtoItem_TableDrivenScenario}, {ItemType: gm.ProtoItem_Scenario}}271 if !reflect.DeepEqual(got, want) {272 t.Errorf("Merge data table spec results failed.\n\tWant: %v\n\tGot: %v", want, got)273 }274}...
scenarioHeading
Using AI Code Generation
1package execution;2import java.io.IOException;3import java.util.ArrayList;4import java.util.List;5import org.apache.poi.EncryptedDocumentException;6import org.apache.poi.openxml4j.exceptions.InvalidFormatException;7import org.openqa.selenium.WebDriver;8import org.openqa.selenium.chrome.ChromeDriver;9import org.testng.annotations.AfterTest;10import org.testng.annotations.BeforeTest;11import org.testng.annotations.Test;12import com.relevantcodes.extentreports.ExtentReports;13import com.relevantcodes.extentreports.ExtentTest;14import com.relevantcodes.extentreports.LogStatus;15import testcases.TestCase;16import utilities.ExcelReader;17import utilities.ExtentReport;18import utilities.Screenshot;19public class Execution {20 WebDriver driver;21 ExtentReports report;22 ExtentTest test;23 ExcelReader excel;24 public void launchBrowser() throws EncryptedDocumentException, InvalidFormatException, IOException {25 System.setProperty("webdriver.chrome.driver", "C:\\Users\\Sai\\Downloads\\chromedriver_win32\\chromedriver.exe");26 driver = new ChromeDriver();27 report = ExtentReport.getReport();28 excel = new ExcelReader();29 }30 @Test(priority = 0)31 public void scenarioHeading() throws IOException {32 test = report.startTest("Scenario Heading");33 List<String> scenarioHeading = new ArrayList<String>();34 scenarioHeading = excel.getScenarioHeading();35 for(int i=0;i<scenarioHeading.size();i++) {36 test.log(LogStatus.INFO, scenarioHeading.get(i));37 }38 report.endTest(test);39 }40 @Test(priority = 1)41 public void testCase1() throws IOException {42 test = report.startTest("TestCase1");43 TestCase testCase = new TestCase();44 testCase.testCase1(driver, test);45 report.endTest(test);46 }47 @Test(priority = 2)48 public void testCase2() throws IOException {49 test = report.startTest("TestCase2");50 TestCase testCase = new TestCase();51 testCase.testCase2(driver, test);52 report.endTest(test);53 }54 @Test(priority = 3)55 public void testCase3() throws IOException {56 test = report.startTest("TestCase3");57 TestCase testCase = new TestCase();58 testCase.testCase3(driver, test);59 report.endTest(test);60 }61 public void closeBrowser() {62 driver.quit();63 report.flush();64 }65}
scenarioHeading
Using AI Code Generation
1package com.qait.automation.getpageobjects;2import java.io.File;3import java.io.IOException;4import java.lang.reflect.Method;5import java.util.ArrayList;6import java.util.Arrays;7import java.util.HashMap;8import java.util.List;9import java.util.Map;10import org.apache.commons.io.FileUtils;11import org.openqa.selenium.WebDriver;12import org.openqa.selenium.WebElement;13import org.openqa.selenium.support.PageFactory;14import org.openqa.selenium.support.ui.Select;15import org.testng.annotations.DataProvider;16import com.qait.automation.utils.ConfigPropertyReader;17import com.qait.automation.utils.YamlReader;18public class GetPage {19 public static WebDriver driver;20 public String pageName;21 public static ConfigPropertyReader configPropertyReader;22 public static String configPropertyFilePath = "src/test/resources/properties/config.properties";23 public static String testDataFilePath = "src/test/resources/TestData/";24 public static String testConfigFilePath = "src/test/resources/TestConfig/";25 public static String testReportsFilePath = "src/test/resources/TestReports/";26 public static String testReports = "src/test/resources/TestReports/";27 public static String testLogFilePath = "src/test/resources/TestLog/";28 public static String testLogFile = "src/test/resources/TestLog/";29 public static String testLog = "src/test/resources/TestLog/";30 public static String testConfig = "src/test/resources/TestConfig/";31 public static String testData = "src/test/resources/TestData/";32 public static String testConfigFile = "src/test/resources/TestConfig/";33 public static String testDataFile = "src/test/resources/TestData/";34 public static String testReportFilePath = "src/test/resources/TestReports/";35 public static String testReportFile = "src/test/resources/TestReports/";36 public static String testReport = "src/test/resources/TestReports/";37 public static String testLogs = "src/test/resources/TestLog/";38 public static String testLogFileName = "src/test/resources/TestLog/";39 public static String testLogFilePathName = "src/test/resources/TestLog/";40 public static String testReportFileName = "src/test/resources/TestReports/";41 public static String testReportFilePathName = "src/test/resources/TestReports/";42 public static String testConfigFileName = "src/test/resources/TestConfig/";43 public static String testConfigFilePathName = "src/test/resources/TestConfig/";44 public static String testDataFileName = "src/test/resources/TestData/";45 public static String testDataFilePathName = "src/test/resources/TestData/";
scenarioHeading
Using AI Code Generation
1func scenarioHeading() {2}3func scenarioHeading() {4}5func scenarioHeading() {6}7func scenarioHeading() {8}9func scenarioHeading() {10}11func scenarioHeading() {12}13func scenarioHeading() {14}15func scenarioHeading() {16}17func scenarioHeading() {18}19func scenarioHeading() {20}
scenarioHeading
Using AI Code Generation
1public class TestRunner {2 private final Execution execution = new Execution();3 public void test1() {4 execution.scenarioHeading("Test 1");5 }6 public void test2() {7 execution.scenarioHeading("Test 2");8 }9}
scenarioHeading
Using AI Code Generation
1import (2func main() {3 fmt.Println("Hello World")4 cucumber.ScenarioHeading("This is a test")5}6import (7func main() {8 fmt.Println("Hello World")9 cucumber.ScenarioHeading("This is a test")10}11import (12func main() {13 fmt.Println("Hello World")14 cucumber.ScenarioHeading("This is a test")15}16import (17func main() {18 fmt.Println("Hello World")19 cucumber.ScenarioHeading("This is a test")20}21import (22func main() {23 fmt.Println("Hello World")24 cucumber.ScenarioHeading("This is a test")25}26import (27func main() {28 fmt.Println("Hello World")29 cucumber.ScenarioHeading("This is a test")30}31import (32func main() {33 fmt.Println("Hello World")34 cucumber.ScenarioHeading("This is a test")35}36import (37func main() {38 fmt.Println("Hello World")39 cucumber.ScenarioHeading("This is a test")40}41import (42func main() {43 fmt.Println("
scenarioHeading
Using AI Code Generation
1import (2func main() {3 fmt.Println("Hello, playground")4 ex.ScenarioHeading("Test")5}6import (7type Execution struct {8}9func (e *Execution) ScenarioHeading(scenarioName string) {10 fmt.Println("Scenario: " + scenarioName)11}12import (13func TestScenarioHeading(t *testing.T) {14 ex.ScenarioHeading("Test")15}
scenarioHeading
Using AI Code Generation
1package execution;2import java.io.IOException;3import org.openqa.selenium.WebDriver;4import com.aventstack.extentreports.ExtentTest;5import commonUtilities.CaptureScreenshot;6public class Execution {7public static void scenarioHeading(WebDriver driver,ExtentTest logger,String scenarioName) throws IOException8{9logger=report.createTest(scenarioName);
scenarioHeading
Using AI Code Generation
1package com.automation.main.scenario;2import org.testng.annotations.Test;3import com.automation.main.execution.Execution;4public class Scenario1 extends Execution {5 public void scenarioHeading() {6 System.out.println("Scenario 1");7 }8}9package com.automation.main.scenario;10import org.testng.annotations.Test;11import com.automation.main.execution.Execution;12public class Scenario2 extends Execution {13 public void scenarioHeading() {14 System.out.println("Scenario 2");15 }16}17package com.automation.main.scenario;18import org.testng.annotations.Test;19import com.automation.main.execution.Execution;20public class Scenario3 extends Execution {21 public void scenarioHeading() {22 System.out.println("Scenario 3");23 }24}25package com.automation.main.scenario;26import org.testng.annotations.Test;27import com.automation.main.execution.Execution;28public class Scenario4 extends Execution {29 public void scenarioHeading() {30 System.out.println("Scenario 4");31 }32}33package com.automation.main.scenario;34import org.testng.annotations.Test;35import com.automation.main.execution.Execution;36public class Scenario5 extends Execution {37 public void scenarioHeading() {38 System.out.println("Scenario 5");39 }40}41package com.automation.main.scenario;42import org.testng.annotations.Test;43import com.automation.main.execution.Execution;44public class Scenario6 extends Execution {45 public void scenarioHeading() {46 System.out.println("Scenario 6");47 }48}49package com.automation.main.scenario;50import org.testng.annotations.Test;51import com.automation.main.execution.Execution;52public class Scenario7 extends Execution {
scenarioHeading
Using AI Code Generation
1import (2func main() {3 execution.ScenarioHeading("Scenario 1")4 fmt.Println("This is scenario 1")5}6import (7func main() {8 execution.ScenarioHeading("Scenario 2")9 fmt.Println("This is scenario 2")10}11import (12func main() {13 execution.ScenarioHeading("Scenario 3")14 fmt.Println("This is scenario 3")15}16import (17func main() {18 execution.ScenarioHeading("Scenario 4")19 fmt.Println("This is scenario 4")20}21import (22func main() {23 execution.ScenarioHeading("Scenario 5")24 fmt.Println("This is scenario 5")25}26import (27func main() {28 execution.ScenarioHeading("Scenario 6")29 fmt.Println("This is scenario 6")30}31import (
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!