From 5e00895f76afae88bc5db44475ed231463f7f2b5 Mon Sep 17 00:00:00 2001 From: "xucong.053" Date: Thu, 10 Nov 2022 13:14:12 +0800 Subject: [PATCH] change: update annotation --- hrp/pkg/uixt/android_driver.go | 17 ++++++++++++++--- hrp/pkg/uixt/ext.go | 8 ++++---- hrp/step.go | 10 +++++----- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/hrp/pkg/uixt/android_driver.go b/hrp/pkg/uixt/android_driver.go index eae15617..5ebf69dd 100644 --- a/hrp/pkg/uixt/android_driver.go +++ b/hrp/pkg/uixt/android_driver.go @@ -18,6 +18,17 @@ import ( "github.com/httprunner/httprunner/v4/hrp/pkg/gadb" ) +// See https://developer.android.com/reference/android/view/KeyEvent +const ( + KEYCODE_BACK string = "4" + KEYCODE_CAMERA string = "27" + KEYCODE_ALT_LEFT string = "57" + KEYCODE_ALT_RIGHT string = "58" + KEYCODE_MENU string = "82" + KEYCODE_BREAK string = "121" + KEYCODE_ALL_APPS string = "284" +) + var errDriverNotImplemented = errors.New("driver method not implemented") type uiaDriver struct { @@ -237,7 +248,7 @@ func (ud *uiaDriver) PressBack(options ...DataOption) (err error) { // register(postHandler, new PressBack("/wd/hub/session/:sessionId/back")) _, err = ud.httpPOST(nil, "/session", ud.sessionId, "back") if err != nil { - _, err = ud.adbDevice.RunShellCommand("input", "keyevent", "4") + _, err = ud.adbDevice.RunShellCommand("input", "keyevent", KEYCODE_BACK) } return } @@ -260,7 +271,7 @@ func (ud *uiaDriver) StartCamera() (err error) { return err } time.Sleep(5 * time.Second) - if _, err = ud.adbDevice.RunShellCommand("input", "keyevent", "27"); err != nil { + if _, err = ud.adbDevice.RunShellCommand("input", "keyevent", KEYCODE_CAMERA); err != nil { return err } return @@ -269,7 +280,7 @@ func (ud *uiaDriver) StartCamera() (err error) { return err } time.Sleep(5 * time.Second) - if _, err = ud.adbDevice.RunShellCommand("input", "keyevent", "27"); err != nil { + if _, err = ud.adbDevice.RunShellCommand("input", "keyevent", KEYCODE_CAMERA); err != nil { return err } return diff --git a/hrp/pkg/uixt/ext.go b/hrp/pkg/uixt/ext.go index 119a03f7..531f95b8 100644 --- a/hrp/pkg/uixt/ext.go +++ b/hrp/pkg/uixt/ext.go @@ -673,10 +673,10 @@ func (dExt *DriverExt) DoAction(action MobileAction) error { } func (dExt *DriverExt) getAbsScope(x1, y1, x2, y2 float64) (int, int, int, int) { - return int(x1 * float64(dExt.windowSize.Width)), - int(y1 * float64(dExt.windowSize.Height)), - int(x2 * float64(dExt.windowSize.Width)), - int(y2 * float64(dExt.windowSize.Height)) + return int(x1 * float64(dExt.windowSize.Width) * dExt.scale), + int(y1 * float64(dExt.windowSize.Height) * dExt.scale), + int(x2 * float64(dExt.windowSize.Width) * dExt.scale), + int(y2 * float64(dExt.windowSize.Height) * dExt.scale) } func (dExt *DriverExt) DoValidation(check, assert, expected string, message ...string) bool { diff --git a/hrp/step.go b/hrp/step.go index c9e96023..0df0347a 100644 --- a/hrp/step.go +++ b/hrp/step.go @@ -22,18 +22,18 @@ const ( var ( WithIdentifier = uixt.WithIdentifier WithMaxRetryTimes = uixt.WithMaxRetryTimes - WithWaitTime = uixt.WithWaitTime - WithIndex = uixt.WithIndex + WithWaitTime = uixt.WithWaitTime // only applicable to SwipeToTap* action + WithIndex = uixt.WithIndex // index of the target element, should start from 1, only applicable to ocr actions WithTimeout = uixt.WithTimeout WithIgnoreNotFoundError = uixt.WithIgnoreNotFoundError WithText = uixt.WithText WithID = uixt.WithID WithDescription = uixt.WithDescription - WithDuration = uixt.WithDuration - WIthSteps = uixt.WithSteps + WithDuration = uixt.WithDuration // only applicable to ios swipe action + WithSteps = uixt.WithSteps // only applicable to android swipe action WithDirection = uixt.WithDirection WithCustomDirection = uixt.WithCustomDirection - WithScope = uixt.WithScope + WithScope = uixt.WithScope // only applicable to ocr actions WithOffset = uixt.WithOffset )