mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-26 01:51:29 +08:00
feat: add initialization of nil fields in summary data to prevent template execution errors
This commit is contained in:
@@ -1 +1 @@
|
||||
v5.0.0-beta-2506191048
|
||||
v5.0.0-beta-2506191446
|
||||
|
||||
35
report.go
35
report.go
@@ -14,6 +14,7 @@ import (
|
||||
|
||||
"github.com/httprunner/httprunner/v5/internal/builtin"
|
||||
"github.com/httprunner/httprunner/v5/uixt"
|
||||
"github.com/httprunner/httprunner/v5/uixt/option"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
@@ -88,6 +89,9 @@ func (g *HTMLReportGenerator) loadSummaryData() error {
|
||||
return err
|
||||
}
|
||||
|
||||
// Initialize nil fields to prevent template execution errors
|
||||
g.initializeSummaryFields()
|
||||
|
||||
// Re-encode the summary data to ensure proper UTF-8 encoding for download
|
||||
// This fixes Chinese character encoding issues in legacy summary.json files
|
||||
buffer := new(strings.Builder)
|
||||
@@ -108,6 +112,37 @@ func (g *HTMLReportGenerator) loadSummaryData() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// initializeSummaryFields initializes nil fields in SummaryData to prevent template execution errors
|
||||
func (g *HTMLReportGenerator) initializeSummaryFields() {
|
||||
if g.SummaryData == nil {
|
||||
g.SummaryData = &Summary{}
|
||||
}
|
||||
|
||||
// Initialize Stat if nil
|
||||
if g.SummaryData.Stat == nil {
|
||||
g.SummaryData.Stat = &Stat{}
|
||||
// Initialize TestSteps.Actions map if needed
|
||||
if g.SummaryData.Stat.TestSteps.Actions == nil {
|
||||
g.SummaryData.Stat.TestSteps.Actions = make(map[option.ActionName]int)
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize Platform if nil
|
||||
if g.SummaryData.Platform == nil {
|
||||
g.SummaryData.Platform = &Platform{}
|
||||
}
|
||||
|
||||
// Initialize Time if nil
|
||||
if g.SummaryData.Time == nil {
|
||||
g.SummaryData.Time = &TestCaseTime{}
|
||||
}
|
||||
|
||||
// Initialize Details if nil
|
||||
if g.SummaryData.Details == nil {
|
||||
g.SummaryData.Details = []*TestCaseSummary{}
|
||||
}
|
||||
}
|
||||
|
||||
// loadLogData loads test log data from log file
|
||||
func (g *HTMLReportGenerator) loadLogData() error {
|
||||
if g.LogFile == "" || !builtin.FileExists(g.LogFile) {
|
||||
|
||||
@@ -49,10 +49,9 @@ type UIXTConfig struct {
|
||||
WDAPort int
|
||||
WDAMjpegPort int
|
||||
|
||||
OSType string // platform
|
||||
Serial string
|
||||
PackageName string
|
||||
LLMService option.LLMServiceType // LLM 服务类型
|
||||
OSType string // platform
|
||||
Serial string
|
||||
LLMService option.LLMServiceType // LLM 服务类型
|
||||
}
|
||||
|
||||
const (
|
||||
|
||||
@@ -384,6 +384,9 @@ func (dev *AndroidDevice) getPackageVersion(packageName string) (string, error)
|
||||
}
|
||||
|
||||
func (dev *AndroidDevice) getPackagePath(packageName string) (string, error) {
|
||||
if packageName == "" {
|
||||
return "", errors.Wrap(code.InvalidParamError, "packageName is empty")
|
||||
}
|
||||
output, err := dev.Device.RunShellCommand("pm", "path", packageName)
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "get package path failed")
|
||||
|
||||
Reference in New Issue
Block a user