MCPcopy
hub / github.com/httprunner/httprunner / Start

Method Start

hrp/runner.go:519–621  ·  view source on GitHub ↗

Start runs the test steps in sequential order. givenVars is used for data driven

(givenVars map[string]interface{})

Source from the content-addressed store, hash-verified

517// Start runs the test steps in sequential order.
518// givenVars is used for data driven
519func (r *SessionRunner) Start(givenVars map[string]interface{}) error {
520 // report GA event
521 sdk.SendGA4Event("hrp_session_runner_start", nil)
522
523 config := r.caseRunner.testCase.Config
524 log.Info().Str("testcase", config.Name).Msg("run testcase start")
525
526 // update config variables with given variables
527 r.InitWithParameters(givenVars)
528
529 defer func() {
530 // close session resource after all steps done or fast fail
531 r.releaseResources()
532 }()
533
534 // run step in sequential order
535 for _, step := range r.caseRunner.testCase.TestSteps {
536 select {
537 case <-r.caseRunner.hrpRunner.caseTimeoutTimer.C:
538 log.Warn().Msg("timeout in session runner")
539 return errors.Wrap(code.TimeoutError, "session runner timeout")
540 case <-r.caseRunner.hrpRunner.interruptSignal:
541 log.Warn().Msg("interrupted in session runner")
542 return errors.Wrap(code.InterruptError, "session runner interrupted")
543 default:
544 // TODO: parse step struct
545 // parse step name
546 parsedName, err := r.caseRunner.parser.ParseString(step.Name(), r.sessionVariables)
547 if err != nil {
548 parsedName = step.Name()
549 }
550 stepName := convertString(parsedName)
551 stepType := string(step.Type())
552 log.Info().Str("step", stepName).Str("type", stepType).Msg("run step start")
553 stepStartTime := time.Now()
554
555 // run times of step
556 loopTimes := step.Struct().Loops
557 if loopTimes < 0 {
558 log.Warn().Int("loops", loopTimes).Msg("loop times should be positive, set to 1")
559 loopTimes = 1
560 } else if loopTimes == 0 {
561 loopTimes = 1
562 } else if loopTimes > 1 {
563 log.Info().Int("loops", loopTimes).Msg("run step with specified loop times")
564 }
565
566 // run step with specified loop times
567 var stepResult *StepResult
568 for i := 1; i <= loopTimes; i++ {
569 var loopIndex string
570 if loopTimes > 1 {
571 log.Info().Int("index", i).Msg("start running step in loop")
572 loopIndex = fmt.Sprintf("_loop_%d", i)
573 }
574
575 // run step
576 startTime := time.Now().Unix()

Callers

nothing calls this directly

Calls 11

InitWithParametersMethod · 0.95
releaseResourcesMethod · 0.95
updateSummaryMethod · 0.95
SendGA4EventFunction · 0.92
convertStringFunction · 0.85
ParseStringMethod · 0.80
ErrMethod · 0.80
NameMethod · 0.65
TypeMethod · 0.65
StructMethod · 0.65
RunMethod · 0.65

Tested by

no test coverage detected