Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var CmdBuild = &cobra.Command{ Use: "build $path ...", Short: "Build plugin for testing", Long: `Build python/go plugin for testing`, Example: ` $ hrp build plugin/debugtalk.go $ hrp build plugin/debugtalk.py`, Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) (err error) { startTime := time.Now() defer func() { sdk.SendGA4Event("hrp_build", map[string]interface{}{ "args": strings.Join(args, "-"), "success": err == nil, "engagement_time_msec": time.Since(startTime).Milliseconds(), }) }() return hrp.BuildPlugin(args[0], output) }, }
View Source
var CmdConvert = &cobra.Command{ Use: "convert $path...", Short: "Convert multiple source format to HttpRunner JSON/YAML/gotest/pytest cases", Args: cobra.MinimumNArgs(1), SilenceUsage: false, RunE: func(cmd *cobra.Command, args []string) error { caseConverter := convert.NewConverter(outputDir, profilePath) var fromType convert.FromType if fromYAMLFlag { fromType = convert.FromTypeYAML } else if fromPostmanFlag { fromType = convert.FromTypePostman } else if fromHARFlag { fromType = convert.FromTypeHAR } else if fromCurlFlag { fromType = convert.FromTypeCurl } else { fromType = convert.FromTypeJSON log.Info().Str("fromType", fromType.String()).Msg("set default") } var outputType convert.OutputType if toYAMLFlag { outputType = convert.OutputTypeYAML } else if toPyTestFlag { packages := []string{"httprunner"} _, err := myexec.EnsurePython3Venv(venv, packages...) if err != nil { log.Error().Err(err).Msg("python3 venv is not ready") return errors.Wrap(code.InvalidPython3Venv, err.Error()) } outputType = convert.OutputTypePyTest } else { outputType = convert.OutputTypeJSON log.Info().Str("outputType", outputType.String()).Msg("set default") } var files []string for _, arg := range args { if builtin.IsFolderPathExists(arg) { fs, err := os.ReadDir(arg) if err != nil { log.Error().Err(err).Str("path", arg).Msg("read dir failed") continue } for _, f := range fs { files = append(files, filepath.Join(arg, f.Name())) } } else { files = append(files, arg) } } for _, file := range files { extName := filepath.Ext(file) if !builtin.Contains(fromType.Extensions(), extName) { log.Warn().Str("path", file). Strs("expectExtensions", fromType.Extensions()). Msg("skip file") continue } if err := caseConverter.Convert(file, fromType, outputType); err != nil { log.Error().Err(err).Str("path", file). Str("outputType", outputType.String()). Msg("convert case failed") } } return nil }, }
View Source
var CmdMCPHost = &cobra.Command{ Use: "mcphost", Short: "Start a chat session to interact with MCP tools", Long: `mcphost is a command-line tool that allows you to interact with MCP tools.`, RunE: func(cmd *cobra.Command, args []string) error { host, err := mcphost.NewMCPHost(mcpConfigPath, withUIXT) if err != nil { return fmt.Errorf("failed to create MCP host: %w", err) } defer host.CloseServers() if dumpPath != "" { return host.ExportToolsToJSON(context.Background(), dumpPath) } chat, err := host.NewChat(context.Background()) if err != nil { return fmt.Errorf("failed to create chat session: %w", err) } return chat.Start(context.Background()) }, }
CmdMCPHost represents the mcphost command
View Source
var CmdMCPServer = &cobra.Command{ Use: "mcp-server", Short: "Start MCP server for UI automation", Long: `Start MCP server for UI automation, expose device driver via MCP protocol`, RunE: func(cmd *cobra.Command, args []string) error { mcpServer := uixt.NewMCPServer() return mcpServer.Start() }, }
View Source
var CmdPytest = &cobra.Command{ Use: "pytest $path ...", Short: "Run API test with pytest", Args: cobra.MinimumNArgs(1), DisableFlagParsing: true, RunE: func(cmd *cobra.Command, args []string) (err error) { startTime := time.Now() defer func() { sdk.SendGA4Event("hrp_pytest", map[string]interface{}{ "args": strings.Join(args, "-"), "success": err == nil, "engagement_time_msec": time.Since(startTime).Milliseconds(), }) }() packages := []string{"httprunner"} _, err = myexec.EnsurePython3Venv(venv, packages...) if err != nil { log.Error().Err(err).Msg("python3 venv is not ready") return errors.Wrap(code.InvalidPython3Venv, err.Error()) } return runPytest(args) }, }
View Source
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] summaryFile := filepath.Join(resultFolder, config.SummaryFileName) logFile := filepath.Join(resultFolder, config.LogFileName) reportFile := filepath.Join(resultFolder, config.ReportFileName) 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 }, }
View Source
var CmdRun = &cobra.Command{ Use: "run $path...", Short: "Run API test with go engine", Long: `Run yaml/json testcase files for API test`, Example: ` $ hrp run demo.json # run specified json testcase file $ hrp run demo.yaml # run specified yaml testcase file $ hrp run examples/ # run testcases in specified folder`, Args: cobra.MinimumNArgs(1), RunE: func(cmd *cobra.Command, args []string) error { var paths []hrp.ITestCase for _, arg := range args { path := hrp.TestCasePath(arg) paths = append(paths, &path) } runner := makeHRPRunner() return runner.Run(paths...) }, }
runCmd represents the run command
View Source
var CmdScaffold = &cobra.Command{ Use: "startproject $project_name", Aliases: []string{"scaffold"}, Short: "Create a scaffold project", Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs), RunE: func(cmd *cobra.Command, args []string) error { if !ignorePlugin && !genPythonPlugin && !genGoPlugin { return errors.New("please specify function plugin type") } var pluginType scaffold.PluginType if empty { pluginType = scaffold.Empty } else if ignorePlugin { pluginType = scaffold.Ignore } else if genGoPlugin { pluginType = scaffold.Go } else { pluginType = scaffold.Py } err := scaffold.CreateScaffold(args[0], pluginType, venv, force) if err != nil { log.Error().Err(err).Msg("create scaffold project failed") return err } log.Info().Str("projectName", args[0]).Msg("create scaffold success") return nil }, }
View Source
var CmdServer = &cobra.Command{ Use: "server start", Short: "Start hrp server", Long: `Start hrp server, call httprunner by HTTP`, Args: cobra.MinimumNArgs(1), RunE: func(cmd *cobra.Command, args []string) error { router := server.NewRouter() mcpConfigPath = os.ExpandEnv(mcpConfigPath) if mcpConfigPath != "" { router.InitMCPHost(mcpConfigPath) } return router.Run(port) }, }
serverCmd represents the server command
View Source
var CmdWiki = &cobra.Command{ Use: "wiki", Aliases: []string{"info", "docs", "doc"}, Short: "visit https://httprunner.com", RunE: func(cmd *cobra.Command, args []string) (err error) { startTime := time.Now() defer func() { sdk.SendGA4Event("hrp_wiki", map[string]interface{}{ "args": strings.Join(args, "-"), "success": err == nil, "engagement_time_msec": time.Since(startTime).Milliseconds(), }) }() return wiki.OpenWiki() }, }
View Source
var RootCmd = &cobra.Command{ Use: "hrp", Short: "All-in-One Testing Framework for API, UI and Performance", Long: ` ██╗ ██╗████████╗████████╗██████╗ ██████╗ ██╗ ██╗███╗ ██╗███╗ ██╗███████╗██████╗ ██║ ██║╚══██╔══╝╚══██╔══╝██╔══██╗██╔══██╗██║ ██║████╗ ██║████╗ ██║██╔════╝██╔══██╗ ███████║ ██║ ██║ ██████╔╝██████╔╝██║ ██║██╔██╗ ██║██╔██╗ ██║█████╗ ██████╔╝ ██╔══██║ ██║ ██║ ██╔═══╝ ██╔══██╗██║ ██║██║╚██╗██║██║╚██╗██║██╔══╝ ██╔══██╗ ██║ ██║ ██║ ██║ ██║ ██║ ██║╚██████╔╝██║ ╚████║██║ ╚████║███████╗██║ ██║ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝╚═╝ ╚═══╝╚══════╝╚═╝ ╚═╝ HttpRunner: Enjoy your All-in-One Testing Solution ✨ 🚀 ✨ 💡 Simple Yet Powerful - Natural language driven test scenarios powered by LLM - User-friendly SDK API with IDE auto-completion - Intuitive GoTest/YAML/JSON/Text testcase format 📌 Comprehensive Testing Capabilities - UI Automation: Android/iOS/Harmony/Browser - API Testing: HTTP(S)/HTTP2/WebSocket/RPC - Load Testing: run API testcase concurrently with boomer 🧩 High Scalability - Plugin system for custom functions - Distributed testing support - Cross-platform: macOS/Linux/Windows 🛠 Easy Integration - CI/CD friendly with JSON logs and HTML reports - Rich ecosystem tools Learn more: Website: https://httprunner.com GitHub: https://github.com/httprunner/httprunner Copyright © 2017-present debugtalk. Apache-2.0 License.`, PersistentPreRun: func(cmd *cobra.Command, args []string) { enableLogFile := cmd.Name() != "report" hrp.InitLogger(logLevel, logJSON, enableLogFile) }, Version: version.GetVersionInfo(), TraverseChildren: true, SilenceUsage: true, }
rootCmd represents the base command when called without any subcommands
Functions ¶
This section is empty.
Types ¶
This section is empty.
Source Files
¶
Click to show internal directories.
Click to hide internal directories.