Files
httprunner/cmd/report.go
lilong.129 4053cc9985 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
2025-06-08 09:23:14 +08:00

40 lines
1.1 KiB
Go

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
},
}