From 38820a869ab0609295738b66c67acbd5157bac38 Mon Sep 17 00:00:00 2001 From: "lilong.129" Date: Mon, 5 Jun 2023 22:05:13 +0800 Subject: [PATCH] feat: support sleep constant time --- hrp/internal/version/VERSION | 2 +- hrp/pkg/uixt/action.go | 7 +++++-- hrp/pkg/uixt/action_test.go | 36 ++++++++++++++++++++++++++++++++++++ hrp/pkg/uixt/tap_test.go | 10 ---------- 4 files changed, 42 insertions(+), 13 deletions(-) create mode 100644 hrp/pkg/uixt/action_test.go diff --git a/hrp/internal/version/VERSION b/hrp/internal/version/VERSION index 2eb49042..ceb7ead9 100644 --- a/hrp/internal/version/VERSION +++ b/hrp/internal/version/VERSION @@ -1 +1 @@ -v4.3.4-beta-2306052108 \ No newline at end of file +v4.3.4-beta-2306052205 \ No newline at end of file diff --git a/hrp/pkg/uixt/action.go b/hrp/pkg/uixt/action.go index 138474eb..025432e8 100644 --- a/hrp/pkg/uixt/action.go +++ b/hrp/pkg/uixt/action.go @@ -542,8 +542,11 @@ func convertToFloat64(val interface{}) (float64, error) { } func sleepRandom(params []interface{}) error { - // append default weight 1 - if len(params) == 2 { + if len(params) == 1 { + // constant sleep time + params = append(params, params[0], 1.0) + } else if len(params) == 2 { + // append default weight 1 params = append(params, 1.0) } diff --git a/hrp/pkg/uixt/action_test.go b/hrp/pkg/uixt/action_test.go new file mode 100644 index 00000000..aba7dcc5 --- /dev/null +++ b/hrp/pkg/uixt/action_test.go @@ -0,0 +1,36 @@ +package uixt + +import ( + "testing" + "time" +) + +func checkErr(t *testing.T, err error, msg ...string) { + if err != nil { + if len(msg) == 0 { + t.Fatal(err) + } else { + t.Fatal(msg, err) + } + } +} + +func TestSleepRandom(t *testing.T) { + startTime := time.Now() + params := []interface{}{1} + err := sleepRandom(params) + checkErr(t, err) + dur := time.Since(startTime).Seconds() + if dur < 0.9 || dur > 1.1 { + t.Fatal("sleepRandom failed") + } + + startTime = time.Now() + params = []interface{}{1, 2} + err = sleepRandom(params) + checkErr(t, err) + dur = time.Since(startTime).Seconds() + if dur < 1 || dur > 2 { + t.Fatal("sleepRandom failed") + } +} diff --git a/hrp/pkg/uixt/tap_test.go b/hrp/pkg/uixt/tap_test.go index 950b7049..4de3428e 100644 --- a/hrp/pkg/uixt/tap_test.go +++ b/hrp/pkg/uixt/tap_test.go @@ -12,16 +12,6 @@ func init() { iosDevice, _ = NewIOSDevice() } -func checkErr(t *testing.T, err error, msg ...string) { - if err != nil { - if len(msg) == 0 { - t.Fatal(err) - } else { - t.Fatal(msg, err) - } - } -} - func TestDriverExt_TapXY(t *testing.T) { driverExt, err := iosDevice.NewDriver(nil) checkErr(t, err)