mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-08 08:57:40 +08:00
fix: unload android device screen
This commit is contained in:
@@ -1 +1 @@
|
|||||||
v5.0.0+2412182148
|
v5.0.0+2412191212
|
||||||
|
|||||||
@@ -279,7 +279,18 @@ func (ad *adbDriver) Homescreen() (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (ad *adbDriver) Unlock() (err error) {
|
func (ad *adbDriver) Unlock() (err error) {
|
||||||
return ad.PressKeyCodes(KCMenu, KMEmpty)
|
// Notice: brighten should be executed before unlock
|
||||||
|
// brighten android device screen
|
||||||
|
if err := ad.PressKeyCodes(KCWakeup, KMEmpty); err != nil {
|
||||||
|
log.Error().Err(err).Msg("brighten android device screen failed")
|
||||||
|
}
|
||||||
|
// unlock android device screen
|
||||||
|
if err := ad.PressKeyCodes(KCMenu, KMEmpty); err != nil {
|
||||||
|
log.Error().Err(err).Msg("press menu key to unlock screen failed")
|
||||||
|
}
|
||||||
|
|
||||||
|
// swipe up to unlock
|
||||||
|
return ad.Swipe(500, 1500, 500, 500)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ad *adbDriver) Backspace(count int, options ...ActionOption) (err error) {
|
func (ad *adbDriver) Backspace(count int, options ...ActionOption) (err error) {
|
||||||
@@ -287,12 +298,12 @@ func (ad *adbDriver) Backspace(count int, options ...ActionOption) (err error) {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if count == 1 {
|
if count == 1 {
|
||||||
return ad.PressKeyCode(67)
|
return ad.PressKeyCode(KCDel)
|
||||||
}
|
}
|
||||||
keyArray := make([]KeyCode, count)
|
keyArray := make([]KeyCode, count)
|
||||||
|
|
||||||
for i := range keyArray {
|
for i := range keyArray {
|
||||||
keyArray[i] = KeyCode(67)
|
keyArray[i] = KCDel
|
||||||
}
|
}
|
||||||
return ad.combinationKey(keyArray)
|
return ad.combinationKey(keyArray)
|
||||||
}
|
}
|
||||||
@@ -315,9 +326,18 @@ func (ad *adbDriver) PressKeyCode(keyCode KeyCode) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (ad *adbDriver) PressKeyCodes(keyCode KeyCode, metaState KeyMeta) (err error) {
|
func (ad *adbDriver) PressKeyCodes(keyCode KeyCode, metaState KeyMeta) (err error) {
|
||||||
// adb shell input keyevent <keyCode>
|
// adb shell input keyevent [--longpress] KEYCODE [METASTATE]
|
||||||
|
if metaState != KMEmpty {
|
||||||
|
// press key with metastate, e.g. KMShiftOn/KMCtrlOn
|
||||||
_, err = ad.runShellCommand(
|
_, err = ad.runShellCommand(
|
||||||
"input", "keyevent", fmt.Sprintf("%d", keyCode))
|
"input", "keyevent", "--longpress",
|
||||||
|
fmt.Sprintf("%d", keyCode),
|
||||||
|
fmt.Sprintf("%d", metaState))
|
||||||
|
} else {
|
||||||
|
_, err = ad.runShellCommand(
|
||||||
|
"input", "keyevent",
|
||||||
|
fmt.Sprintf("%d", keyCode))
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+21
-21
@@ -10,27 +10,27 @@ const (
|
|||||||
KMAltLocked KeyMeta = 0x200 // ALT key locked.
|
KMAltLocked KeyMeta = 0x200 // ALT key locked.
|
||||||
KMSymLocked KeyMeta = 0x400 // SYM key locked.
|
KMSymLocked KeyMeta = 0x400 // SYM key locked.
|
||||||
KMSelecting KeyMeta = 0x800 // Text is in selection mode.
|
KMSelecting KeyMeta = 0x800 // Text is in selection mode.
|
||||||
// KMAltOn KeyMeta = 0x02 // This mask is used to check whether one of the ALT meta keys is pressed.
|
KMAltOn KeyMeta = 0x02 // This mask is used to check whether one of the ALT meta keys is pressed.
|
||||||
// KMAltLeftOn KeyMeta = 0x10 // This mask is used to check whether the left ALT meta key is pressed.
|
KMAltLeftOn KeyMeta = 0x10 // This mask is used to check whether the left ALT meta key is pressed.
|
||||||
// KMAltRightOn KeyMeta = 0x20 // This mask is used to check whether the right the ALT meta key is pressed.
|
KMAltRightOn KeyMeta = 0x20 // This mask is used to check whether the right the ALT meta key is pressed.
|
||||||
// KMShiftOn KeyMeta = 0x1 // This mask is used to check whether one of the SHIFT meta keys is pressed.
|
KMShiftOn KeyMeta = 0x1 // This mask is used to check whether one of the SHIFT meta keys is pressed.
|
||||||
// KMShiftLeftOn KeyMeta = 0x40 // This mask is used to check whether the left SHIFT meta key is pressed.
|
KMShiftLeftOn KeyMeta = 0x40 // This mask is used to check whether the left SHIFT meta key is pressed.
|
||||||
// KMShiftRightOn KeyMeta = 0x80 // This mask is used to check whether the right SHIFT meta key is pressed.
|
KMShiftRightOn KeyMeta = 0x80 // This mask is used to check whether the right SHIFT meta key is pressed.
|
||||||
// KMSymOn KeyMeta = 0x4 // This mask is used to check whether the SYM meta key is pressed.
|
KMSymOn KeyMeta = 0x4 // This mask is used to check whether the SYM meta key is pressed.
|
||||||
// KMFunctionOn KeyMeta = 0x8 // This mask is used to check whether the FUNCTION meta key is pressed.
|
KMFunctionOn KeyMeta = 0x8 // This mask is used to check whether the FUNCTION meta key is pressed.
|
||||||
// KMCtrlOn KeyMeta = 0x1000 // This mask is used to check whether one of the CTRL meta keys is pressed.
|
KMCtrlOn KeyMeta = 0x1000 // This mask is used to check whether one of the CTRL meta keys is pressed.
|
||||||
// KMCtrlLeftOn KeyMeta = 0x2000 // This mask is used to check whether the left CTRL meta key is pressed.
|
KMCtrlLeftOn KeyMeta = 0x2000 // This mask is used to check whether the left CTRL meta key is pressed.
|
||||||
// KMCtrlRightOn KeyMeta = 0x4000 // This mask is used to check whether the right CTRL meta key is pressed.
|
KMCtrlRightOn KeyMeta = 0x4000 // This mask is used to check whether the right CTRL meta key is pressed.
|
||||||
// KMMetaOn KeyMeta = 0x10000 // This mask is used to check whether one of the META meta keys is pressed.
|
KMMetaOn KeyMeta = 0x10000 // This mask is used to check whether one of the META meta keys is pressed.
|
||||||
// KMMetaLeftOn KeyMeta = 0x20000 // This mask is used to check whether the left META meta key is pressed.
|
KMMetaLeftOn KeyMeta = 0x20000 // This mask is used to check whether the left META meta key is pressed.
|
||||||
// KMMetaRightOn KeyMeta = 0x40000 // This mask is used to check whether the right META meta key is pressed.
|
KMMetaRightOn KeyMeta = 0x40000 // This mask is used to check whether the right META meta key is pressed.
|
||||||
// KMCapsLockOn KeyMeta = 0x100000 // This mask is used to check whether the CAPS LOCK meta key is on.
|
KMCapsLockOn KeyMeta = 0x100000 // This mask is used to check whether the CAPS LOCK meta key is on.
|
||||||
// KMNumLockOn KeyMeta = 0x200000 // This mask is used to check whether the NUM LOCK meta key is on.
|
KMNumLockOn KeyMeta = 0x200000 // This mask is used to check whether the NUM LOCK meta key is on.
|
||||||
// KMScrollLockOn KeyMeta = 0x400000 // This mask is used to check whether the SCROLL LOCK meta key is on.
|
KMScrollLockOn KeyMeta = 0x400000 // This mask is used to check whether the SCROLL LOCK meta key is on.
|
||||||
// KMShiftMask = KMShiftOn | KMShiftLeftOn | KMShiftRightOn
|
KMShiftMask = KMShiftOn | KMShiftLeftOn | KMShiftRightOn
|
||||||
// KMAltMask = KMAltOn | KMAltLeftOn | KMAltRightOn
|
KMAltMask = KMAltOn | KMAltLeftOn | KMAltRightOn
|
||||||
// KMCtrlMask = KMCtrlOn | KMCtrlLeftOn | KMCtrlRightOn
|
KMCtrlMask = KMCtrlOn | KMCtrlLeftOn | KMCtrlRightOn
|
||||||
// KMMetaMask = KMMetaOn | KMMetaLeftOn | KMMetaRightOn
|
KMMetaMask = KMMetaOn | KMMetaLeftOn | KMMetaRightOn
|
||||||
)
|
)
|
||||||
|
|
||||||
type KeyFlag int
|
type KeyFlag int
|
||||||
|
|||||||
Reference in New Issue
Block a user