From 29c5c4df840c79c681fe77f805050418466ea06c Mon Sep 17 00:00:00 2001 From: "lilong.129" Date: Fri, 27 Jun 2025 12:12:48 +0800 Subject: [PATCH] feat: add auto popup handler configuration for HRPRunner --- cmd/run.go | 5 +++++ docs/cmd/hrp.md | 2 +- docs/cmd/hrp_adb.md | 2 +- docs/cmd/hrp_adb_devices.md | 2 +- docs/cmd/hrp_adb_install.md | 2 +- docs/cmd/hrp_adb_screencap.md | 2 +- docs/cmd/hrp_build.md | 2 +- docs/cmd/hrp_convert.md | 2 +- docs/cmd/hrp_ios.md | 2 +- docs/cmd/hrp_ios_apps.md | 2 +- docs/cmd/hrp_ios_devices.md | 2 +- docs/cmd/hrp_ios_install.md | 2 +- docs/cmd/hrp_ios_mount.md | 2 +- docs/cmd/hrp_ios_ps.md | 2 +- docs/cmd/hrp_ios_reboot.md | 2 +- docs/cmd/hrp_ios_tunnel.md | 2 +- docs/cmd/hrp_ios_uninstall.md | 2 +- docs/cmd/hrp_ios_xctest.md | 2 +- docs/cmd/hrp_mcp-server.md | 2 +- docs/cmd/hrp_mcphost.md | 2 +- docs/cmd/hrp_pytest.md | 2 +- docs/cmd/hrp_report.md | 2 +- docs/cmd/hrp_run.md | 23 ++++++++++++----------- docs/cmd/hrp_server.md | 2 +- docs/cmd/hrp_startproject.md | 2 +- docs/cmd/hrp_wiki.md | 2 +- runner.go | 26 +++++++++++++++++++++----- 27 files changed, 62 insertions(+), 40 deletions(-) diff --git a/cmd/run.go b/cmd/run.go index fe9721b6..5d566f78 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -36,6 +36,7 @@ var ( genHTMLReport bool caseTimeout float32 runMCPConfigPath string // MCP config path for run command + autoPopupHandler bool // enable auto popup handler for all steps ) func init() { @@ -48,6 +49,7 @@ func init() { CmdRun.Flags().BoolVarP(&genHTMLReport, "gen-html-report", "g", false, "generate html report") CmdRun.Flags().Float32Var(&caseTimeout, "case-timeout", 3600, "set testcase timeout (seconds)") CmdRun.Flags().StringVar(&runMCPConfigPath, "mcp-config", "", "path to the MCP config file") + CmdRun.Flags().BoolVar(&autoPopupHandler, "enable-auto-popup-handler", false, "enable auto popup handler for all UI steps") } func makeHRPRunner() *hrp.HRPRunner { @@ -76,5 +78,8 @@ func makeHRPRunner() *hrp.HRPRunner { if runMCPConfigPath != "" { runner.SetMCPConfigPath(runMCPConfigPath) } + if autoPopupHandler { + runner.EnableAutoPopupHandler(autoPopupHandler) + } return runner } diff --git a/docs/cmd/hrp.md b/docs/cmd/hrp.md index 9b57d269..944e56ab 100644 --- a/docs/cmd/hrp.md +++ b/docs/cmd/hrp.md @@ -63,4 +63,4 @@ Copyright © 2017-present debugtalk. Apache-2.0 License. * [hrp startproject](hrp_startproject.md) - Create a scaffold project * [hrp wiki](hrp_wiki.md) - visit https://httprunner.com -###### Auto generated by spf13/cobra on 8-Jun-2025 +###### Auto generated by spf13/cobra on 27-Jun-2025 diff --git a/docs/cmd/hrp_adb.md b/docs/cmd/hrp_adb.md index e4f26177..f7b1b740 100644 --- a/docs/cmd/hrp_adb.md +++ b/docs/cmd/hrp_adb.md @@ -23,4 +23,4 @@ simple utils for android device management * [hrp adb install](hrp_adb_install.md) - push package to the device and install them automatically * [hrp adb screencap](hrp_adb_screencap.md) - Start android screen capture -###### Auto generated by spf13/cobra on 8-Jun-2025 +###### Auto generated by spf13/cobra on 27-Jun-2025 diff --git a/docs/cmd/hrp_adb_devices.md b/docs/cmd/hrp_adb_devices.md index ba1296c3..015e76e9 100644 --- a/docs/cmd/hrp_adb_devices.md +++ b/docs/cmd/hrp_adb_devices.md @@ -24,4 +24,4 @@ hrp adb devices [flags] * [hrp adb](hrp_adb.md) - simple utils for android device management -###### Auto generated by spf13/cobra on 8-Jun-2025 +###### Auto generated by spf13/cobra on 27-Jun-2025 diff --git a/docs/cmd/hrp_adb_install.md b/docs/cmd/hrp_adb_install.md index 56687299..d47962af 100644 --- a/docs/cmd/hrp_adb_install.md +++ b/docs/cmd/hrp_adb_install.md @@ -28,4 +28,4 @@ hrp adb install [flags] PACKAGE * [hrp adb](hrp_adb.md) - simple utils for android device management -###### Auto generated by spf13/cobra on 8-Jun-2025 +###### Auto generated by spf13/cobra on 27-Jun-2025 diff --git a/docs/cmd/hrp_adb_screencap.md b/docs/cmd/hrp_adb_screencap.md index 5c656ea5..8e950a6b 100644 --- a/docs/cmd/hrp_adb_screencap.md +++ b/docs/cmd/hrp_adb_screencap.md @@ -25,4 +25,4 @@ hrp adb screencap [flags] * [hrp adb](hrp_adb.md) - simple utils for android device management -###### Auto generated by spf13/cobra on 8-Jun-2025 +###### Auto generated by spf13/cobra on 27-Jun-2025 diff --git a/docs/cmd/hrp_build.md b/docs/cmd/hrp_build.md index eab54dd9..dc5ebdb2 100644 --- a/docs/cmd/hrp_build.md +++ b/docs/cmd/hrp_build.md @@ -36,4 +36,4 @@ hrp build $path ... [flags] * [hrp](hrp.md) - All-in-One Testing Framework for API, UI and Performance -###### Auto generated by spf13/cobra on 8-Jun-2025 +###### Auto generated by spf13/cobra on 27-Jun-2025 diff --git a/docs/cmd/hrp_convert.md b/docs/cmd/hrp_convert.md index 81e985ea..d8c37ed1 100644 --- a/docs/cmd/hrp_convert.md +++ b/docs/cmd/hrp_convert.md @@ -34,4 +34,4 @@ hrp convert $path... [flags] * [hrp](hrp.md) - All-in-One Testing Framework for API, UI and Performance -###### Auto generated by spf13/cobra on 8-Jun-2025 +###### Auto generated by spf13/cobra on 27-Jun-2025 diff --git a/docs/cmd/hrp_ios.md b/docs/cmd/hrp_ios.md index f38307ed..63500f19 100644 --- a/docs/cmd/hrp_ios.md +++ b/docs/cmd/hrp_ios.md @@ -29,4 +29,4 @@ simple utils for ios device management * [hrp ios uninstall](hrp_ios_uninstall.md) - uninstall package automatically * [hrp ios xctest](hrp_ios_xctest.md) - run xctest -###### Auto generated by spf13/cobra on 8-Jun-2025 +###### Auto generated by spf13/cobra on 27-Jun-2025 diff --git a/docs/cmd/hrp_ios_apps.md b/docs/cmd/hrp_ios_apps.md index 2529c98f..1e42aec4 100644 --- a/docs/cmd/hrp_ios_apps.md +++ b/docs/cmd/hrp_ios_apps.md @@ -26,4 +26,4 @@ hrp ios apps [flags] * [hrp ios](hrp_ios.md) - simple utils for ios device management -###### Auto generated by spf13/cobra on 8-Jun-2025 +###### Auto generated by spf13/cobra on 27-Jun-2025 diff --git a/docs/cmd/hrp_ios_devices.md b/docs/cmd/hrp_ios_devices.md index 6b4e15c6..13e29866 100644 --- a/docs/cmd/hrp_ios_devices.md +++ b/docs/cmd/hrp_ios_devices.md @@ -24,4 +24,4 @@ hrp ios devices [flags] * [hrp ios](hrp_ios.md) - simple utils for ios device management -###### Auto generated by spf13/cobra on 8-Jun-2025 +###### Auto generated by spf13/cobra on 27-Jun-2025 diff --git a/docs/cmd/hrp_ios_install.md b/docs/cmd/hrp_ios_install.md index 5b85c94e..c3985c73 100644 --- a/docs/cmd/hrp_ios_install.md +++ b/docs/cmd/hrp_ios_install.md @@ -25,4 +25,4 @@ hrp ios install [flags] PACKAGE * [hrp ios](hrp_ios.md) - simple utils for ios device management -###### Auto generated by spf13/cobra on 8-Jun-2025 +###### Auto generated by spf13/cobra on 27-Jun-2025 diff --git a/docs/cmd/hrp_ios_mount.md b/docs/cmd/hrp_ios_mount.md index 43312b16..26efd7d9 100644 --- a/docs/cmd/hrp_ios_mount.md +++ b/docs/cmd/hrp_ios_mount.md @@ -28,4 +28,4 @@ hrp ios mount [flags] * [hrp ios](hrp_ios.md) - simple utils for ios device management -###### Auto generated by spf13/cobra on 8-Jun-2025 +###### Auto generated by spf13/cobra on 27-Jun-2025 diff --git a/docs/cmd/hrp_ios_ps.md b/docs/cmd/hrp_ios_ps.md index 9173a89f..5696a24e 100644 --- a/docs/cmd/hrp_ios_ps.md +++ b/docs/cmd/hrp_ios_ps.md @@ -26,4 +26,4 @@ hrp ios ps [flags] * [hrp ios](hrp_ios.md) - simple utils for ios device management -###### Auto generated by spf13/cobra on 8-Jun-2025 +###### Auto generated by spf13/cobra on 27-Jun-2025 diff --git a/docs/cmd/hrp_ios_reboot.md b/docs/cmd/hrp_ios_reboot.md index 81d41d98..9feb9fb4 100644 --- a/docs/cmd/hrp_ios_reboot.md +++ b/docs/cmd/hrp_ios_reboot.md @@ -25,4 +25,4 @@ hrp ios reboot [flags] * [hrp ios](hrp_ios.md) - simple utils for ios device management -###### Auto generated by spf13/cobra on 8-Jun-2025 +###### Auto generated by spf13/cobra on 27-Jun-2025 diff --git a/docs/cmd/hrp_ios_tunnel.md b/docs/cmd/hrp_ios_tunnel.md index 51fa5033..b80eeedc 100644 --- a/docs/cmd/hrp_ios_tunnel.md +++ b/docs/cmd/hrp_ios_tunnel.md @@ -24,4 +24,4 @@ hrp ios tunnel [flags] * [hrp ios](hrp_ios.md) - simple utils for ios device management -###### Auto generated by spf13/cobra on 8-Jun-2025 +###### Auto generated by spf13/cobra on 27-Jun-2025 diff --git a/docs/cmd/hrp_ios_uninstall.md b/docs/cmd/hrp_ios_uninstall.md index ad4e1247..d2ebcb5a 100644 --- a/docs/cmd/hrp_ios_uninstall.md +++ b/docs/cmd/hrp_ios_uninstall.md @@ -26,4 +26,4 @@ hrp ios uninstall [flags] PACKAGE * [hrp ios](hrp_ios.md) - simple utils for ios device management -###### Auto generated by spf13/cobra on 8-Jun-2025 +###### Auto generated by spf13/cobra on 27-Jun-2025 diff --git a/docs/cmd/hrp_ios_xctest.md b/docs/cmd/hrp_ios_xctest.md index 50ea73dd..001fb2e1 100644 --- a/docs/cmd/hrp_ios_xctest.md +++ b/docs/cmd/hrp_ios_xctest.md @@ -28,4 +28,4 @@ hrp ios xctest [flags] * [hrp ios](hrp_ios.md) - simple utils for ios device management -###### Auto generated by spf13/cobra on 8-Jun-2025 +###### Auto generated by spf13/cobra on 27-Jun-2025 diff --git a/docs/cmd/hrp_mcp-server.md b/docs/cmd/hrp_mcp-server.md index b066c165..f906af4b 100644 --- a/docs/cmd/hrp_mcp-server.md +++ b/docs/cmd/hrp_mcp-server.md @@ -28,4 +28,4 @@ hrp mcp-server [flags] * [hrp](hrp.md) - All-in-One Testing Framework for API, UI and Performance -###### Auto generated by spf13/cobra on 8-Jun-2025 +###### Auto generated by spf13/cobra on 27-Jun-2025 diff --git a/docs/cmd/hrp_mcphost.md b/docs/cmd/hrp_mcphost.md index c0d5dff1..bebdbc4f 100644 --- a/docs/cmd/hrp_mcphost.md +++ b/docs/cmd/hrp_mcphost.md @@ -31,4 +31,4 @@ hrp mcphost [flags] * [hrp](hrp.md) - All-in-One Testing Framework for API, UI and Performance -###### Auto generated by spf13/cobra on 8-Jun-2025 +###### Auto generated by spf13/cobra on 27-Jun-2025 diff --git a/docs/cmd/hrp_pytest.md b/docs/cmd/hrp_pytest.md index ecb007ea..a2b0a11c 100644 --- a/docs/cmd/hrp_pytest.md +++ b/docs/cmd/hrp_pytest.md @@ -24,4 +24,4 @@ hrp pytest $path ... [flags] * [hrp](hrp.md) - All-in-One Testing Framework for API, UI and Performance -###### Auto generated by spf13/cobra on 8-Jun-2025 +###### Auto generated by spf13/cobra on 27-Jun-2025 diff --git a/docs/cmd/hrp_report.md b/docs/cmd/hrp_report.md index 9d713483..d781cea7 100644 --- a/docs/cmd/hrp_report.md +++ b/docs/cmd/hrp_report.md @@ -33,4 +33,4 @@ hrp report [result_folder] [flags] * [hrp](hrp.md) - All-in-One Testing Framework for API, UI and Performance -###### Auto generated by spf13/cobra on 8-Jun-2025 +###### Auto generated by spf13/cobra on 27-Jun-2025 diff --git a/docs/cmd/hrp_run.md b/docs/cmd/hrp_run.md index 323493b0..12c2cb62 100644 --- a/docs/cmd/hrp_run.md +++ b/docs/cmd/hrp_run.md @@ -21,16 +21,17 @@ hrp run $path... [flags] ### Options ``` - --case-timeout float32 set testcase timeout (seconds) (default 3600) - -c, --continue-on-failure continue running next step when failure occurs - -g, --gen-html-report generate html report - -h, --help help for run - --http-stat turn on HTTP latency stat (DNSLookup, TCP Connection, etc.) - --log-plugin turn on plugin logging - --log-requests-off turn off request & response details logging - --mcp-config string path to the MCP config file - -p, --proxy-url string set proxy url - -s, --save-tests save tests summary + --case-timeout float32 set testcase timeout (seconds) (default 3600) + -c, --continue-on-failure continue running next step when failure occurs + --enable-auto-popup-handler enable auto popup handler for all UI steps + -g, --gen-html-report generate html report + -h, --help help for run + --http-stat turn on HTTP latency stat (DNSLookup, TCP Connection, etc.) + --log-plugin turn on plugin logging + --log-requests-off turn off request & response details logging + --mcp-config string path to the MCP config file + -p, --proxy-url string set proxy url + -s, --save-tests save tests summary ``` ### Options inherited from parent commands @@ -45,4 +46,4 @@ hrp run $path... [flags] * [hrp](hrp.md) - All-in-One Testing Framework for API, UI and Performance -###### Auto generated by spf13/cobra on 8-Jun-2025 +###### Auto generated by spf13/cobra on 27-Jun-2025 diff --git a/docs/cmd/hrp_server.md b/docs/cmd/hrp_server.md index 7edb4106..da60a80d 100644 --- a/docs/cmd/hrp_server.md +++ b/docs/cmd/hrp_server.md @@ -30,4 +30,4 @@ hrp server start [flags] * [hrp](hrp.md) - All-in-One Testing Framework for API, UI and Performance -###### Auto generated by spf13/cobra on 8-Jun-2025 +###### Auto generated by spf13/cobra on 27-Jun-2025 diff --git a/docs/cmd/hrp_startproject.md b/docs/cmd/hrp_startproject.md index 5826d901..e0605b43 100644 --- a/docs/cmd/hrp_startproject.md +++ b/docs/cmd/hrp_startproject.md @@ -29,4 +29,4 @@ hrp startproject $project_name [flags] * [hrp](hrp.md) - All-in-One Testing Framework for API, UI and Performance -###### Auto generated by spf13/cobra on 8-Jun-2025 +###### Auto generated by spf13/cobra on 27-Jun-2025 diff --git a/docs/cmd/hrp_wiki.md b/docs/cmd/hrp_wiki.md index 53e6e4c9..042fd8c0 100644 --- a/docs/cmd/hrp_wiki.md +++ b/docs/cmd/hrp_wiki.md @@ -24,4 +24,4 @@ hrp wiki [flags] * [hrp](hrp.md) - All-in-One Testing Framework for API, UI and Performance -###### Auto generated by spf13/cobra on 8-Jun-2025 +###### Auto generated by spf13/cobra on 27-Jun-2025 diff --git a/runner.go b/runner.go index fe944244..81bb88fe 100644 --- a/runner.go +++ b/runner.go @@ -18,12 +18,12 @@ import ( "time" "github.com/gorilla/websocket" + "github.com/httprunner/funplugin" "github.com/jinzhu/copier" "github.com/pkg/errors" "github.com/rs/zerolog/log" "golang.org/x/net/http2" - "github.com/httprunner/funplugin" "github.com/httprunner/httprunner/v5/code" "github.com/httprunner/httprunner/v5/internal/builtin" "github.com/httprunner/httprunner/v5/internal/config" @@ -50,10 +50,11 @@ func NewRunner(t *testing.T) *HRPRunner { interruptSignal := make(chan os.Signal, 1) signal.Notify(interruptSignal, syscall.SIGTERM, syscall.SIGINT) return &HRPRunner{ - t: t, - failfast: true, // default to failfast - genHTMLReport: false, - mcpConfigPath: "", + t: t, + failfast: true, // default to failfast + genHTMLReport: false, + mcpConfigPath: "", + autoPopupHandler: false, httpClient: &http.Client{ Transport: &http.Transport{ TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, @@ -87,6 +88,7 @@ type HRPRunner struct { saveTests bool genHTMLReport bool mcpConfigPath string // MCP config file path + autoPopupHandler bool // enable auto popup handler for all UI steps httpClient *http.Client http2Client *http.Client wsDialer *websocket.Dialer @@ -198,6 +200,13 @@ func (r *HRPRunner) GenHTMLReport() *HRPRunner { return r } +// EnableAutoPopupHandler configures whether to enable auto popup handler for all UI steps. +func (r *HRPRunner) EnableAutoPopupHandler(enabled bool) *HRPRunner { + log.Info().Bool("autoPopupHandler", enabled).Msg("[init] EnableAutoPopupHandler") + r.autoPopupHandler = enabled + return r +} + // SetMCPConfigPath configures the MCP config path. func (r *HRPRunner) SetMCPConfigPath(mcpConfigPath string) *HRPRunner { log.Info().Str("mcpConfigPath", mcpConfigPath).Msg("[init] SetMCPConfigPath") @@ -394,6 +403,13 @@ func NewCaseRunner(testcase TestCase, hrpRunner *HRPRunner) (*CaseRunner, error) return nil, errors.Wrap(err, "parse testcase config failed") } + // apply global auto popup handler setting if enabled + // priority: command line > testcase config > step config + if hrpRunner.autoPopupHandler { + parsedConfig.AutoPopupHandler = true + log.Info().Bool("autoPopupHandler", true).Msg("applied global auto popup handler setting") + } + // set request timeout in seconds if parsedConfig.RequestTimeout != 0 { hrpRunner.SetRequestTimeout(parsedConfig.RequestTimeout)