change: add logs

This commit is contained in:
lilong.129 2025-03-17 20:08:51 +08:00
parent 7d8efaa540
commit fb3f8a6fca
6 changed files with 66 additions and 2 deletions

View File

@ -1 +1 @@
v5.0.0-beta-2503171813 v5.0.0-beta-2503172016

View File

@ -173,6 +173,7 @@ func (ad *ADBDriver) WindowSize() (size types.Size, err error) {
// Back simulates a short press on the BACK button. // Back simulates a short press on the BACK button.
func (ad *ADBDriver) Back() (err error) { func (ad *ADBDriver) Back() (err error) {
log.Info().Msg("ADBDriver.Back")
// adb shell input keyevent 4 // adb shell input keyevent 4
_, err = ad.runShellCommand("input", "keyevent", fmt.Sprintf("%d", KCBack)) _, err = ad.runShellCommand("input", "keyevent", fmt.Sprintf("%d", KCBack))
if err != nil { if err != nil {
@ -200,10 +201,12 @@ func (ad *ADBDriver) Orientation() (orientation types.Orientation, err error) {
} }
func (ad *ADBDriver) Home() (err error) { func (ad *ADBDriver) Home() (err error) {
log.Info().Msg("ADBDriver.Home")
return ad.PressKeyCode(KCHome, KMEmpty) return ad.PressKeyCode(KCHome, KMEmpty)
} }
func (ad *ADBDriver) Unlock() (err error) { func (ad *ADBDriver) Unlock() (err error) {
log.Info().Msg("ADBDriver.Unlock")
// Notice: brighten should be executed before unlock // Notice: brighten should be executed before unlock
// brighten android device screen // brighten android device screen
if err := ad.PressKeyCode(KCWakeup, KMEmpty); err != nil { if err := ad.PressKeyCode(KCWakeup, KMEmpty); err != nil {
@ -219,6 +222,7 @@ func (ad *ADBDriver) Unlock() (err error) {
} }
func (ad *ADBDriver) Backspace(count int, opts ...option.ActionOption) (err error) { func (ad *ADBDriver) Backspace(count int, opts ...option.ActionOption) (err error) {
log.Info().Int("count", count).Msg("ADBDriver.Backspace")
if count == 0 { if count == 0 {
return nil return nil
} }
@ -263,6 +267,7 @@ func (ad *ADBDriver) PressKeyCode(keyCode KeyCode, metaState KeyMeta) (err error
} }
func (ad *ADBDriver) AppLaunch(packageName string) (err error) { func (ad *ADBDriver) AppLaunch(packageName string) (err error) {
log.Info().Str("packageName", packageName).Msg("ADBDriver.AppLaunch")
// 不指定 Activity 名称启动(启动主 Activity // 不指定 Activity 名称启动(启动主 Activity
// adb shell monkey -p <packagename> -c android.intent.category.LAUNCHER 1 // adb shell monkey -p <packagename> -c android.intent.category.LAUNCHER 1
sOutput, err := ad.runShellCommand( sOutput, err := ad.runShellCommand(
@ -280,6 +285,7 @@ func (ad *ADBDriver) AppLaunch(packageName string) (err error) {
} }
func (ad *ADBDriver) AppTerminate(packageName string) (successful bool, err error) { func (ad *ADBDriver) AppTerminate(packageName string) (successful bool, err error) {
log.Info().Str("packageName", packageName).Msg("ADBDriver.AppTerminate")
// 强制停止应用,停止 <packagename> 相关的进程 // 强制停止应用,停止 <packagename> 相关的进程
// adb shell am force-stop <packagename> // adb shell am force-stop <packagename>
_, err = ad.runShellCommand("am", "force-stop", packageName) _, err = ad.runShellCommand("am", "force-stop", packageName)
@ -291,6 +297,7 @@ func (ad *ADBDriver) AppTerminate(packageName string) (successful bool, err erro
} }
func (ad *ADBDriver) TapXY(x, y float64, opts ...option.ActionOption) error { func (ad *ADBDriver) TapXY(x, y float64, opts ...option.ActionOption) error {
log.Info().Float64("x", x).Float64("y", y).Msg("ADBDriver.TapXY")
absX, absY, err := convertToAbsolutePoint(ad, x, y) absX, absY, err := convertToAbsolutePoint(ad, x, y)
if err != nil { if err != nil {
return err return err
@ -299,6 +306,7 @@ func (ad *ADBDriver) TapXY(x, y float64, opts ...option.ActionOption) error {
} }
func (ad *ADBDriver) TapAbsXY(x, y float64, opts ...option.ActionOption) error { func (ad *ADBDriver) TapAbsXY(x, y float64, opts ...option.ActionOption) error {
log.Info().Float64("x", x).Float64("y", y).Msg("ADBDriver.TapAbsXY")
actionOptions := option.NewActionOptions(opts...) actionOptions := option.NewActionOptions(opts...)
x, y = actionOptions.ApplyTapOffset(x, y) x, y = actionOptions.ApplyTapOffset(x, y)
@ -314,6 +322,7 @@ func (ad *ADBDriver) TapAbsXY(x, y float64, opts ...option.ActionOption) error {
} }
func (ad *ADBDriver) DoubleTap(x, y float64, opts ...option.ActionOption) error { func (ad *ADBDriver) DoubleTap(x, y float64, opts ...option.ActionOption) error {
log.Info().Float64("x", x).Float64("y", y).Msg("ADBDriver.DoubleTap")
var err error var err error
x, y, err = convertToAbsolutePoint(ad, x, y) x, y, err = convertToAbsolutePoint(ad, x, y)
if err != nil { if err != nil {
@ -340,6 +349,7 @@ func (ad *ADBDriver) DoubleTap(x, y float64, opts ...option.ActionOption) error
} }
func (ad *ADBDriver) TouchAndHold(x, y float64, opts ...option.ActionOption) (err error) { func (ad *ADBDriver) TouchAndHold(x, y float64, opts ...option.ActionOption) (err error) {
log.Info().Float64("x", x).Float64("y", y).Msg("ADBDriver.TouchAndHold")
actionOptions := option.NewActionOptions(opts...) actionOptions := option.NewActionOptions(opts...)
x, y = actionOptions.ApplyTapOffset(x, y) x, y = actionOptions.ApplyTapOffset(x, y)
duration := 1000.0 duration := 1000.0
@ -360,6 +370,8 @@ func (ad *ADBDriver) TouchAndHold(x, y float64, opts ...option.ActionOption) (er
} }
func (ad *ADBDriver) Drag(fromX, fromY, toX, toY float64, opts ...option.ActionOption) (err error) { func (ad *ADBDriver) Drag(fromX, fromY, toX, toY float64, opts ...option.ActionOption) (err error) {
log.Info().Float64("fromX", fromX).Float64("fromY", fromY).
Float64("toX", toX).Float64("toY", toY).Msg("ADBDriver.Drag")
actionOptions := option.NewActionOptions(opts...) actionOptions := option.NewActionOptions(opts...)
fromX, fromY, toX, toY, err = convertToAbsoluteCoordinates(ad, fromX, fromY, toX, toY) fromX, fromY, toX, toY, err = convertToAbsoluteCoordinates(ad, fromX, fromY, toX, toY)
if err != nil { if err != nil {
@ -389,6 +401,8 @@ func (ad *ADBDriver) Drag(fromX, fromY, toX, toY float64, opts ...option.ActionO
} }
func (ad *ADBDriver) Swipe(fromX, fromY, toX, toY float64, opts ...option.ActionOption) error { func (ad *ADBDriver) Swipe(fromX, fromY, toX, toY float64, opts ...option.ActionOption) error {
log.Info().Float64("fromX", fromX).Float64("fromY", fromY).
Float64("toX", toX).Float64("toY", toY).Msg("ADBDriver.Swipe")
var err error var err error
fromX, fromY, toX, toY, err = convertToAbsoluteCoordinates(ad, fromX, fromY, toX, toY) fromX, fromY, toX, toY, err = convertToAbsoluteCoordinates(ad, fromX, fromY, toX, toY)
if err != nil { if err != nil {
@ -419,6 +433,7 @@ func (ad *ADBDriver) ForceTouchFloat(x, y, pressure float64, second ...float64)
} }
func (ad *ADBDriver) Input(text string, opts ...option.ActionOption) error { func (ad *ADBDriver) Input(text string, opts ...option.ActionOption) error {
log.Info().Str("text", text).Msg("ADBDriver.Input")
err := ad.SendUnicodeKeys(text, opts...) err := ad.SendUnicodeKeys(text, opts...)
if err == nil { if err == nil {
return nil return nil
@ -436,6 +451,7 @@ func (ad *ADBDriver) input(text string, _ ...option.ActionOption) error {
} }
func (ad *ADBDriver) SendUnicodeKeys(text string, opts ...option.ActionOption) (err error) { func (ad *ADBDriver) SendUnicodeKeys(text string, opts ...option.ActionOption) (err error) {
log.Info().Str("text", text).Msg("ADBDriver.SendUnicodeKeys")
// If the Unicode IME is not installed, fall back to the old interface. // If the Unicode IME is not installed, fall back to the old interface.
// There might be differences in the tracking schemes across different phones, and it is pending further verification. // There might be differences in the tracking schemes across different phones, and it is pending further verification.
// In release version: without the Unicode IME installed, the test cannot execute. // In release version: without the Unicode IME installed, the test cannot execute.
@ -523,6 +539,7 @@ func (ad *ADBDriver) SendKeysByAdbKeyBoard(text string) (err error) {
} }
func (ad *ADBDriver) AppClear(packageName string) error { func (ad *ADBDriver) AppClear(packageName string) error {
log.Info().Str("packageName", packageName).Msg("ADBDriver.AppClear")
if _, err := ad.runShellCommand("pm", "clear", packageName); err != nil { if _, err := ad.runShellCommand("pm", "clear", packageName); err != nil {
log.Error().Str("packageName", packageName).Err(err).Msg("failed to clear package cache") log.Error().Str("packageName", packageName).Err(err).Msg("failed to clear package cache")
return err return err
@ -552,6 +569,7 @@ func (ad *ADBDriver) ScreenShot(opts ...option.ActionOption) (raw *bytes.Buffer,
} }
func (ad *ADBDriver) TapByHierarchy(text string, opts ...option.ActionOption) error { func (ad *ADBDriver) TapByHierarchy(text string, opts ...option.ActionOption) error {
log.Info().Str("text", text).Msg("ADBDriver.TapByHierarchy")
sourceTree, err := ad.sourceTree() sourceTree, err := ad.sourceTree()
if err != nil { if err != nil {
return err return err
@ -784,6 +802,7 @@ func (ad *ADBDriver) GetIme() (ime string, err error) {
} }
func (ad *ADBDriver) ScreenRecord(opts ...option.ActionOption) (videoPath string, err error) { func (ad *ADBDriver) ScreenRecord(opts ...option.ActionOption) (videoPath string, err error) {
log.Info().Msg("ADBDriver.ScreenRecord")
options := option.NewActionOptions(opts...) options := option.NewActionOptions(opts...)
var filePath string var filePath string
@ -924,6 +943,7 @@ func (ad *ADBDriver) OpenUrl(url string) (err error) {
} }
func (ad *ADBDriver) PushImage(localPath string) error { func (ad *ADBDriver) PushImage(localPath string) error {
log.Info().Str("localPath", localPath).Msg("ADBDriver.PushImage")
remotePath := path.Join("/sdcard/DCIM/Camera/", path.Base(localPath)) remotePath := path.Join("/sdcard/DCIM/Camera/", path.Base(localPath))
if err := ad.Device.PushFile(localPath, remotePath); err != nil { if err := ad.Device.PushFile(localPath, remotePath); err != nil {
return err return err
@ -936,6 +956,7 @@ func (ad *ADBDriver) PushImage(localPath string) error {
} }
func (ad *ADBDriver) ClearImages() error { func (ad *ADBDriver) ClearImages() error {
log.Info().Msg("ADBDriver.ClearImages")
_, _ = ad.Device.RunShellCommand("rm", "-rf", "/sdcard/DCIM/Camera/*") _, _ = ad.Device.RunShellCommand("rm", "-rf", "/sdcard/DCIM/Camera/*")
return nil return nil
} }

View File

@ -215,6 +215,7 @@ func (ud *UIA2Driver) WindowSize() (size types.Size, err error) {
// Back simulates a short press on the BACK button. // Back simulates a short press on the BACK button.
func (ud *UIA2Driver) Back() (err error) { func (ud *UIA2Driver) Back() (err error) {
log.Info().Msg("UIA2Driver.Back")
// register(postHandler, new PressBack("/wd/hub/session/:sessionId/back")) // register(postHandler, new PressBack("/wd/hub/session/:sessionId/back"))
urlStr := fmt.Sprintf("/session/%s/back", ud.Session.ID) urlStr := fmt.Sprintf("/session/%s/back", ud.Session.ID)
_, err = ud.Session.POST(nil, urlStr) _, err = ud.Session.POST(nil, urlStr)
@ -253,6 +254,7 @@ func (ud *UIA2Driver) Orientation() (orientation types.Orientation, err error) {
} }
func (ud *UIA2Driver) DoubleTap(x, y float64, opts ...option.ActionOption) error { func (ud *UIA2Driver) DoubleTap(x, y float64, opts ...option.ActionOption) error {
log.Info().Float64("x", x).Float64("y", y).Msg("UIA2Driver.DoubleTap")
var err error var err error
x, y, err = convertToAbsolutePoint(ud, x, y) x, y, err = convertToAbsolutePoint(ud, x, y)
if err != nil { if err != nil {
@ -284,6 +286,7 @@ func (ud *UIA2Driver) DoubleTap(x, y float64, opts ...option.ActionOption) error
} }
func (ud *UIA2Driver) TapXY(x, y float64, opts ...option.ActionOption) error { func (ud *UIA2Driver) TapXY(x, y float64, opts ...option.ActionOption) error {
log.Info().Float64("x", x).Float64("y", y).Msg("UIA2Driver.TapXY")
// register(postHandler, new Tap("/wd/hub/session/:sessionId/appium/tap")) // register(postHandler, new Tap("/wd/hub/session/:sessionId/appium/tap"))
absX, absY, err := convertToAbsolutePoint(ud, x, y) absX, absY, err := convertToAbsolutePoint(ud, x, y)
if err != nil { if err != nil {
@ -293,6 +296,7 @@ func (ud *UIA2Driver) TapXY(x, y float64, opts ...option.ActionOption) error {
} }
func (ud *UIA2Driver) TapAbsXY(x, y float64, opts ...option.ActionOption) error { func (ud *UIA2Driver) TapAbsXY(x, y float64, opts ...option.ActionOption) error {
log.Info().Float64("x", x).Float64("y", y).Msg("UIA2Driver.TapAbsXY")
// register(postHandler, new Tap("/wd/hub/session/:sessionId/appium/tap")) // register(postHandler, new Tap("/wd/hub/session/:sessionId/appium/tap"))
actionOptions := option.NewActionOptions(opts...) actionOptions := option.NewActionOptions(opts...)
x, y = actionOptions.ApplyTapOffset(x, y) x, y = actionOptions.ApplyTapOffset(x, y)
@ -324,6 +328,7 @@ func (ud *UIA2Driver) TapAbsXY(x, y float64, opts ...option.ActionOption) error
} }
func (ud *UIA2Driver) TouchAndHold(x, y float64, opts ...option.ActionOption) (err error) { func (ud *UIA2Driver) TouchAndHold(x, y float64, opts ...option.ActionOption) (err error) {
log.Info().Float64("x", x).Float64("y", y).Msg("UIA2Driver.TouchAndHold")
actionOptions := option.NewActionOptions(opts...) actionOptions := option.NewActionOptions(opts...)
x, y = actionOptions.ApplyTapOffset(x, y) x, y = actionOptions.ApplyTapOffset(x, y)
duration := actionOptions.Duration duration := actionOptions.Duration
@ -348,6 +353,8 @@ func (ud *UIA2Driver) TouchAndHold(x, y float64, opts ...option.ActionOption) (e
// Each step execution is throttled to 5 milliseconds per step, so for a 100 // Each step execution is throttled to 5 milliseconds per step, so for a 100
// steps, the swipe will take around 0.5 seconds to complete. // steps, the swipe will take around 0.5 seconds to complete.
func (ud *UIA2Driver) Drag(fromX, fromY, toX, toY float64, opts ...option.ActionOption) error { func (ud *UIA2Driver) Drag(fromX, fromY, toX, toY float64, opts ...option.ActionOption) error {
log.Info().Float64("fromX", fromX).Float64("fromY", fromY).
Float64("toX", toX).Float64("toY", toY).Msg("UIA2Driver.Drag")
var err error var err error
fromX, fromY, toX, toY, err = convertToAbsoluteCoordinates(ud, fromX, fromY, toX, toY) fromX, fromY, toX, toY, err = convertToAbsoluteCoordinates(ud, fromX, fromY, toX, toY)
if err != nil { if err != nil {
@ -377,6 +384,8 @@ func (ud *UIA2Driver) Drag(fromX, fromY, toX, toY float64, opts ...option.Action
// `steps` is the number of move steps sent to the system // `steps` is the number of move steps sent to the system
func (ud *UIA2Driver) Swipe(fromX, fromY, toX, toY float64, opts ...option.ActionOption) error { func (ud *UIA2Driver) Swipe(fromX, fromY, toX, toY float64, opts ...option.ActionOption) error {
// register(postHandler, new Swipe("/wd/hub/session/:sessionId/touch/perform")) // register(postHandler, new Swipe("/wd/hub/session/:sessionId/touch/perform"))
log.Info().Float64("fromX", fromX).Float64("fromY", fromY).
Float64("toX", toX).Float64("toY", toY).Msg("UIA2Driver.Swipe")
var err error var err error
actionOptions := option.NewActionOptions(opts...) actionOptions := option.NewActionOptions(opts...)
fromX, fromY, toX, toY, err = convertToAbsoluteCoordinates(ud, fromX, fromY, toX, toY) fromX, fromY, toX, toY, err = convertToAbsoluteCoordinates(ud, fromX, fromY, toX, toY)
@ -412,6 +421,8 @@ func (ud *UIA2Driver) Swipe(fromX, fromY, toX, toY float64, opts ...option.Actio
} }
func (ud *UIA2Driver) SetPasteboard(contentType types.PasteboardType, content string) (err error) { func (ud *UIA2Driver) SetPasteboard(contentType types.PasteboardType, content string) (err error) {
log.Info().Str("contentType", string(contentType)).
Str("content", content).Msg("UIA2Driver.SetPasteboard")
lbl := content lbl := content
const defaultLabelLen = 10 const defaultLabelLen = 10
@ -458,6 +469,7 @@ func (ud *UIA2Driver) GetPasteboard(contentType types.PasteboardType) (raw *byte
// SendKeys Android input does not support setting frequency. // SendKeys Android input does not support setting frequency.
func (ud *UIA2Driver) Input(text string, opts ...option.ActionOption) (err error) { func (ud *UIA2Driver) Input(text string, opts ...option.ActionOption) (err error) {
log.Info().Str("text", text).Msg("UIA2Driver.Input")
// register(postHandler, new SendKeysToElement("/wd/hub/session/:sessionId/keys")) // register(postHandler, new SendKeysToElement("/wd/hub/session/:sessionId/keys"))
// https://github.com/appium/appium-uiautomator2-server/blob/master/app/src/main/java/io/appium/uiautomator2/handler/SendKeysToElement.java#L76-L85 // https://github.com/appium/appium-uiautomator2-server/blob/master/app/src/main/java/io/appium/uiautomator2/handler/SendKeysToElement.java#L76-L85
err = ud.SendUnicodeKeys(text, opts...) err = ud.SendUnicodeKeys(text, opts...)
@ -475,6 +487,7 @@ func (ud *UIA2Driver) Input(text string, opts ...option.ActionOption) (err error
} }
func (ud *UIA2Driver) SendUnicodeKeys(text string, opts ...option.ActionOption) (err error) { func (ud *UIA2Driver) SendUnicodeKeys(text string, opts ...option.ActionOption) (err error) {
log.Info().Str("text", text).Msg("UIA2Driver.SendUnicodeKeys")
// If the Unicode IME is not installed, fall back to the old interface. // If the Unicode IME is not installed, fall back to the old interface.
// There might be differences in the tracking schemes across different phones, and it is pending further verification. // There might be differences in the tracking schemes across different phones, and it is pending further verification.
// In release version: without the Unicode IME installed, the test cannot execute. // In release version: without the Unicode IME installed, the test cannot execute.
@ -505,6 +518,7 @@ func (ud *UIA2Driver) SendUnicodeKeys(text string, opts ...option.ActionOption)
} }
func (ud *UIA2Driver) SendActionKey(text string, opts ...option.ActionOption) (err error) { func (ud *UIA2Driver) SendActionKey(text string, opts ...option.ActionOption) (err error) {
log.Info().Str("text", text).Msg("UIA2Driver.SendActionKey")
var actions []interface{} var actions []interface{}
for i, c := range text { for i, c := range text {
actions = append(actions, map[string]interface{}{"type": "keyDown", "value": string(c)}, actions = append(actions, map[string]interface{}{"type": "keyDown", "value": string(c)},

View File

@ -5,6 +5,7 @@ import (
"github.com/httprunner/httprunner/v5/uixt/ai" "github.com/httprunner/httprunner/v5/uixt/ai"
"github.com/httprunner/httprunner/v5/uixt/option" "github.com/httprunner/httprunner/v5/uixt/option"
"github.com/rs/zerolog/log"
) )
func (dExt *XTDriver) TapByOCR(text string, opts ...option.ActionOption) error { func (dExt *XTDriver) TapByOCR(text string, opts ...option.ActionOption) error {
@ -27,6 +28,8 @@ func (dExt *XTDriver) TapByOCR(text string, opts ...option.ActionOption) error {
} else { } else {
point = textRect.Center() point = textRect.Center()
} }
log.Info().Str("text", text).Interface("rawTextRect", textRect).
Interface("tapPoint", point).Msg("TapByOCR success")
return dExt.TapAbsXY(point.X, point.Y, opts...) return dExt.TapAbsXY(point.X, point.Y, opts...)
} }
@ -48,6 +51,8 @@ func (dExt *XTDriver) TapByCV(opts ...option.ActionOption) error {
} else { } else {
point = uiResult.Center() point = uiResult.Center()
} }
log.Info().Interface("rawUIResult", uiResult).
Interface("tapPoint", point).Msg("TapByCV success")
return dExt.TapAbsXY(point.X, point.Y, opts...) return dExt.TapAbsXY(point.X, point.Y, opts...)
} }

View File

@ -97,6 +97,7 @@ const (
) )
func (hd *HDCDriver) Unlock() (err error) { func (hd *HDCDriver) Unlock() (err error) {
log.Info().Msg("HDCDriver.Unlock")
// Todo 检查是否锁屏 hdc shell hidumper -s RenderService -a screen // Todo 检查是否锁屏 hdc shell hidumper -s RenderService -a screen
screenInfo, err := hd.Device.RunShellCommand("hidumper", "-s", "RenderService", "-a", "screen") screenInfo, err := hd.Device.RunShellCommand("hidumper", "-s", "RenderService", "-a", "screen")
if err != nil { if err != nil {
@ -124,6 +125,7 @@ func (hd *HDCDriver) AppLaunch(packageName string) error {
} }
func (hd *HDCDriver) AppTerminate(packageName string) (bool, error) { func (hd *HDCDriver) AppTerminate(packageName string) (bool, error) {
log.Info().Str("packageName", packageName).Msg("HDCDriver.AppTerminate")
_, err := hd.Device.RunShellCommand("aa", "force-stop", packageName) _, err := hd.Device.RunShellCommand("aa", "force-stop", packageName)
if err != nil { if err != nil {
log.Error().Err(err).Msg("failed to terminal app") log.Error().Err(err).Msg("failed to terminal app")
@ -142,6 +144,7 @@ func (hd *HDCDriver) Orientation() (orientation types.Orientation, err error) {
} }
func (hd *HDCDriver) TapXY(x, y float64, opts ...option.ActionOption) error { func (hd *HDCDriver) TapXY(x, y float64, opts ...option.ActionOption) error {
log.Info().Float64("x", x).Float64("y", y).Msg("HDCDriver.TapXY")
absX, absY, err := convertToAbsolutePoint(hd, x, y) absX, absY, err := convertToAbsolutePoint(hd, x, y)
if err != nil { if err != nil {
return err return err
@ -150,6 +153,7 @@ func (hd *HDCDriver) TapXY(x, y float64, opts ...option.ActionOption) error {
} }
func (hd *HDCDriver) TapAbsXY(x, y float64, opts ...option.ActionOption) error { func (hd *HDCDriver) TapAbsXY(x, y float64, opts ...option.ActionOption) error {
log.Info().Float64("x", x).Float64("y", y).Msg("HDCDriver.TapAbsXY")
actionOptions := option.NewActionOptions(opts...) actionOptions := option.NewActionOptions(opts...)
x, y = actionOptions.ApplyTapOffset(x, y) x, y = actionOptions.ApplyTapOffset(x, y)
@ -175,6 +179,8 @@ func (hd *HDCDriver) Drag(fromX, fromY, toX, toY float64, opts ...option.ActionO
// Swipe works like Drag, but `pressForDuration` value is 0 // Swipe works like Drag, but `pressForDuration` value is 0
func (hd *HDCDriver) Swipe(fromX, fromY, toX, toY float64, opts ...option.ActionOption) error { func (hd *HDCDriver) Swipe(fromX, fromY, toX, toY float64, opts ...option.ActionOption) error {
log.Info().Float64("fromX", fromX).Float64("fromY", fromY).
Float64("toX", toX).Float64("toY", toY).Msg("HDCDriver.Swipe")
var err error var err error
actionOptions := option.NewActionOptions(opts...) actionOptions := option.NewActionOptions(opts...)
fromX, fromY, toX, toY, err = convertToAbsoluteCoordinates(hd, fromX, fromY, toX, toY) fromX, fromY, toX, toY, err = convertToAbsoluteCoordinates(hd, fromX, fromY, toX, toY)
@ -209,6 +215,7 @@ func (hd *HDCDriver) AppClear(packageName string) error {
} }
func (hd *HDCDriver) Back() error { func (hd *HDCDriver) Back() error {
log.Info().Msg("HDCDriver.Back")
return hd.uiDriver.PressBack() return hd.uiDriver.PressBack()
} }

View File

@ -108,7 +108,7 @@ func (wd *WDADriver) initMjpegClient() error {
} }
mjpegHTTPConn, err := net.Dial( mjpegHTTPConn, err := net.Dial(
"tcp", "tcp",
fmt.Sprintf("%s:%d", host, localMjpegPort), net.JoinHostPort(host, fmt.Sprintf("%d", localMjpegPort)),
) )
if err != nil { if err != nil {
return errors.Wrap(code.DeviceHTTPDriverError, err.Error()) return errors.Wrap(code.DeviceHTTPDriverError, err.Error())
@ -492,6 +492,7 @@ func (wd *WDADriver) AlertSendKeys(text string) (err error) {
} }
func (wd *WDADriver) AppLaunch(bundleId string) (err error) { func (wd *WDADriver) AppLaunch(bundleId string) (err error) {
log.Info().Str("bundleId", bundleId).Msg("WDADriver.AppLaunch")
// [[FBRoute POST:@"/wda/apps/launch"] respondWithTarget:self action:@selector(handleSessionAppLaunch:)] // [[FBRoute POST:@"/wda/apps/launch"] respondWithTarget:self action:@selector(handleSessionAppLaunch:)]
data := make(map[string]interface{}) data := make(map[string]interface{})
data["bundleId"] = bundleId data["bundleId"] = bundleId
@ -508,6 +509,7 @@ func (wd *WDADriver) AppLaunch(bundleId string) (err error) {
} }
func (wd *WDADriver) AppLaunchUnattached(bundleId string) (err error) { func (wd *WDADriver) AppLaunchUnattached(bundleId string) (err error) {
log.Info().Str("bundleId", bundleId).Msg("WDADriver.AppLaunchUnattached")
// [[FBRoute POST:@"/wda/apps/launchUnattached"].withoutSession respondWithTarget:self action:@selector(handleLaunchUnattachedApp:)] // [[FBRoute POST:@"/wda/apps/launchUnattached"].withoutSession respondWithTarget:self action:@selector(handleLaunchUnattachedApp:)]
data := map[string]interface{}{"bundleId": bundleId} data := map[string]interface{}{"bundleId": bundleId}
_, err = wd.Session.POST(data, "/wda/apps/launchUnattached") _, err = wd.Session.POST(data, "/wda/apps/launchUnattached")
@ -519,6 +521,7 @@ func (wd *WDADriver) AppLaunchUnattached(bundleId string) (err error) {
} }
func (wd *WDADriver) AppTerminate(bundleId string) (successful bool, err error) { func (wd *WDADriver) AppTerminate(bundleId string) (successful bool, err error) {
log.Info().Str("bundleId", bundleId).Msg("WDADriver.AppTerminate")
// [[FBRoute POST:@"/wda/apps/terminate"] respondWithTarget:self action:@selector(handleSessionAppTerminate:)] // [[FBRoute POST:@"/wda/apps/terminate"] respondWithTarget:self action:@selector(handleSessionAppTerminate:)]
data := map[string]interface{}{"bundleId": bundleId} data := map[string]interface{}{"bundleId": bundleId}
var rawResp DriverRawResponse var rawResp DriverRawResponse
@ -533,6 +536,7 @@ func (wd *WDADriver) AppTerminate(bundleId string) (successful bool, err error)
} }
func (wd *WDADriver) AppActivate(bundleId string) (err error) { func (wd *WDADriver) AppActivate(bundleId string) (err error) {
log.Info().Str("bundleId", bundleId).Msg("WDADriver.AppActivate")
// [[FBRoute POST:@"/wda/apps/activate"] respondWithTarget:self action:@selector(handleSessionAppActivate:)] // [[FBRoute POST:@"/wda/apps/activate"] respondWithTarget:self action:@selector(handleSessionAppActivate:)]
data := map[string]interface{}{"bundleId": bundleId} data := map[string]interface{}{"bundleId": bundleId}
urlStr := fmt.Sprintf("/session/%s/wda/apps/activate", wd.Session.ID) urlStr := fmt.Sprintf("/session/%s/wda/apps/activate", wd.Session.ID)
@ -541,6 +545,7 @@ func (wd *WDADriver) AppActivate(bundleId string) (err error) {
} }
func (wd *WDADriver) AppDeactivate(second float64) (err error) { func (wd *WDADriver) AppDeactivate(second float64) (err error) {
log.Info().Float64("second", second).Msg("WDADriver.AppDeactivate")
// [[FBRoute POST:@"/wda/deactivateApp"] respondWithTarget:self action:@selector(handleDeactivateAppCommand:)] // [[FBRoute POST:@"/wda/deactivateApp"] respondWithTarget:self action:@selector(handleDeactivateAppCommand:)]
if second < 3 { if second < 3 {
second = 3.0 second = 3.0
@ -576,6 +581,7 @@ func (wd *WDADriver) ForegroundInfo() (appInfo types.AppInfo, err error) {
} }
func (wd *WDADriver) TapXY(x, y float64, opts ...option.ActionOption) error { func (wd *WDADriver) TapXY(x, y float64, opts ...option.ActionOption) error {
log.Info().Float64("x", x).Float64("y", y).Msg("WDADriver.TapXY")
// [[FBRoute POST:@"/wda/tap/:uuid"] respondWithTarget:self action:@selector(handleTap:)] // [[FBRoute POST:@"/wda/tap/:uuid"] respondWithTarget:self action:@selector(handleTap:)]
absX, absY, err := convertToAbsolutePoint(wd, x, y) absX, absY, err := convertToAbsolutePoint(wd, x, y)
if err != nil { if err != nil {
@ -585,6 +591,7 @@ func (wd *WDADriver) TapXY(x, y float64, opts ...option.ActionOption) error {
} }
func (wd *WDADriver) TapAbsXY(x, y float64, opts ...option.ActionOption) error { func (wd *WDADriver) TapAbsXY(x, y float64, opts ...option.ActionOption) error {
log.Info().Float64("x", x).Float64("y", y).Msg("WDADriver.TapAbsXY")
// [[FBRoute POST:@"/wda/tap/:uuid"] respondWithTarget:self action:@selector(handleTap:)] // [[FBRoute POST:@"/wda/tap/:uuid"] respondWithTarget:self action:@selector(handleTap:)]
actionOptions := option.NewActionOptions(opts...) actionOptions := option.NewActionOptions(opts...)
x, y = actionOptions.ApplyTapOffset(x, y) x, y = actionOptions.ApplyTapOffset(x, y)
@ -600,6 +607,7 @@ func (wd *WDADriver) TapAbsXY(x, y float64, opts ...option.ActionOption) error {
} }
func (wd *WDADriver) DoubleTap(x, y float64, opts ...option.ActionOption) error { func (wd *WDADriver) DoubleTap(x, y float64, opts ...option.ActionOption) error {
log.Info().Float64("x", x).Float64("y", y).Msg("WDADriver.DoubleTap")
// [[FBRoute POST:@"/wda/doubleTap"] respondWithTarget:self action:@selector(handleDoubleTapCoordinate:)] // [[FBRoute POST:@"/wda/doubleTap"] respondWithTarget:self action:@selector(handleDoubleTapCoordinate:)]
var err error var err error
x, y, err = convertToAbsolutePoint(wd, x, y) x, y, err = convertToAbsolutePoint(wd, x, y)
@ -622,6 +630,7 @@ func (wd *WDADriver) DoubleTap(x, y float64, opts ...option.ActionOption) error
// FIXME: hold not work // FIXME: hold not work
func (wd *WDADriver) TouchAndHold(x, y float64, opts ...option.ActionOption) (err error) { func (wd *WDADriver) TouchAndHold(x, y float64, opts ...option.ActionOption) (err error) {
log.Info().Float64("x", x).Float64("y", y).Msg("WDADriver.TouchAndHold")
actionOptions := option.NewActionOptions(opts...) actionOptions := option.NewActionOptions(opts...)
x, y = actionOptions.ApplyTapOffset(x, y) x, y = actionOptions.ApplyTapOffset(x, y)
if actionOptions.Duration == 0 { if actionOptions.Duration == 0 {
@ -631,6 +640,8 @@ func (wd *WDADriver) TouchAndHold(x, y float64, opts ...option.ActionOption) (er
} }
func (wd *WDADriver) Drag(fromX, fromY, toX, toY float64, opts ...option.ActionOption) error { func (wd *WDADriver) Drag(fromX, fromY, toX, toY float64, opts ...option.ActionOption) error {
log.Info().Float64("fromX", fromX).Float64("fromY", fromY).
Float64("toX", toX).Float64("toY", toY).Msg("WDADriver.Drag")
// [[FBRoute POST:@"/wda/dragfromtoforduration"] respondWithTarget:self action:@selector(handleDragCoordinate:)] // [[FBRoute POST:@"/wda/dragfromtoforduration"] respondWithTarget:self action:@selector(handleDragCoordinate:)]
var err error var err error
fromX, fromY, toX, toY, err = convertToAbsoluteCoordinates(wd, fromX, fromY, toX, toY) fromX, fromY, toX, toY, err = convertToAbsoluteCoordinates(wd, fromX, fromY, toX, toY)
@ -692,6 +703,7 @@ func (wd *WDADriver) SetIme(ime string) error {
} }
func (wd *WDADriver) Input(text string, opts ...option.ActionOption) (err error) { func (wd *WDADriver) Input(text string, opts ...option.ActionOption) (err error) {
log.Info().Str("text", text).Msg("WDADriver.Input")
// [[FBRoute POST:@"/wda/keys"] respondWithTarget:self action:@selector(handleKeys:)] // [[FBRoute POST:@"/wda/keys"] respondWithTarget:self action:@selector(handleKeys:)]
data := map[string]interface{}{"value": strings.Split(text, "")} data := map[string]interface{}{"value": strings.Split(text, "")}
option.MergeOptions(data, opts...) option.MergeOptions(data, opts...)
@ -701,6 +713,7 @@ func (wd *WDADriver) Input(text string, opts ...option.ActionOption) (err error)
} }
func (wd *WDADriver) Backspace(count int, opts ...option.ActionOption) (err error) { func (wd *WDADriver) Backspace(count int, opts ...option.ActionOption) (err error) {
log.Info().Int("count", count).Msg("WDADriver.Backspace")
if count == 0 { if count == 0 {
return nil return nil
} }
@ -716,6 +729,7 @@ func (wd *WDADriver) AppClear(packageName string) error {
// Back simulates a short press on the BACK button. // Back simulates a short press on the BACK button.
func (wd *WDADriver) Back() (err error) { func (wd *WDADriver) Back() (err error) {
log.Info().Msg("WDADriver.Back")
return wd.Swipe(0, 0.5, 0.6, 0.5) return wd.Swipe(0, 0.5, 0.6, 0.5)
} }
@ -879,6 +893,7 @@ func (wd *WDADriver) triggerWDALog(data map[string]interface{}) (rawResp []byte,
} }
func (wd *WDADriver) ScreenRecord(opts ...option.ActionOption) (videoPath string, err error) { func (wd *WDADriver) ScreenRecord(opts ...option.ActionOption) (videoPath string, err error) {
log.Info().Msg("WDADriver.ScreenRecord")
timestamp := time.Now().Format("20060102_150405") + fmt.Sprintf("_%03d", time.Now().UnixNano()/1e6%1000) timestamp := time.Now().Format("20060102_150405") + fmt.Sprintf("_%03d", time.Now().UnixNano()/1e6%1000)
fileName := filepath.Join(config.GetConfig().ScreenShotsPath, fmt.Sprintf("%s.mp4", timestamp)) fileName := filepath.Join(config.GetConfig().ScreenShotsPath, fmt.Sprintf("%s.mp4", timestamp))
@ -954,6 +969,7 @@ func (wd *WDADriver) StartCaptureLog(identifier ...string) error {
} }
func (wd *WDADriver) PushImage(localPath string) error { func (wd *WDADriver) PushImage(localPath string) error {
log.Info().Str("localPath", localPath).Msg("WDADriver.PushImage")
localFile, err := os.Open(localPath) localFile, err := os.Open(localPath)
if err != nil { if err != nil {
return err return err
@ -974,6 +990,7 @@ func (wd *WDADriver) PushImage(localPath string) error {
} }
func (wd *WDADriver) ClearImages() error { func (wd *WDADriver) ClearImages() error {
log.Info().Msg("WDADriver.ClearImages")
data := map[string]interface{}{} data := map[string]interface{}{}
_, err := wd.Session.POST(data, "/gtf/albums/clear") _, err := wd.Session.POST(data, "/gtf/albums/clear")