How to use newSpecBuilder method of execution Package

Best Gauge code snippet using execution.newSpecBuilder

specExecutor_test.go

Source:specExecutor_test.go Github

copy

Full Screen

...26)27type specBuilder struct {28 lines []string29}30func newSpecBuilder() *specBuilder {31 return &specBuilder{lines: make([]string, 0)}32}33func (specBuilder *specBuilder) addPrefix(prefix string, line string) string {34 return fmt.Sprintf("%s%s\n", prefix, line)35}36func (specBuilder *specBuilder) String() string {37 var result string38 for _, line := range specBuilder.lines {39 result = fmt.Sprintf("%s%s", result, line)40 }41 return result42}43func (specBuilder *specBuilder) specHeading(heading string) *specBuilder {44 line := specBuilder.addPrefix("#", heading)45 specBuilder.lines = append(specBuilder.lines, line)46 return specBuilder47}48func (specBuilder *specBuilder) scenarioHeading(heading string) *specBuilder {49 line := specBuilder.addPrefix("##", heading)50 specBuilder.lines = append(specBuilder.lines, line)51 return specBuilder52}53func (specBuilder *specBuilder) step(stepText string) *specBuilder {54 line := specBuilder.addPrefix("* ", stepText)55 specBuilder.lines = append(specBuilder.lines, line)56 return specBuilder57}58func (specBuilder *specBuilder) tags(tags ...string) *specBuilder {59 tagText := ""60 for i, tag := range tags {61 tagText = fmt.Sprintf("%s%s", tagText, tag)62 if i != len(tags)-1 {63 tagText = fmt.Sprintf("%s,", tagText)64 }65 }66 line := specBuilder.addPrefix("tags: ", tagText)67 specBuilder.lines = append(specBuilder.lines, line)68 return specBuilder69}70func (specBuilder *specBuilder) tableHeader(cells ...string) *specBuilder {71 return specBuilder.tableRow(cells...)72}73func (specBuilder *specBuilder) tableRow(cells ...string) *specBuilder {74 rowInMarkdown := "|"75 for _, cell := range cells {76 rowInMarkdown = fmt.Sprintf("%s%s|", rowInMarkdown, cell)77 }78 specBuilder.lines = append(specBuilder.lines, fmt.Sprintf("%s\n", rowInMarkdown))79 return specBuilder80}81func (specBuilder *specBuilder) text(comment string) *specBuilder {82 specBuilder.lines = append(specBuilder.lines, fmt.Sprintf("%s\n", comment))83 return specBuilder84}85type tableRow struct {86 name string87 input string // input by user for data table rows88 output []int // data table indexes to be executed89}90var tableRowTests = []*tableRow{91 {"Valid single row number", "2", []int{1}},92 {"Valid row numbers list", "2,3,4", []int{1, 2, 3}},93 {"Valid table rows range", "2-5", []int{1, 2, 3, 4}},94 {"Empty table rows range", "", []int(nil)},95 {"Table rows list with spaces", "2, 4 ", []int{1, 3}},96}97func (s *MySuite) TestToGetDataTableRowsRangeFromInputFlag(c *C) {98 for _, test := range tableRowTests {99 got := getDataTableRows(test.input)100 want := test.output101 c.Assert(got, DeepEquals, want, Commentf(test.name))102 }103}104func (s *MySuite) TestCreateSkippedSpecResult(c *C) {105 spec := &gauge.Specification{Heading: &gauge.Heading{LineNo: 0, Value: "SPEC_HEADING"}, FileName: "FILE"}106 se := newSpecExecutor(spec, nil, nil, nil, 0)107 se.errMap = getValidationErrorMap()108 se.specResult = &result.SpecResult{}109 se.skipSpecForError(fmt.Errorf("ERROR"))110 c.Assert(se.specResult.IsFailed, Equals, false)111 c.Assert(se.specResult.Skipped, Equals, true)112 c.Assert(len(se.errMap.SpecErrs[spec]), Equals, 1)113}114func (s *MySuite) TestCreateSkippedSpecResultWithScenarios(c *C) {115 se := newSpecExecutor(anySpec(), nil, nil, nil, 0)116 se.errMap = getValidationErrorMap()117 se.specResult = &result.SpecResult{ProtoSpec: &gauge_messages.ProtoSpec{}}118 se.skipSpecForError(fmt.Errorf("ERROR"))119 c.Assert(len(se.errMap.ScenarioErrs[se.specification.Scenarios[0]]), Equals, 1)120 c.Assert(len(se.errMap.SpecErrs[se.specification]), Equals, 1)121}122func anySpec() *gauge.Specification {123 specText := newSpecBuilder().specHeading("A spec heading").124 scenarioHeading("First scenario").125 step("create user \"456\" \"foo\" and \"9900\"").126 String()127 spec, _, _ := new(parser.SpecParser).Parse(specText, gauge.NewConceptDictionary(), "")128 spec.FileName = "FILE"129 return spec130}131func (s *MySuite) TestSpecIsSkippedIfDataRangeIsInvalid(c *C) {132 errMap := &gauge.BuildErrors{133 SpecErrs: make(map[*gauge.Specification][]error),134 ScenarioErrs: make(map[*gauge.Scenario][]error),135 StepErrs: make(map[*gauge.Step]error),136 }137 spec := anySpec()138 errMap.SpecErrs[spec] = []error{validation.NewSpecValidationError("Table row number out of range", spec.FileName)}139 se := newSpecExecutor(spec, nil, nil, errMap, 0)140 specResult := se.execute(true, false, false)141 c.Assert(specResult.Skipped, Equals, true)142}143func (s *MySuite) TestDataTableRowsAreSkippedForUnimplemetedStep(c *C) {144 MaxRetriesCount = 1145 stepText := "Unimplememted step"146 specText := newSpecBuilder().specHeading("A spec heading").147 tableHeader("id", "name", "phone").148 tableRow("123", "foo", "8800").149 tableRow("666", "bar", "9900").150 scenarioHeading("First scenario").151 step(stepText).152 step("create user <id> <name> and <phone>").153 String()154 spec, _, _ := new(parser.SpecParser).Parse(specText, gauge.NewConceptDictionary(), "")155 errMap := &gauge.BuildErrors{156 SpecErrs: make(map[*gauge.Specification][]error),157 ScenarioErrs: make(map[*gauge.Scenario][]error),158 StepErrs: make(map[*gauge.Step]error),159 }160 errMap.SpecErrs[spec] = []error{validation.NewSpecValidationError("Step implementation not found", spec.FileName)}...

Full Screen

Full Screen

resolve_test.go

Source:resolve_test.go Github

copy

Full Screen

...13 . "gopkg.in/check.v1"14)15func (s *MySuite) TestResolveConceptToProtoConceptItem(c *C) {16 conceptDictionary := gauge.NewConceptDictionary()17 specText := newSpecBuilder().specHeading("A spec heading").18 scenarioHeading("First scenario").19 step("create user \"456\" \"foo\" and \"9900\"").20 String()21 path, _ := filepath.Abs(filepath.Join("testdata", "concept.cpt"))22 _, _, err := parser.AddConcepts([]string{path}, conceptDictionary)23 if err != nil {24 c.Error(err)25 }26 spec, _, err := new(parser.SpecParser).Parse(specText, conceptDictionary, "")27 if err != nil {28 c.Error(err)29 }30 specExecutor := newSpecExecutor(spec, nil, nil, nil, 0)31 specExecutor.errMap = getValidationErrorMap()32 lookup, err := specExecutor.dataTableLookup()33 c.Assert(err, IsNil)34 cItem, err := resolveToProtoConceptItem(*spec.Scenarios[0].Steps[0], lookup, specExecutor.setSkipInfo)35 c.Assert(err, IsNil)36 protoConcept := cItem.GetConcept()37 checkConceptParameterValuesInOrder(c, protoConcept, "456", "foo", "9900")38 firstNestedStep := protoConcept.GetSteps()[0].GetConcept().GetSteps()[0].GetStep()39 params := getParameters(firstNestedStep.GetFragments())40 c.Assert(1, Equals, len(params))41 c.Assert(params[0].GetParameterType(), Equals, gauge_messages.Parameter_Dynamic)42 c.Assert(params[0].GetValue(), Equals, "456")43 secondNestedStep := protoConcept.GetSteps()[0].GetConcept().GetSteps()[1].GetStep()44 params = getParameters(secondNestedStep.GetFragments())45 c.Assert(1, Equals, len(params))46 c.Assert(params[0].GetParameterType(), Equals, gauge_messages.Parameter_Dynamic)47 c.Assert(params[0].GetValue(), Equals, "foo")48 secondStep := protoConcept.GetSteps()[1].GetStep()49 params = getParameters(secondStep.GetFragments())50 c.Assert(1, Equals, len(params))51 c.Assert(params[0].GetParameterType(), Equals, gauge_messages.Parameter_Dynamic)52 c.Assert(params[0].GetValue(), Equals, "9900")53}54func (s *MySuite) TestResolveNestedConceptToProtoConceptItem(c *C) {55 conceptDictionary := gauge.NewConceptDictionary()56 specText := newSpecBuilder().specHeading("A spec heading").57 scenarioHeading("First scenario").58 step("create user \"456\" \"foo\" and \"9900\"").59 String()60 path, _ := filepath.Abs(filepath.Join("testdata", "concept.cpt"))61 _, _, err := parser.AddConcepts([]string{path}, conceptDictionary)62 if err != nil {63 c.Error(err)64 }65 specParser := new(parser.SpecParser)66 spec, _, _ := specParser.Parse(specText, conceptDictionary, "")67 specExecutor := newSpecExecutor(spec, nil, nil, nil, 0)68 specExecutor.errMap = getValidationErrorMap()69 lookup, err := specExecutor.dataTableLookup()70 c.Assert(err, IsNil)71 cItem, err := resolveToProtoConceptItem(*spec.Scenarios[0].Steps[0], lookup, specExecutor.setSkipInfo)72 c.Assert(err, IsNil)73 protoConcept := cItem.GetConcept()74 checkConceptParameterValuesInOrder(c, protoConcept, "456", "foo", "9900")75 c.Assert(protoConcept.GetSteps()[0].GetItemType(), Equals, gauge_messages.ProtoItem_Concept)76 nestedConcept := protoConcept.GetSteps()[0].GetConcept()77 checkConceptParameterValuesInOrder(c, nestedConcept, "456", "foo")78 firstNestedStep := nestedConcept.GetSteps()[0].GetStep()79 params := getParameters(firstNestedStep.GetFragments())80 c.Assert(1, Equals, len(params))81 c.Assert(params[0].GetParameterType(), Equals, gauge_messages.Parameter_Dynamic)82 c.Assert(params[0].GetValue(), Equals, "456")83 secondNestedStep := nestedConcept.GetSteps()[1].GetStep()84 params = getParameters(secondNestedStep.GetFragments())85 c.Assert(1, Equals, len(params))86 c.Assert(params[0].GetParameterType(), Equals, gauge_messages.Parameter_Dynamic)87 c.Assert(params[0].GetValue(), Equals, "foo")88 c.Assert(protoConcept.GetSteps()[1].GetItemType(), Equals, gauge_messages.ProtoItem_Step)89 secondStepInConcept := protoConcept.GetSteps()[1].GetStep()90 params = getParameters(secondStepInConcept.GetFragments())91 c.Assert(1, Equals, len(params))92 c.Assert(params[0].GetParameterType(), Equals, gauge_messages.Parameter_Dynamic)93 c.Assert(params[0].GetValue(), Equals, "9900")94}95func TestResolveNestedConceptAndTableParamToProtoConceptItem(t *testing.T) {96 conceptDictionary := gauge.NewConceptDictionary()97 specText := newSpecBuilder().specHeading("A spec heading").98 scenarioHeading("First scenario").99 step("create user \"456\"").100 String()101 want := "456"102 path, _ := filepath.Abs(filepath.Join("testdata", "conceptTable.cpt"))103 _, _, err := parser.AddConcepts([]string{path}, conceptDictionary)104 if err != nil {105 t.Error(err)106 }107 specParser := new(parser.SpecParser)108 spec, _, _ := specParser.Parse(specText, conceptDictionary, "")109 specExecutor := newSpecExecutor(spec, nil, nil, nil, 0)110 specExecutor.errMap = getValidationErrorMap()111 lookup, err := specExecutor.dataTableLookup()112 if err != nil {113 t.Errorf("Expected no error. Got : %s", err.Error())114 }115 cItem, err := resolveToProtoConceptItem(*spec.Scenarios[0].Steps[0], lookup, specExecutor.setSkipInfo)116 if err != nil {117 t.Errorf("Expected no error. Got : %s", err.Error())118 }119 protoConcept := cItem.GetConcept()120 got := getParameters(protoConcept.GetSteps()[0].GetStep().GetFragments())[0].GetTable().GetRows()[1].Cells[0]121 if want != got {122 t.Errorf("Did not resolve dynamic param in table for concept. Got %s, want: %s", got, want)123 }124}125func (s *MySuite) TestResolveToProtoConceptItemWithDataTable(c *C) {126 conceptDictionary := gauge.NewConceptDictionary()127 specText := newSpecBuilder().specHeading("A spec heading").128 tableHeader("id", "name", "phone").129 tableHeader("123", "foo", "8800").130 tableHeader("666", "bar", "9900").131 scenarioHeading("First scenario").132 step("create user <id> <name> and <phone>").133 String()134 path, _ := filepath.Abs(filepath.Join("testdata", "concept.cpt"))135 _, _, err := parser.AddConcepts([]string{path}, conceptDictionary)136 if err != nil {137 c.Error(err)138 }139 specParser := new(parser.SpecParser)140 spec, _, _ := specParser.Parse(specText, conceptDictionary, "")141 specExecutor := newSpecExecutor(spec, nil, nil, nil, 0)...

Full Screen

Full Screen

newSpecBuilder

Using AI Code Generation

copy

Full Screen

1import (2func main() {3}4import (5func main() {6}7import (8func main() {9}10import (11func main() {12}13import (14func main() {15}16import (17func main() {18}19import (20func main() {21}22import (23func main() {24}25import (26func main() {

Full Screen

Full Screen

newSpecBuilder

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 gauge.Step("Hello World", func() {4 fmt.Println("Hello World")5 })6}7import (8func main() {9 gauge.Step("Hello World", func() {10 fmt.Println("Hello World")11 })12}13import (14func main() {15 gauge.Step("Hello World", func() {16 fmt.Println("Hello World")17 })18}19import (20func main() {21 gauge.Step("Hello World", func() {22 fmt.Println("Hello World")23 })24}25import (26func main() {27 gauge.Step("Hello World", func() {28 fmt.Println("Hello World")29 })30}31import (32func main() {33 gauge.Step("Hello World", func() {34 fmt.Println("Hello World")35 })36}37import (38func main() {39 gauge.Step("Hello World", func() {40 fmt.Println("Hello World")41 })42}43import (44func main() {45 gauge.Step("Hello World", func() {46 fmt.Println("Hello World")47 })48}

Full Screen

Full Screen

newSpecBuilder

Using AI Code Generation

copy

Full Screen

1import (2type execution struct {3}4func (e *execution) newSpecBuilder() *specBuilder {5 return &specBuilder{e}6}7type specBuilder struct {8}9func (s *specBuilder) build() {10 fmt.Println("build")11}12func main() {

Full Screen

Full Screen

newSpecBuilder

Using AI Code Generation

copy

Full Screen

1func main() {2 WithInputs(3 WithOutput("out", "input"),4 WithTransforms(5 WithOutput("out", "transform"),6 WithOutputs(7 WithInput("in", "transform"),8 Build()9 ctx := execution.NewContext(context.Background())10 err := execution.Execute(ctx, spec)11 if err != nil {12 fmt.Printf("execution error: %s", err)13 }14}

Full Screen

Full Screen

newSpecBuilder

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 specBuilder := gauge.NewSpecBuilder()4 specBuilder.AddStep("A step that prints 'Hello World!' to the console", func() {5 fmt.Println("Hello World!")6 })7 specBuilder.AddScenario("A scenario with a single step", []string{"A step that prints 'Hello World!' to the console"})8 specBuilder.AddScenario("A scenario with a single step", []string{"A step that prints 'Hello World!' to the console"})9 specBuilder.AddScenario("A scenario with a single step", []string{"A step that prints 'Hello World!' to the console"})10 specBuilder.AddScenario("A scenario with a single step", []string{"A step that prints 'Hello World!' to the console"})11 specBuilder.AddScenario("A scenario with a single step", []string{"A step that prints 'Hello World!' to the console"})12 specBuilder.AddScenario("A scenario with a single step", []string{"A step that prints 'Hello World!' to the console"})13 specBuilder.AddScenario("A scenario with a single step", []string{"A step that prints 'Hello World!' to the console"})14 specBuilder.AddScenario("A scenario with a single step", []string{"A step that prints 'Hello World!' to the console"})15 specBuilder.AddScenario("A scenario with a single step", []string{"A step that prints 'Hello World!' to the console"})16 specBuilder.AddScenario("A scenario with a single step", []string{"A step that prints 'Hello World!' to the console"})17 specBuilder.AddScenario("A scenario with a single step", []

Full Screen

Full Screen

newSpecBuilder

Using AI Code Generation

copy

Full Screen

1 Step("This is a sample step", func() {2 }). 3 Step("This is another sample step", func() {4 Step("This is a sample step with args", func(args *struct {5 }) {6 Step("This is a sample step with args and return values", func(args *struct {7 }) (string, error) {8 Step("This is a sample step with args and return values", func(args *struct {9 }) (string, error) {10 Step("This is a sample step with args and return values", func(args *struct {11 }) (string, error) {12 Step("This is a sample step with args and return values", func(args *struct {13 }) (string, error) {14 Step("This is a sample step with args and return values", func(args *struct {15 }) (string, error) {16 Step("This is a sample step with args and return values", func(args *struct {17 }) (string, error) {

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.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful