mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-17 18:37:35 +08:00
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:
@@ -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
39
cmd/report.go
Normal 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
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user