From c5712b1a6682b6cedb80d897e62ade5764b17ac8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=99=E6=B3=93=E9=93=AE?= Date: Wed, 12 Jun 2024 11:37:29 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8Dduration=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E4=B8=8D=E5=87=86=E7=A1=AE=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hrp/internal/version/VERSION | 2 +- hrp/pkg/uixt/android_test.go | 21 ++++++++++----------- hrp/pkg/uixt/android_uia2_driver.go | 12 +++++++++--- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/hrp/internal/version/VERSION b/hrp/internal/version/VERSION index dfe33e04..baabcd7d 100644 --- a/hrp/internal/version/VERSION +++ b/hrp/internal/version/VERSION @@ -1 +1 @@ -v4.5.1 \ No newline at end of file +v4.5.6 \ No newline at end of file diff --git a/hrp/pkg/uixt/android_test.go b/hrp/pkg/uixt/android_test.go index 3c20f741..591893d0 100644 --- a/hrp/pkg/uixt/android_test.go +++ b/hrp/pkg/uixt/android_test.go @@ -216,17 +216,8 @@ func TestDriver_Tap(t *testing.T) { } func TestDriver_Swipe(t *testing.T) { - driver, err := NewUIADriver(nil, uiaServerURL) - if err != nil { - t.Fatal(err) - } - - err = driver.Swipe(400, 1000, 400, 500, WithPressDuration(2000)) - if err != nil { - t.Fatal(err) - } - - err = driver.SwipeFloat(400, 555.5, 400, 1255.5) + setupAndroid(t) + err := driverExt.Driver.Swipe(400, 1000, 400, 500, WithPressDuration(0.5)) if err != nil { t.Fatal(err) } @@ -307,6 +298,14 @@ func TestDriver_SetRotation(t *testing.T) { } } +func TestDriver_GetOrientation(t *testing.T) { + setupAndroid(t) + _, _ = driverExt.Driver.AppTerminate("com.quark.browser") + _ = driverExt.Driver.AppLaunch("com.quark.browser") + time.Sleep(2 * time.Second) + _ = driverExt.Driver.Homescreen() +} + func TestUiSelectorHelper_NewUiSelectorHelper(t *testing.T) { uiSelector := NewUiSelectorHelper().Text("a").String() if uiSelector != `new UiSelector().text("a");` { diff --git a/hrp/pkg/uixt/android_uia2_driver.go b/hrp/pkg/uixt/android_uia2_driver.go index 6606cd78..8e962d29 100644 --- a/hrp/pkg/uixt/android_uia2_driver.go +++ b/hrp/pkg/uixt/android_uia2_driver.go @@ -29,6 +29,7 @@ func NewUIADriver(capabilities Capabilities, urlPrefix string) (driver *uiaDrive log.Info().Msg("init uiautomator2 driver") if capabilities == nil { capabilities = NewCapabilities() + capabilities.WithWaitForIdleTimeout(0) } driver = new(uiaDriver) if driver.urlPrefix, err = url.Parse(urlPrefix); err != nil { @@ -141,7 +142,12 @@ func (ud *uiaDriver) httpDELETE(pathElem ...string) (rawResp rawResponse, err er func (ud *uiaDriver) NewSession(capabilities Capabilities) (sessionInfo SessionInfo, err error) { // register(postHandler, new NewSession("/wd/hub/session")) var rawResp rawResponse - data := map[string]interface{}{"capabilities": capabilities} + data := make(map[string]interface{}) + if len(capabilities) == 0 { + data["capabilities"] = make(map[string]interface{}) + } else { + data["capabilities"] = map[string]interface{}{"alwaysMatch": capabilities} + } if rawResp, err = ud.Driver.httpPOST(data, "/session"); err != nil { return SessionInfo{SessionId: ""}, err } @@ -293,7 +299,7 @@ func (ud *uiaDriver) TapFloat(x, y float64, options ...ActionOption) (err error) duration := 100.0 if actionOptions.PressDuration > 0 { - duration = actionOptions.PressDuration + duration = actionOptions.PressDuration * 1000 } data := map[string]interface{}{ "actions": []interface{}{ @@ -399,7 +405,7 @@ func (ud *uiaDriver) SwipeFloat(fromX, fromY, toX, toY float64, options ...Actio duration := 200.0 if actionOptions.PressDuration > 0 { - duration = actionOptions.PressDuration + duration = actionOptions.PressDuration * 1000 } data := map[string]interface{}{ "actions": []interface{}{