feat: add Init for driver

This commit is contained in:
lilong.129
2024-12-19 13:25:36 +08:00
parent 75f3853b79
commit dcd252f802
4 changed files with 21 additions and 8 deletions

View File

@@ -193,13 +193,6 @@ func (dev *AndroidDevice) Options() (deviceOptions []AndroidDeviceOption) {
func (dev *AndroidDevice) Init() error {
dev.d.RunShellCommand("ime", "enable", UnicodeImePackageName)
dev.d.RunShellCommand("rm", "-r", config.DeviceActionLogFilePath)
// Notice: brighten should be executed before unlock
// brighten android device screen
dev.d.RunShellCommand("input", "keyevent", fmt.Sprintf("%d", KCWakeup))
// unlock android device screen
dev.d.RunShellCommand("input", "keyevent", fmt.Sprintf("%d", KCMenu))
// swipe up to unlock
dev.d.RunShellCommand("input", "swipe", "540", "1000", "540", "500")
if dev.UIA2 {
// uiautomator2 server must be started before

View File

@@ -53,6 +53,17 @@ func newDriverExt(device IDevice, driver IWebDriver, options ...DriverOption) (d
return dExt, nil
}
func (dExt *DriverExt) Init() error {
// unlock device screen
err := dExt.Driver.Unlock()
if err != nil {
log.Error().Err(err).Msg("unlock device screen failed")
return err
}
return nil
}
func (dExt *DriverExt) assertOCR(text, assert string) error {
var options []ActionOption
options = append(options, WithScreenShotFileName(fmt.Sprintf("assert_ocr_%s", text)))