How to use AllSteps method of infoGatherer Package

Best Gauge code snippet using infoGatherer.AllSteps

specDetails.go

Source:specDetails.go Github

copy

Full Screen

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 infoGatherer14import (15	"io/ioutil"16	"path/filepath"17	"sync"18	"os"19	"github.com/fsnotify/fsnotify"20	"github.com/getgauge/common"21	"github.com/getgauge/gauge/config"22	"github.com/getgauge/gauge/gauge"23	"github.com/getgauge/gauge/gauge_messages"24	"github.com/getgauge/gauge/logger"25	"github.com/getgauge/gauge/parser"26	"github.com/getgauge/gauge/util"27)28// SpecInfoGatherer contains the caches for specs, concepts, and steps29type SpecInfoGatherer struct {30	waitGroup         sync.WaitGroup31	mutex             sync.Mutex32	conceptDictionary *gauge.ConceptDictionary33	specsCache        map[string]*SpecDetail34	conceptsCache     map[string][]*gauge.Concept35	stepsCache        map[string]*gauge.StepValue36	SpecDirs          []string37}38type SpecDetail struct {39	Spec *gauge.Specification40	Errs []parser.ParseError41}42func (d *SpecDetail) HasSpec() bool {43	return d.Spec != nil && d.Spec.Heading != nil44}45// MakeListOfAvailableSteps initializes all the SpecInfoGatherer caches46func (s *SpecInfoGatherer) MakeListOfAvailableSteps() {47	go s.watchForFileChanges()48	s.waitGroup.Wait()49	// Concepts parsed first because we need to create a concept dictionary that spec parsing can use50	s.waitGroup.Add(3)51	s.initConceptsCache()52	s.initSpecsCache()53	s.initStepsCache()54}55func (s *SpecInfoGatherer) initSpecsCache() {56	defer s.waitGroup.Done()57	s.specsCache = make(map[string]*SpecDetail, 0)58	details := s.getParsedSpecs(getSpecFiles(s.SpecDirs))59	logger.APILog.Info("Initializing specs cache with %d specs", len(details))60	for _, d := range details {61		logger.APILog.Debug("Adding specs from %s", d.Spec.FileName)62		s.addToSpecsCache(d.Spec.FileName, d)63	}64}65func getSpecFiles(specs []string) []string {66	var specFiles []string67	for _, dir := range specs {68		specFiles = append(specFiles, util.FindSpecFilesIn(dir)...)69	}70	return specFiles71}72func (s *SpecInfoGatherer) initConceptsCache() {73	defer s.waitGroup.Done()74	s.conceptsCache = make(map[string][]*gauge.Concept, 0)75	parsedConcepts := s.getParsedConcepts()76	logger.APILog.Info("Initializing concepts cache with %d concepts", len(parsedConcepts))77	for _, concept := range parsedConcepts {78		logger.APILog.Debug("Adding concepts from %s", concept.FileName)79		s.addToConceptsCache(concept.FileName, concept)80	}81}82func (s *SpecInfoGatherer) initStepsCache() {83	defer s.waitGroup.Done()84	s.stepsCache = make(map[string]*gauge.StepValue, 0)85	stepsFromSpecs := s.getStepsFromCachedSpecs()86	stepsFromConcepts := s.getStepsFromCachedConcepts()87	allSteps := append(stepsFromSpecs, stepsFromConcepts...)88	logger.APILog.Info("Initializing steps cache with %d steps", len(allSteps))89	s.addToStepsCache(allSteps)90}91func (s *SpecInfoGatherer) addToSpecsCache(key string, value *SpecDetail) {92	s.mutex.Lock()93	s.specsCache[key] = value94	s.mutex.Unlock()95}96func (s *SpecInfoGatherer) addToConceptsCache(key string, value *gauge.Concept) {97	s.mutex.Lock()98	if s.conceptsCache[key] == nil {99		s.conceptsCache[key] = make([]*gauge.Concept, 0)100	}101	s.conceptsCache[key] = append(s.conceptsCache[key], value)102	s.mutex.Unlock()103}104func (s *SpecInfoGatherer) addToStepsCache(allSteps []*gauge.StepValue) {105	s.mutex.Lock()106	for _, step := range allSteps {107		if _, ok := s.stepsCache[step.StepValue]; !ok {108			s.stepsCache[step.StepValue] = step109		}110	}111	s.mutex.Unlock()112}113func (s *SpecInfoGatherer) getParsedSpecs(specFiles []string) []*SpecDetail {114	if s.conceptDictionary == nil {115		s.conceptDictionary = gauge.NewConceptDictionary()116	}117	parsedSpecs, parseResults := parser.ParseSpecFiles(specFiles, s.conceptDictionary, gauge.NewBuildErrors())118	specs := make(map[string]*SpecDetail)119	for _, spec := range parsedSpecs {120		specs[spec.FileName] = &SpecDetail{Spec: spec}121	}122	for _, v := range parseResults {123		_, ok := specs[v.FileName]124		if !ok {125			specs[v.FileName] = &SpecDetail{Spec: &gauge.Specification{FileName: v.FileName}}126		}127		specs[v.FileName].Errs = append(v.CriticalErrors, v.ParseErrors...)128	}129	details := make([]*SpecDetail, 0)130	for _, d := range specs {131		details = append(details, d)132	}133	return details134}135func (s *SpecInfoGatherer) getParsedConcepts() map[string]*gauge.Concept {136	var result *parser.ParseResult137	s.conceptDictionary, result = parser.CreateConceptsDictionary()138	handleParseFailures([]*parser.ParseResult{result})139	return s.conceptDictionary.ConceptsMap140}141func (s *SpecInfoGatherer) getStepsFromCachedSpecs() []*gauge.StepValue {142	var stepValues []*gauge.StepValue143	s.mutex.Lock()144	for _, detail := range s.specsCache {145		stepValues = append(stepValues, getStepsFromSpec(detail.Spec)...)146	}147	s.mutex.Unlock()148	return stepValues149}150func (s *SpecInfoGatherer) getStepsFromCachedConcepts() []*gauge.StepValue {151	var stepValues []*gauge.StepValue152	s.mutex.Lock()153	for _, conceptList := range s.conceptsCache {154		for _, concept := range conceptList {155			stepValues = append(stepValues, getStepsFromConcept(concept)...)156		}157	}158	s.mutex.Unlock()159	return stepValues160}161func (s *SpecInfoGatherer) onSpecFileModify(file string) {162	s.waitGroup.Add(1)163	defer s.waitGroup.Done()164	logger.APILog.Info("Spec file added / modified: %s", file)165	details := s.getParsedSpecs([]string{file})166	s.addToSpecsCache(file, details[0])167	stepsFromSpec := getStepsFromSpec(details[0].Spec)168	s.addToStepsCache(stepsFromSpec)169}170func (s *SpecInfoGatherer) onConceptFileModify(file string) {171	s.waitGroup.Add(1)172	defer s.waitGroup.Done()173	logger.APILog.Info("Concept file added / modified: %s", file)174	conceptParser := new(parser.ConceptParser)175	concepts, parseResults := conceptParser.ParseFile(file)176	if parseResults != nil && len(parseResults.ParseErrors) > 0 {177		for _, err := range parseResults.ParseErrors {178			logger.APILog.Error("Error parsing concepts: ", err)179		}180		return181	}182	for _, concept := range concepts {183		c := gauge.Concept{ConceptStep: concept, FileName: file}184		s.addToConceptsCache(file, &c)185		stepsFromConcept := getStepsFromConcept(&c)186		s.addToStepsCache(stepsFromConcept)187	}188}189func (s *SpecInfoGatherer) onSpecFileRemove(file string) {190	s.waitGroup.Add(1)191	defer s.waitGroup.Done()192	logger.APILog.Info("Spec file removed: %s", file)193	s.mutex.Lock()194	delete(s.specsCache, file)195	s.mutex.Unlock()196}197func (s *SpecInfoGatherer) onConceptFileRemove(file string) {198	s.waitGroup.Add(1)199	defer s.waitGroup.Done()200	logger.APILog.Info("Concept file removed: %s", file)201	s.mutex.Lock()202	delete(s.conceptsCache, file)203	s.mutex.Unlock()204}205func (s *SpecInfoGatherer) onFileAdd(watcher *fsnotify.Watcher, file string) {206	if util.IsDir(file) {207		addDirToFileWatcher(watcher, file)208	}209	s.onFileModify(watcher, file)210}211func (s *SpecInfoGatherer) onFileModify(watcher *fsnotify.Watcher, file string) {212	if util.IsSpec(file) {213		s.onSpecFileModify(file)214	} else if util.IsConcept(file) {215		s.onConceptFileModify(file)216	}217}218func (s *SpecInfoGatherer) onFileRemove(watcher *fsnotify.Watcher, file string) {219	if util.IsSpec(file) {220		s.onSpecFileRemove(file)221	} else if util.IsConcept(file) {222		s.onConceptFileRemove(file)223	} else {224		removeWatcherOn(watcher, file)225	}226}227func (s *SpecInfoGatherer) onFileRename(watcher *fsnotify.Watcher, file string) {228	s.onFileRemove(watcher, file)229}230func (s *SpecInfoGatherer) handleEvent(event fsnotify.Event, watcher *fsnotify.Watcher) {231	s.waitGroup.Wait()232	file, err := filepath.Abs(event.Name)233	if err != nil {234		logger.APILog.Error("Failed to get abs file path for %s: %s", event.Name, err)235		return236	}237	if util.IsSpec(file) || util.IsConcept(file) || util.IsDir(file) {238		switch event.Op {239		case fsnotify.Create:240			s.onFileAdd(watcher, file)241		case fsnotify.Write:242			s.onFileModify(watcher, file)243		case fsnotify.Rename:244			s.onFileRename(watcher, file)245		case fsnotify.Remove:246			s.onFileRemove(watcher, file)247		}248	}249}250func (s *SpecInfoGatherer) watchForFileChanges() {251	s.waitGroup.Add(1)252	watcher, err := fsnotify.NewWatcher()253	if err != nil {254		logger.APILog.Error("Error creating fileWatcher: %s", err)255	}256	defer watcher.Close()257	done := make(chan bool)258	go func() {259		for {260			select {261			case event := <-watcher.Events:262				s.handleEvent(event, watcher)263			case err := <-watcher.Errors:264				logger.APILog.Error("Error event while watching specs", err)265			}266		}267	}()268	var allDirsToWatch []string269	var specDir string270	for _, dir := range s.SpecDirs {271		specDir = filepath.Join(config.ProjectRoot, dir)272		allDirsToWatch = append(allDirsToWatch, specDir)273		allDirsToWatch = append(allDirsToWatch, util.FindAllNestedDirs(specDir)...)274	}275	for _, dir := range allDirsToWatch {276		addDirToFileWatcher(watcher, dir)277	}278	s.waitGroup.Done()279	<-done280}281// GetAvailableSpecs returns the list of all the specs in the gauge project282func (s *SpecInfoGatherer) GetAvailableSpecDetails(specs []string) []*SpecDetail {283	if len(specs) < 1 {284		specs = []string{common.SpecsDirectoryName}285	}286	specFiles := getSpecFiles(specs)287	s.waitGroup.Wait()288	var details []*SpecDetail289	s.mutex.Lock()290	for _, f := range specFiles {291		if d, ok := s.specsCache[f]; ok {292			details = append(details, d)293		}294	}295	s.mutex.Unlock()296	return details297}298// GetAvailableSteps returns the list of all the steps in the gauge project299func (s *SpecInfoGatherer) GetAvailableSteps() []*gauge.StepValue {300	s.waitGroup.Wait()301	var steps []*gauge.StepValue302	s.mutex.Lock()303	for _, stepValue := range s.stepsCache {304		steps = append(steps, stepValue)305	}306	s.mutex.Unlock()307	return steps308}309// GetConceptInfos returns an array containing information about all the concepts present in the Gauge project310func (s *SpecInfoGatherer) GetConceptInfos() []*gauge_messages.ConceptInfo {311	s.waitGroup.Wait()312	var conceptInfos []*gauge_messages.ConceptInfo313	s.mutex.Lock()314	for _, conceptList := range s.conceptsCache {315		for _, concept := range conceptList {316			stepValue := parser.CreateStepValue(concept.ConceptStep)317			conceptInfos = append(conceptInfos, &gauge_messages.ConceptInfo{StepValue: gauge.ConvertToProtoStepValue(&stepValue), Filepath: concept.FileName, LineNumber: int32(concept.ConceptStep.LineNo)})318		}319	}320	s.mutex.Unlock()321	return conceptInfos322}323func getStepsFromSpec(spec *gauge.Specification) []*gauge.StepValue {324	stepValues := getParsedStepValues(spec.Contexts)325	for _, scenario := range spec.Scenarios {326		stepValues = append(stepValues, getParsedStepValues(scenario.Steps)...)327	}328	return stepValues329}330func getStepsFromConcept(concept *gauge.Concept) []*gauge.StepValue {331	return getParsedStepValues(concept.ConceptStep.ConceptSteps)332}333func getParsedStepValues(steps []*gauge.Step) []*gauge.StepValue {334	var stepValues []*gauge.StepValue335	for _, step := range steps {336		if !step.IsConcept {337			stepValue := parser.CreateStepValue(step)338			stepValues = append(stepValues, &stepValue)339		}340	}341	return stepValues342}343func handleParseFailures(parseResults []*parser.ParseResult) {344	for _, result := range parseResults {345		if !result.Ok {346			logger.APILog.Error("Spec Parse failure: %s", result.Errors())347			if len(result.CriticalErrors) > 0 {348				os.Exit(1)349			}350		}351	}352}353func addDirToFileWatcher(watcher *fsnotify.Watcher, dir string) {354	err := watcher.Add(dir)355	if err != nil {356		logger.APILog.Error("Unable to add directory %v to file watcher: %s", dir, err)357	} else {358		logger.APILog.Info("Watching directory: %s", dir)359		files, _ := ioutil.ReadDir(dir)360		logger.APILog.Debug("Found %d files", len(files))361	}362}363func removeWatcherOn(watcher *fsnotify.Watcher, path string) {364	logger.APILog.Info("Removing watcher on : %s", path)365	watcher.Remove(path)366}...

