mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-06 07:57:27 +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
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import (
|
|||||||
|
|
||||||
"github.com/httprunner/httprunner/v5/internal/builtin"
|
"github.com/httprunner/httprunner/v5/internal/builtin"
|
||||||
"github.com/httprunner/httprunner/v5/uixt"
|
"github.com/httprunner/httprunner/v5/uixt"
|
||||||
|
"github.com/httprunner/httprunner/v5/uixt/option"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
)
|
)
|
||||||
@@ -88,6 +89,9 @@ func (g *HTMLReportGenerator) loadSummaryData() error {
|
|||||||
return err
|
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
|
// Re-encode the summary data to ensure proper UTF-8 encoding for download
|
||||||
// This fixes Chinese character encoding issues in legacy summary.json files
|
// This fixes Chinese character encoding issues in legacy summary.json files
|
||||||
buffer := new(strings.Builder)
|
buffer := new(strings.Builder)
|
||||||
@@ -108,6 +112,37 @@ func (g *HTMLReportGenerator) loadSummaryData() error {
|
|||||||
return nil
|
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
|
// loadLogData loads test log data from log file
|
||||||
func (g *HTMLReportGenerator) loadLogData() error {
|
func (g *HTMLReportGenerator) loadLogData() error {
|
||||||
if g.LogFile == "" || !builtin.FileExists(g.LogFile) {
|
if g.LogFile == "" || !builtin.FileExists(g.LogFile) {
|
||||||
|
|||||||
@@ -51,7 +51,6 @@ type UIXTConfig struct {
|
|||||||
|
|
||||||
OSType string // platform
|
OSType string // platform
|
||||||
Serial string
|
Serial string
|
||||||
PackageName string
|
|
||||||
LLMService option.LLMServiceType // LLM 服务类型
|
LLMService option.LLMServiceType // LLM 服务类型
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -384,6 +384,9 @@ func (dev *AndroidDevice) getPackageVersion(packageName string) (string, error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (dev *AndroidDevice) getPackagePath(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)
|
output, err := dev.Device.RunShellCommand("pm", "path", packageName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", errors.Wrap(err, "get package path failed")
|
return "", errors.Wrap(err, "get package path failed")
|
||||||
|
|||||||
Reference in New Issue
Block a user