feat: add comprehensive HTML report generation with log filtering

- Add complete HTML report generator with template-based rendering
- Implement log time filtering for step-specific logs
- Support responsive design and interactive UI features
- Consolidate duplicate report implementations
This commit is contained in:
lilong.129
2025-06-08 09:23:01 +08:00
parent ec4f1eb68a
commit 4053cc9985
5 changed files with 1283 additions and 26 deletions

View File

@@ -17,6 +17,7 @@ func addAllCommands() {
cmd.RootCmd.AddCommand(cmd.CmdBuild)
cmd.RootCmd.AddCommand(cmd.CmdConvert)
cmd.RootCmd.AddCommand(cmd.CmdPytest)
cmd.RootCmd.AddCommand(cmd.CmdReport)
cmd.RootCmd.AddCommand(cmd.CmdRun)
cmd.RootCmd.AddCommand(cmd.CmdScaffold)
cmd.RootCmd.AddCommand(cmd.CmdServer)

39
cmd/report.go Normal file
View File

@@ -0,0 +1,39 @@
package cmd
import (
"fmt"
"path/filepath"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
hrp "github.com/httprunner/httprunner/v5"
)
var CmdReport = &cobra.Command{
Use: "report [result_folder]",
Short: "Generate HTML report from test results",
Long: `Generate report.html from test results in the specified folder.
The folder should contain summary.json and optionally hrp.log files.
Examples:
$ hrp report results/20250607234602/
$ hrp report /path/to/test/results/`,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
resultFolder := args[0]
// Construct file paths
summaryFile := filepath.Join(resultFolder, "summary.json")
logFile := filepath.Join(resultFolder, "hrp.log")
reportFile := filepath.Join(resultFolder, "report.html")
// Generate HTML report
if err := hrp.GenerateHTMLReportFromFiles(summaryFile, logFile, reportFile); err != nil {
return fmt.Errorf("failed to generate HTML report: %w", err)
}
log.Info().Str("report_file", reportFile).Msg("HTML report generated successfully")
return nil
},
}