mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-25 17:44:02 +08:00
feat: 支持打开锁屏
This commit is contained in:
2
go.mod
2
go.mod
@@ -41,7 +41,7 @@ require (
|
||||
require (
|
||||
cloud.google.com/go/compute v1.23.0 // indirect
|
||||
cloud.google.com/go/compute/metadata v0.2.3 // indirect
|
||||
code.byted.org/iesqa/ghdc v0.0.0-20240911080657-3fe04d3190a5 // indirect
|
||||
code.byted.org/iesqa/ghdc v0.0.0-20240918093157-b4feef0e5af0 // indirect
|
||||
github.com/beorn7/perks v1.0.1 // indirect
|
||||
github.com/bytedance/sonic v1.11.6 // indirect
|
||||
github.com/bytedance/sonic/loader v0.1.1 // indirect
|
||||
|
||||
6
go.sum
6
go.sum
@@ -36,6 +36,12 @@ cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RX
|
||||
cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0=
|
||||
code.byted.org/iesqa/ghdc v0.0.0-20240911080657-3fe04d3190a5 h1:9H06vi9l4K8xjhQg5Lsu4lbtB2NBKUG/l4XyRGhLuAk=
|
||||
code.byted.org/iesqa/ghdc v0.0.0-20240911080657-3fe04d3190a5/go.mod h1:0IrKgKT75jmlpi9N0Mi5xWKctJuKHFM6f+ZMQe5vnNs=
|
||||
code.byted.org/iesqa/ghdc v0.0.0-20240918062858-e57e2d72ed7b h1:pbIbB1S+vhIgEeaDoIqM5GtsCtlGXYaO7VZBYbVGYZU=
|
||||
code.byted.org/iesqa/ghdc v0.0.0-20240918062858-e57e2d72ed7b/go.mod h1:0IrKgKT75jmlpi9N0Mi5xWKctJuKHFM6f+ZMQe5vnNs=
|
||||
code.byted.org/iesqa/ghdc v0.0.0-20240918083005-02dc9c3eed10 h1:QwIVe4NaY3i3u0sN3JGczfrtAlI0FnPQSfOCfojudoc=
|
||||
code.byted.org/iesqa/ghdc v0.0.0-20240918083005-02dc9c3eed10/go.mod h1:0IrKgKT75jmlpi9N0Mi5xWKctJuKHFM6f+ZMQe5vnNs=
|
||||
code.byted.org/iesqa/ghdc v0.0.0-20240918093157-b4feef0e5af0 h1:qsKGQS3A530QpOXY80ogzzhVpf25Q4WfHusSlRyNvLU=
|
||||
code.byted.org/iesqa/ghdc v0.0.0-20240918093157-b4feef0e5af0/go.mod h1:0IrKgKT75jmlpi9N0Mi5xWKctJuKHFM6f+ZMQe5vnNs=
|
||||
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
|
||||
|
||||
@@ -4,8 +4,6 @@ import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"os"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"code.byted.org/iesqa/ghdc"
|
||||
@@ -59,32 +57,13 @@ func (hd *hdcDriver) BatteryInfo() (BatteryInfo, error) {
|
||||
}
|
||||
|
||||
func (hd *hdcDriver) WindowSize() (size Size, err error) {
|
||||
res, err := hd.device.RunShellCommand("hidumper", "-s", "RenderService", "-a", "screen")
|
||||
display, err := hd.uiDriver.GetDisplaySize()
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("failed to get window size")
|
||||
return size, err
|
||||
return Size{}, err
|
||||
}
|
||||
re := regexp.MustCompile(`activeMode:\s*(\d+)x(\d+)`)
|
||||
matches := re.FindStringSubmatch(res)
|
||||
|
||||
if len(matches) > 2 {
|
||||
fmt.Printf("Width: %s, Height: %s\n", matches[1], matches[2])
|
||||
width, err := strconv.Atoi(matches[1])
|
||||
if err != nil {
|
||||
log.Error().Err(err).Str("width", matches[1]).Msg("failed to get window size")
|
||||
return size, err
|
||||
}
|
||||
size.Width = width
|
||||
height, err := strconv.Atoi(matches[2])
|
||||
if err != nil {
|
||||
log.Error().Err(err).Str("height", matches[2]).Msg("failed to get window size")
|
||||
return size, err
|
||||
}
|
||||
size.Height = height
|
||||
return size, nil
|
||||
}
|
||||
err = fmt.Errorf("failed to find window size in dump result")
|
||||
log.Error().Err(err).Str("result", res).Msg("failed to get window size")
|
||||
size.Width = display.Width
|
||||
size.Height = display.Height
|
||||
return size, err
|
||||
}
|
||||
|
||||
@@ -105,7 +84,12 @@ func (hd *hdcDriver) Homescreen() error {
|
||||
}
|
||||
|
||||
func (hd *hdcDriver) Unlock() (err error) {
|
||||
return hd.uiDriver.PressKey(ghdc.KEYCODE_HOME)
|
||||
// Todo 检查是否锁屏 hdc shell hidumper -s RenderService -a screen
|
||||
err = hd.uiDriver.PressPowerKey()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return hd.Swipe(500, 2000, 500, 500)
|
||||
}
|
||||
|
||||
func (hd *hdcDriver) AppLaunch(packageName string) error {
|
||||
@@ -114,8 +98,12 @@ func (hd *hdcDriver) AppLaunch(packageName string) error {
|
||||
}
|
||||
|
||||
func (hd *hdcDriver) AppTerminate(packageName string) (bool, error) {
|
||||
// Todo
|
||||
return false, errDriverNotImplemented
|
||||
_, err := hd.device.RunShellCommand("aa", "force-stop", packageName)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("failed to terminal app")
|
||||
return false, err
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (hd *hdcDriver) GetForegroundApp() (app AppInfo, err error) {
|
||||
@@ -155,7 +143,7 @@ func (hd *hdcDriver) TapFloat(x, y float64, options ...ActionOption) error {
|
||||
x += actionOptions.getRandomOffset()
|
||||
y += actionOptions.getRandomOffset()
|
||||
|
||||
return hd.uiDriver.Touch(int(x), int(y))
|
||||
return hd.uiDriver.InjectGesture(ghdc.NewGesture().Start(ghdc.Point{X: int(x), Y: int(y)}).Pause(100))
|
||||
}
|
||||
|
||||
func (hd *hdcDriver) DoubleTap(x, y int, options ...ActionOption) error {
|
||||
@@ -200,12 +188,12 @@ func (hd *hdcDriver) SwipeFloat(fromX, fromY, toX, toY float64, options ...Actio
|
||||
toX += actionOptions.getRandomOffset()
|
||||
toY += actionOptions.getRandomOffset()
|
||||
|
||||
duration := 0.2
|
||||
duration := 200
|
||||
if actionOptions.PressDuration > 0 {
|
||||
duration = actionOptions.PressDuration
|
||||
duration = int(actionOptions.PressDuration * 1000)
|
||||
}
|
||||
|
||||
return hd.uiDriver.Drag(int(fromX), int(fromY), int(toX), int(toY), duration)
|
||||
return hd.uiDriver.InjectGesture(ghdc.NewGesture().Start(ghdc.Point{X: int(fromX), Y: int(fromY)}).MoveTo(ghdc.Point{X: int(toX), Y: int(toY)}, duration))
|
||||
}
|
||||
|
||||
func (hd *hdcDriver) SetPasteboard(contentType PasteboardType, content string) error {
|
||||
|
||||
@@ -34,7 +34,7 @@ func TestWindowSize(t *testing.T) {
|
||||
t.Log(fmt.Sprintf("width: %d, height: %d", size.Width, size.Height))
|
||||
}
|
||||
|
||||
func TestTap(t *testing.T) {
|
||||
func TestHarmonyTap(t *testing.T) {
|
||||
setup(t)
|
||||
err := harmonyDriverExt.TapAbsXY(200, 2000)
|
||||
if err != nil {
|
||||
@@ -52,7 +52,7 @@ func TestSwipe(t *testing.T) {
|
||||
|
||||
func TestInput(t *testing.T) {
|
||||
setup(t)
|
||||
err := harmonyDriverExt.Input("test测试123!@#")
|
||||
err := harmonyDriverExt.Input("test")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user