From f83338b28f523936b0cba4a4b530f1384c8c22cf Mon Sep 17 00:00:00 2001 From: "lilong.129" Date: Tue, 10 Dec 2024 21:50:34 +0800 Subject: [PATCH] feat: check WDA server status before create session --- hrp/internal/version/VERSION | 2 +- hrp/pkg/uixt/ios_device.go | 15 ++++++++++++++- hrp/pkg/uixt/ios_wda_driver.go | 9 +++++---- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/hrp/internal/version/VERSION b/hrp/internal/version/VERSION index 741839ce..2bd7f83b 100644 --- a/hrp/internal/version/VERSION +++ b/hrp/internal/version/VERSION @@ -1 +1 @@ -v5.0.0+2412101121 +v5.0.0+2412102150 diff --git a/hrp/pkg/uixt/ios_device.go b/hrp/pkg/uixt/ios_device.go index c6dcd0d7..d7cc57d8 100644 --- a/hrp/pkg/uixt/ios_device.go +++ b/hrp/pkg/uixt/ios_device.go @@ -430,7 +430,6 @@ func (dev *IOSDevice) NewDriver(options ...DriverOption) (driverExt *DriverExt, if err != nil { return nil, errors.Wrap(err, "failed to init Stub driver") } - } else { driver, err = dev.NewHTTPDriver(capabilities) if err != nil { @@ -774,6 +773,20 @@ func (dev *IOSDevice) NewHTTPDriver(capabilities Capabilities) (driver IWebDrive if wd.urlPrefix, err = url.Parse(fmt.Sprintf("http://%s:%d", host, localPort)); err != nil { return nil, errors.Wrap(code.DeviceHTTPDriverError, err.Error()) } + + // check WDA server status + status, err := wd.Status() + if err != nil { + return nil, errors.Wrapf(code.DeviceHTTPDriverError, + "get WDA server status failed: %s", err.Error()) + } + log.Info().Interface("status", status).Msg("get WDA server status") + if status.State != "success" { + return nil, errors.Wrap(code.DeviceHTTPDriverError, + "WDA server status is not success") + } + + // create new session var sessionInfo SessionInfo if sessionInfo, err = wd.NewSession(capabilities); err != nil { return nil, errors.Wrap(code.DeviceHTTPDriverError, err.Error()) diff --git a/hrp/pkg/uixt/ios_wda_driver.go b/hrp/pkg/uixt/ios_wda_driver.go index f6b32a0f..831d5068 100644 --- a/hrp/pkg/uixt/ios_wda_driver.go +++ b/hrp/pkg/uixt/ios_wda_driver.go @@ -6,6 +6,7 @@ import ( builtinJSON "encoding/json" "fmt" "io" + "math" "net" "net/http" "net/url" @@ -559,10 +560,10 @@ func (wd *wdaDriver) Drag(fromX, fromY, toX, toY float64, options ...ActionOptio toY += actionOptions.getRandomOffset() data := map[string]interface{}{ - "fromX": fromX, - "fromY": fromY, - "toX": toX, - "toY": toY, + "fromX": math.Round(fromX*10) / 10, + "fromY": math.Round(fromY*10) / 10, + "toX": math.Round(toX*10) / 10, + "toY": math.Round(toY*10) / 10, } if actionOptions.PressDuration > 0 { data["pressDuration"] = actionOptions.PressDuration