fix: failed to exec web script

This commit is contained in:
徐聪
2025-06-24 23:02:35 +08:00
parent d926d908e0
commit ea6b0a6902
5 changed files with 60 additions and 4 deletions

View File

@@ -38,6 +38,49 @@ build: ## build hrp cli tool
-o output/hrp ./cmd/cli
./output/hrp -v
.PHONY: build-windows
build-windows: ## build hrp cli tool for Windows amd64
@echo "[info] build hrp cli tool for Windows amd64"
go mod tidy
GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go build -tags netgo,osusergo -trimpath -ldflags "\
-s -w \
-X 'github.com/httprunner/httprunner/v5/internal/version.GitCommit=$(shell git rev-parse HEAD)' \
-X 'github.com/httprunner/httprunner/v5/internal/version.GitBranch=$(shell git rev-parse --abbrev-ref HEAD)' \
-X 'github.com/httprunner/httprunner/v5/internal/version.GitAuthor=$(shell git log -1 --pretty=format:%an)' \
-X 'github.com/httprunner/httprunner/v5/internal/version.BuildTime=$(shell date "+%y%m%d%H%M")'" \
-o output/hrp.exe ./cmd/cli
@echo "[info] Windows binary built successfully: output/hrp.exe"
.PHONY: build-windows-arm64
build-windows-arm64: ## build hrp cli tool for Windows arm64
@echo "[info] build hrp cli tool for Windows arm64"
go mod tidy
GOOS=windows GOARCH=arm64 CGO_ENABLED=0 go build -tags netgo,osusergo -trimpath -ldflags "\
-s -w \
-X 'github.com/httprunner/httprunner/v5/internal/version.GitCommit=$(shell git rev-parse HEAD)' \
-X 'github.com/httprunner/httprunner/v5/internal/version.GitBranch=$(shell git rev-parse --abbrev-ref HEAD)' \
-X 'github.com/httprunner/httprunner/v5/internal/version.GitAuthor=$(shell git log -1 --pretty=format:%an)' \
-X 'github.com/httprunner/httprunner/v5/internal/version.BuildTime=$(shell date "+%y%m%d%H%M")'" \
-o output/hrp_arm64.exe ./cmd/cli
@echo "[info] Windows ARM64 binary built successfully: output/hrp_arm64.exe"
.PHONY: build-linux
build-linux: ## build hrp cli tool for Linux amd64
@echo "[info] build hrp cli tool for Linux amd64"
go mod tidy
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -tags netgo,osusergo -trimpath -ldflags "\
-s -w \
-X 'github.com/httprunner/httprunner/v5/internal/version.GitCommit=$(shell git rev-parse HEAD)' \
-X 'github.com/httprunner/httprunner/v5/internal/version.GitBranch=$(shell git rev-parse --abbrev-ref HEAD)' \
-X 'github.com/httprunner/httprunner/v5/internal/version.GitAuthor=$(shell git log -1 --pretty=format:%an)' \
-X 'github.com/httprunner/httprunner/v5/internal/version.BuildTime=$(shell date "+%y%m%d%H%M")'" \
-o output/hrp_linux ./cmd/cli
@echo "[info] Linux binary built successfully: output/hrp_linux"
.PHONY: build-all
build-all: build build-windows build-windows-arm64 build-linux ## build hrp cli tool for all platforms
@echo "[info] All binaries built successfully"
.PHONY: install-hooks
install-hooks: ## install git hooks
@find scripts -name "install-*-hook" | awk -F'-' '{s=$$2;for(i=3;i<NF;i++){s=s"-"$$i;}print s;}' | while read f; do bash "scripts/install-$$f-hook"; done

View File

@@ -1 +1 @@
v5.0.0-beta-2506222254
v5.0.0-beta-2506242302

View File

@@ -37,6 +37,7 @@ type CreateBrowserResponse struct {
type BrowserDriver struct {
urlPrefix *url.URL
Session *DriverSession
Device *BrowserDevice
}
type BrowserInfo struct {
@@ -96,6 +97,7 @@ func CreateBrowser(timeout int, width, height int) (browserInfo *BrowserInfo, er
func NewBrowserDriver(device *BrowserDevice) (driver *BrowserDriver, err error) {
log.Info().Msg("init NewBrowserDriver driver")
driver = new(BrowserDriver)
driver.Device = device
driver.urlPrefix = &url.URL{}
driver.urlPrefix.Host = BROWSER_LOCAL_ADDRESS
driver.urlPrefix.Scheme = "http"
@@ -597,7 +599,7 @@ func (wd *BrowserDriver) Clear(packageName string) error {
}
func (wd *BrowserDriver) GetDevice() IDevice {
return nil
return wd.Device
}
func (wd *BrowserDriver) ForegroundInfo() (app types.AppInfo, err error) {

View File

@@ -117,6 +117,7 @@ func (s *MCPServer4XTDriver) registerTools() {
s.registerTool(&ToolClosePopups{})
// PC/Web Tools
s.registerTool(&ToolWebLoginNoneUI{})
s.registerTool(&ToolSecondaryClick{})
s.registerTool(&ToolHoverBySelector{})
s.registerTool(&ToolTapBySelector{})

View File

@@ -63,7 +63,15 @@ func (t *ToolWebLoginNoneUI) Implement() server.ToolHandlerFunc {
}
func (t *ToolWebLoginNoneUI) ConvertActionToCallToolRequest(action option.MobileAction) (mcp.CallToolRequest, error) {
return BuildMCPCallToolRequest(t.Name(), map[string]any{}), nil
arguments := map[string]any{}
if textsSlice, ok := action.Params.([]interface{}); ok {
arguments["packageName"] = textsSlice[0].(string)
arguments["phoneNumber"] = textsSlice[1].(string)
arguments["captcha"] = textsSlice[2].(string)
arguments["password"] = textsSlice[3].(string)
}
return BuildMCPCallToolRequest(t.Name(), arguments), nil
}
// ToolSecondaryClick implements the secondary_click tool call.
@@ -216,7 +224,7 @@ func (t *ToolTapBySelector) Implement() server.ToolHandlerFunc {
}
// Tap by selector action logic
err = driverExt.TapBySelector(unifiedReq.Selector)
err = driverExt.TapBySelector(unifiedReq.Selector, option.WithIndex(unifiedReq.Index))
if err != nil {
return NewMCPErrorResponse(fmt.Sprintf("Tap by selector failed: %s", err.Error())), nil
}
@@ -233,6 +241,8 @@ func (t *ToolTapBySelector) ConvertActionToCallToolRequest(action option.MobileA
arguments := map[string]any{
"selector": selector,
}
// Extract options to arguments
extractActionOptionsToArguments(action.GetOptions(), arguments)
return BuildMCPCallToolRequest(t.Name(), arguments), nil
}
return mcp.CallToolRequest{}, fmt.Errorf("invalid tap by selector params: %v", action.Params)