Full Screen

Full Screen

server.go

Source:server.go Github

copy

Full Screen

...25)26type infoProvider interface {27	Init()28	Steps(filterConcepts bool) []*gauge.Step29	AllSteps(filterConcepts bool) []*gauge.Step30	Concepts() []*gm.ConceptInfo31	Params(file string, argType gauge.ArgType) []gauge.StepArg32	Tags() []string33	SearchConceptDictionary(string) *gauge.Concept34	GetAvailableSpecDetails(specs []string) []*infoGatherer.SpecDetail35	GetSpecDirs() []string36}37var provider infoProvider38type lspHandler struct {39	jsonrpc2.Handler40}41type LangHandler struct {42}43type InitializeParams struct {...

Full Screen

Full Screen

AllSteps

Using AI Code Generation

copy

Full Screen

1type Step struct {2}3func (g *infoGatherer) AllSteps() []*Step4type Step struct {5}6func (g *infoGatherer) AllSteps() []*Step7type Step struct {8}9func (g *infoGatherer) AllSteps() []*Step10type Step struct {11}

Full Screen

Full Screen

AllSteps

Using AI Code Generation

copy

Full Screen

1import (2func main() {3	const (4	opts := []selenium.ServiceOption{5	}6	selenium.SetDebug(false)7	service, err := selenium.NewSeleniumService(seleniumPath, port, opts...)8	if err != nil {9	}10	defer service.Stop()11	caps := selenium.Capabilities{"browserName": "firefox"}12	if err != nil {13		panic(err)14	}15	defer wd.Quit()16		panic(err)17	}18	elem, err := wd.FindElement(selenium.ByCSSSelector, "#code")19	if err != nil {20		panic(err)21	}22	if err := elem.Clear(); err != nil {23		panic(err)24	}25	if err := elem.SendKeys(`package main26import "fmt"27func main() {28	fmt.Println("Hello WebDriver!")29}`); err != nil {30		panic(err)31	}32	btn, err := wd.FindElement(selenium.ByCSSSelector, "#run")33	if err != nil {34		panic(err)35	}36	if err := btn.Click(); err != nil {37		panic(err)38	}

Full Screen

Full Screen

AllSteps

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3    infoGatherer = InfoGatherer{}4    infoGatherer.AllSteps()5}6import "fmt"7func main() {8    infoGatherer = InfoGatherer{}9    infoGatherer.AllSteps()10}11import "fmt"12func main() {13    infoGatherer = InfoGatherer{}14    infoGatherer.AllSteps()15}16import "fmt"17func main() {18    infoGatherer = InfoGatherer{}19    infoGatherer.AllSteps()20}21import "fmt"22func main() {23    infoGatherer = InfoGatherer{}24    infoGatherer.AllSteps()25}26import "fmt"27func main() {28    infoGatherer = InfoGatherer{}29    infoGatherer.AllSteps()30}31import "fmt"32func main() {33    infoGatherer = InfoGatherer{}34    infoGatherer.AllSteps()35}36import "fmt"37func main() {38    infoGatherer = InfoGatherer{}39    infoGatherer.AllSteps()40}

Full Screen

Full Screen

AllSteps

Using AI Code Generation

copy

Full Screen

1import (2func main() {3	image1Info, err := utils.GetImageInfo(image1)4	if err != nil {5		fmt.Printf("Error getting image1: %s6	}7	image2Info, err := utils.GetImageInfo(image2)8	if err != nil {9		fmt.Printf("Error getting image2: %s10	}11	diffs, err := differs.AllSteps(image1Info, image2Info)12	if err != nil {13		fmt.Printf("Error getting diffs: %s14	}15	for _, diff := range diffs {16		fmt.Printf("Diff Type: %s17		fmt.Printf("Diff:18	}19}20import (21func main() {22	image1Info, err := utils.GetImageInfo(image1)23	if err != nil {24		fmt.Printf("Error getting image1: %s25	}26	image2Info, err := utils.GetImageInfo(image2)27	if err != nil {28		fmt.Printf("Error getting image2: %s29	}

Full Screen

Full Screen

AllSteps

Using AI Code Generation

copy

Full Screen

1import (2func main() {3	dir, err := os.Getwd()4	if err != nil {5		log.Fatal(err)6	}7	info := NewInfoGatherer()8	steps := info.AllSteps(dir)9	fmt.Println("List of steps:")10	for _, step := range steps {11		fmt.Println(step)12	}13}14import (15func main() {16	dir, err := os.Getwd()17	if err != nil {18		log.Fatal(err)19	}20	info := NewInfoGatherer()21	stepInfo := info.GetStepInfo(dir, "step1")22	fmt.Println("Step info:")23	fmt.Println(stepInfo)24}25import (26func main() {27	dir, err := os.Getwd()28	if err != nil {29		log.Fatal(err)30	}31	info := NewInfoGatherer()32	stepInfo := info.GetStepInfo(dir, "step1")33	fmt.Println("Step info:")34	fmt.Println(stepInfo)35}36import (37func main() {38	dir, err := os.Getwd()39	if err != nil {40		log.Fatal(err)41	}42	info := NewInfoGatherer()

Full Screen

Full Screen

AllSteps

Using AI Code Generation

copy

Full Screen

1import (2func main() {3	info := imagetest.InfoGatherer{}4	info.AllSteps()5	fmt.Println(info)6}7import (8func main() {9	info := imagetest.InfoGatherer{}10	info.AllSteps()11	fmt.Println(info)12}13import (14func main() {15	info := imagetest.InfoGatherer{}16	info.AllSteps()17	fmt.Println(info)18}19import (20func main() {21	info := imagetest.InfoGatherer{}22	info.AllSteps()23	fmt.Println(info)24}25import (26func main() {27	info := imagetest.InfoGatherer{}28	info.AllSteps()29	fmt.Println(info)30}31import (32func main() {33	info := imagetest.InfoGatherer{}34	info.AllSteps()35	fmt.Println(info)36}37import (38func main() {39	info := imagetest.InfoGatherer{}40	info.AllSteps()41	fmt.Println(info)42}43import (

Full Screen

Full Screen

AllSteps

Using AI Code Generation

copy

Full Screen

1func main() {2  ig := infoGatherer{}3  fmt.Println(ig.AllSteps())4}5import "fmt"6func main() {7  ig := infoGatherer{}8  fmt.Println(ig.AllSteps())9}10import "fmt"11func main() {12  ig := infoGatherer{}13  fmt.Println(ig.AllSteps())14}15import "fmt"16func main() {17  ig := infoGatherer{}18  fmt.Println(ig.AllSteps())19}20import "fmt"21func main() {22  ig := infoGatherer{}23  fmt.Println(ig.AllSteps())24}25import "fmt"26func main() {27  ig := infoGatherer{}28  fmt.Println(ig.AllSteps())29}30import "fmt"31func main() {32  ig := infoGatherer{}33  fmt.Println(ig.AllSteps())34}35import "fmt"

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Gauge automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful