Best Gauge code snippet using execution.getTagValue
specExecutor.go
Source:specExecutor.go
...41 CurrentSpec: &gauge_messages.SpecInfo{42 Name: s.Heading.Value,43 FileName: s.FileName,44 IsFailed: false,45 Tags: getTagValue(s.Tags)},46 }47 return &specExecutor{48 specification: s,49 runner: r,50 pluginHandler: ph,51 errMap: e,52 stream: stream,53 currentExecutionInfo: ei,54 scenarioExecutor: newScenarioExecutor(r, ph, ei, e, s.Contexts, s.TearDownSteps, stream),55 }56}57func (e *specExecutor) execute(executeBefore, execute, executeAfter bool) *result.SpecResult {58 e.specResult = gauge.NewSpecResult(e.specification)59 if errs, ok := e.errMap.SpecErrs[e.specification]; ok {60 if hasParseError(errs) {61 e.failSpec()62 return e.specResult63 }64 }65 lookup, err := e.dataTableLookup()66 if err != nil {67 logger.Fatalf(true, "Failed to resolve Specifications : %s", err.Error())68 }69 resolvedSpecItems, err := resolveItems(e.specification.GetSpecItems(), lookup, e.setSkipInfo)70 if err != nil {71 logger.Fatalf(true, "Failed to resolve Specifications : %s", err.Error())72 }73 e.specResult.AddSpecItems(resolvedSpecItems)74 if executeBefore {75 event.Notify(event.NewExecutionEvent(event.SpecStart, e.specification, e.specResult, e.stream, *e.currentExecutionInfo))76 if _, ok := e.errMap.SpecErrs[e.specification]; !ok {77 if res := e.initSpecDataStore(); res.GetFailed() {78 e.skipSpecForError(fmt.Errorf("Failed to initialize spec datastore. Error: %s", res.GetErrorMessage()))79 } else {80 e.notifyBeforeSpecHook()81 }82 } else {83 e.specResult.SetSkipped(true)84 e.specResult.Errors = e.convertErrors(e.errMap.SpecErrs[e.specification])85 }86 }87 if execute && !e.specResult.GetFailed() {88 if e.specification.DataTable.Table.GetRowCount() == 0 {89 others, tableDriven := parser.FilterTableRelatedScenarios(e.specification.Scenarios, func(s *gauge.Scenario) bool {90 return s.ScenarioDataTableRow.IsInitialized()91 })92 results, err := e.executeScenarios(others)93 if err != nil {94 logger.Fatalf(true, "Failed to resolve Specifications : %s", err.Error())95 }96 e.specResult.AddScenarioResults(results)97 scnMap := make(map[int]bool, 0)98 for _, s := range tableDriven {99 if _, ok := scnMap[s.Span.Start]; !ok {100 scnMap[s.Span.Start] = true101 }102 r, err := e.executeScenario(s)103 if err != nil {104 logger.Fatalf(true, "Failed to resolve Specifications : %s", err.Error())105 }106 e.specResult.AddTableDrivenScenarioResult(r, gauge.ConvertToProtoTable(&s.DataTable.Table),107 s.ScenarioDataTableRowIndex, s.SpecDataTableRowIndex, s.SpecDataTableRow.IsInitialized())108 }109 e.specResult.ScenarioCount += len(scnMap)110 } else {111 e.executeSpec()112 }113 }114 e.specResult.SetSkipped(e.specResult.Skipped || e.specResult.ScenarioSkippedCount == len(e.specification.Scenarios))115 if executeAfter {116 if _, ok := e.errMap.SpecErrs[e.specification]; !ok {117 e.notifyAfterSpecHook()118 }119 event.Notify(event.NewExecutionEvent(event.SpecEnd, e.specification, e.specResult, e.stream, *e.currentExecutionInfo))120 }121 return e.specResult122}123func (e *specExecutor) executeTableRelatedScenarios(scenarios []*gauge.Scenario) error {124 if len(scenarios) > 0 {125 index := e.specification.Scenarios[0].SpecDataTableRowIndex126 sceRes, err := e.executeScenarios(scenarios)127 if err != nil {128 return err129 }130 result := [][]result.Result{sceRes}131 e.specResult.AddTableRelatedScenarioResult(result, index)132 }133 return nil134}135func (e *specExecutor) executeSpec() error {136 parser.GetResolvedDataTablerows(e.specification.DataTable.Table)137 nonTableRelatedScenarios, tableRelatedScenarios := parser.FilterTableRelatedScenarios(e.specification.Scenarios, func(s *gauge.Scenario) bool {138 return s.SpecDataTableRow.IsInitialized()139 })140 res, err := e.executeScenarios(nonTableRelatedScenarios)141 if err != nil {142 return err143 }144 e.specResult.AddScenarioResults(res)145 e.executeTableRelatedScenarios(tableRelatedScenarios)146 return nil147}148func (e *specExecutor) initSpecDataStore() *gauge_messages.ProtoExecutionResult {149 initSpecDataStoreMessage := &gauge_messages.Message{MessageType: gauge_messages.Message_SpecDataStoreInit,150 SpecDataStoreInitRequest: &gauge_messages.SpecDataStoreInitRequest{}}151 return e.runner.ExecuteAndGetStatus(initSpecDataStoreMessage)152}153func (e *specExecutor) notifyBeforeSpecHook() {154 m := &gauge_messages.Message{MessageType: gauge_messages.Message_SpecExecutionStarting,155 SpecExecutionStartingRequest: &gauge_messages.SpecExecutionStartingRequest{CurrentExecutionInfo: e.currentExecutionInfo}}156 e.pluginHandler.NotifyPlugins(m)157 res := executeHook(m, e.specResult, e.runner)158 e.specResult.ProtoSpec.PreHookMessages = res.Message159 e.specResult.ProtoSpec.PreHookScreenshots = res.Screenshots160 if res.GetFailed() {161 setSpecFailure(e.currentExecutionInfo)162 handleHookFailure(e.specResult, res, result.AddPreHook)163 }164}165func (e *specExecutor) notifyAfterSpecHook() {166 e.currentExecutionInfo.CurrentScenario = nil167 m := &gauge_messages.Message{MessageType: gauge_messages.Message_SpecExecutionEnding,168 SpecExecutionEndingRequest: &gauge_messages.SpecExecutionEndingRequest{CurrentExecutionInfo: e.currentExecutionInfo}}169 res := executeHook(m, e.specResult, e.runner)170 e.specResult.ProtoSpec.PostHookMessages = res.Message171 e.specResult.ProtoSpec.PostHookScreenshots = res.Screenshots172 if res.GetFailed() {173 setSpecFailure(e.currentExecutionInfo)174 handleHookFailure(e.specResult, res, result.AddPostHook)175 }176 e.pluginHandler.NotifyPlugins(m)177}178func (e *specExecutor) skipSpecForError(err error) {179 logger.Errorf(true, err.Error())180 validationError := validation.NewStepValidationError(&gauge.Step{LineNo: e.specification.Heading.LineNo, LineText: e.specification.Heading.Value},181 err.Error(), e.specification.FileName, nil, "")182 for _, scenario := range e.specification.Scenarios {183 e.errMap.ScenarioErrs[scenario] = []error{validationError}184 }185 e.errMap.SpecErrs[e.specification] = []error{validationError}186 e.specResult.Errors = e.convertErrors(e.errMap.SpecErrs[e.specification])187 e.specResult.SetSkipped(true)188}189func (e *specExecutor) failSpec() {190 e.specResult.Errors = e.convertErrors(e.errMap.SpecErrs[e.specification])191 e.specResult.SetFailure()192}193func (e *specExecutor) convertErrors(specErrors []error) []*gauge_messages.Error {194 var errors []*gauge_messages.Error195 for _, e := range specErrors {196 switch e.(type) {197 case parser.ParseError:198 err := e.(parser.ParseError)199 errors = append(errors, &gauge_messages.Error{200 Message: err.Error(),201 LineNumber: int32(err.LineNo),202 Filename: err.FileName,203 Type: gauge_messages.Error_PARSE_ERROR,204 })205 case validation.StepValidationError, validation.SpecValidationError:206 errors = append(errors, &gauge_messages.Error{207 Message: e.Error(),208 Type: gauge_messages.Error_VALIDATION_ERROR,209 })210 }211 }212 return errors213}214func (e *specExecutor) setSkipInfo(protoStep *gauge_messages.ProtoStep, step *gauge.Step) {215 protoStep.StepExecutionResult = &gauge_messages.ProtoStepExecutionResult{}216 protoStep.StepExecutionResult.Skipped = false217 if _, ok := e.errMap.StepErrs[step]; ok {218 protoStep.StepExecutionResult.Skipped = true219 protoStep.StepExecutionResult.SkippedReason = "Step implementation not found"220 }221}222func (e *specExecutor) getItemsForScenarioExecution(steps []*gauge.Step) ([]*gauge_messages.ProtoItem, error) {223 items := make([]gauge.Item, len(steps))224 for i, context := range steps {225 items[i] = context226 }227 lookup, err := e.dataTableLookup()228 if err != nil {229 return nil, err230 }231 return resolveItems(items, lookup, e.setSkipInfo)232}233func (e *specExecutor) dataTableLookup() (*gauge.ArgLookup, error) {234 l := new(gauge.ArgLookup)235 err := l.ReadDataTableRow(&e.specification.DataTable.Table, 0)236 return l, err237}238func (e *specExecutor) executeScenarios(scenarios []*gauge.Scenario) ([]result.Result, error) {239 var scenarioResults []result.Result240 for _, scenario := range scenarios {241 sceResult, err := e.executeScenario(scenario)242 if err != nil {243 return nil, err244 }245 scenarioResults = append(scenarioResults, sceResult)246 }247 return scenarioResults, nil248}249func (e *specExecutor) executeScenario(scenario *gauge.Scenario) (*result.ScenarioResult, error) {250 var scenarioResult *result.ScenarioResult251 shouldRetry := RetryOnlyTags == ""252 if !shouldRetry {253 spec := e.specification254 tagValues := make([]string, 0)255 if spec.Tags != nil {256 tagValues = spec.Tags.Values()257 }258 specFilter := filter.NewScenarioFilterBasedOnTags(tagValues, RetryOnlyTags)259 shouldRetry = !(specFilter.Filter(scenario))260 }261 for i := 0; i < MaxRetriesCount; i++ {262 e.currentExecutionInfo.CurrentScenario = &gauge_messages.ScenarioInfo{263 Name: scenario.Heading.Value,264 Tags: getTagValue(scenario.Tags),265 IsFailed: false,266 }267 scenarioResult = &result.ScenarioResult{268 ProtoScenario: gauge.NewProtoScenario(scenario),269 ScenarioDataTableRow: gauge.ConvertToProtoTable(&scenario.ScenarioDataTableRow),270 ScenarioDataTableRowIndex: scenario.ScenarioDataTableRowIndex,271 ScenarioDataTable: gauge.ConvertToProtoTable(&scenario.DataTable.Table),272 }273 if err := e.addAllItemsForScenarioExecution(scenario, scenarioResult); err != nil {274 return nil, err275 }276 e.scenarioExecutor.execute(scenario, scenarioResult)277 if scenarioResult.ProtoScenario.GetExecutionStatus() == gauge_messages.ExecutionStatus_SKIPPED {278 e.specResult.ScenarioSkippedCount++279 }280 if !(shouldRetry && scenarioResult.GetFailed()) {281 break282 }283 }284 return scenarioResult, nil285}286func (e *specExecutor) addAllItemsForScenarioExecution(scenario *gauge.Scenario, scenarioResult *result.ScenarioResult) error {287 contexts, err := e.getItemsForScenarioExecution(e.specification.Contexts)288 if err != nil {289 return err290 }291 scenarioResult.AddContexts(contexts)292 tearDownSteps, err := e.getItemsForScenarioExecution(e.specification.TearDownSteps)293 if err != nil {294 return err295 }296 scenarioResult.AddTearDownSteps(tearDownSteps)297 lookup, err := e.dataTableLookup()298 if err != nil {299 return err300 }301 if scenario.ScenarioDataTableRow.IsInitialized() {302 if err = lookup.ReadDataTableRow(&scenario.ScenarioDataTableRow, 0); err != nil {303 return err304 }305 }306 items, err := resolveItems(scenario.Items, lookup, e.setSkipInfo)307 if err != nil {308 return err309 }310 scenarioResult.AddItems(items)311 return nil312}313func getTagValue(tags *gauge.Tags) []string {314 var tagValues []string315 if tags != nil {316 tagValues = append(tagValues, tags.Values()...)317 }318 return tagValues319}320func setSpecFailure(executionInfo *gauge_messages.ExecutionInfo) {321 executionInfo.CurrentSpec.IsFailed = true322}323func shouldExecuteForRow(i int) bool {324 if len(tableRowsIndexes) < 1 {325 return true326 }327 for _, index := range tableRowsIndexes {...
getTagValue
Using AI Code Generation
1import (2type TagType struct {3 field1 bool "An important answer"4}5func main() {6 tt := TagType{true, "Barak Obama", 1}7 for i := 0; i < 3; i++ {8 refTag(tt, i)9 }10}11func refTag(tt TagType, ix int) {12 ttType := reflect.TypeOf(tt)13 ixField := ttType.Field(ix)14 fmt.Printf("%v15}16An important answer
getTagValue
Using AI Code Generation
1import (2func main() {3 if err != nil {4 log.Fatal(err)5 }6 address := common.HexToAddress("0x0b1e1c8a1
getTagValue
Using AI Code Generation
1import (2func main() {3 e := execution{}4 fmt.Println(e.getTagValue("name"))5}6type execution struct {7}8func (e execution) getTagValue(s string) string {9 t := reflect.TypeOf(e)10 f, _ := t.FieldByName(s)11 return f.Tag.Get("tag")12}
getTagValue
Using AI Code Generation
1import (2func main() {3 fmt.Println(getTagValue("main", "main"))4}5func getTagValue(pkg, name string) string {6 r := reflect.ValueOf(pkg).MethodByName(name)7 return r.Type().In(0).Field(0).Tag.Get("test")8}9func main() {10 fmt.Println("Hello World")11}12Note: We have used the Tag.Get() method to
getTagValue
Using AI Code Generation
1func main() {2 var tagValue = execution.getTagValue("1")3 println(tagValue)4}5func main() {6 var tagValue = execution.getTagValue("2")7 println(tagValue)8}9func main() {10 var tagValue = execution.getTagValue("3")11 println(tagValue)12}13func main() {14 var tagValue = execution.getTagValue("4")15 println(tagValue)16}17func main() {18 var tagValue = execution.getTagValue("5")19 println(tagValue)20}21func main() {22 var tagValue = execution.getTagValue("6")23 println(tagValue)24}25func main() {26 var tagValue = execution.getTagValue("7")27 println(tagValue)28}29func main() {30 var tagValue = execution.getTagValue("8")31 println(tagValue)32}33func main() {34 var tagValue = execution.getTagValue("9")35 println(tagValue)36}37func main() {38 var tagValue = execution.getTagValue("10")39 println(tag
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!!