feat: get android device timestamp

This commit is contained in:
lilong.129
2023-06-05 00:43:36 +08:00
parent ef7f8def53
commit b81903ab5e
3 changed files with 22 additions and 0 deletions

View File

@@ -92,6 +92,21 @@ func (ad *adbDriver) Scale() (scale float64, err error) {
return 1, nil
}
func (ad *adbDriver) GetTimestamp() (timestamp int64, err error) {
// adb shell date +%s
output, err := ad.adbClient.RunShellCommand("date", "+%s")
if err != nil {
return 0, errors.Wrap(err, "failed to get timestamp by adb")
}
timestamp, err = strconv.ParseInt(strings.TrimSpace(output), 10, 64)
if err != nil {
return 0, errors.Wrap(err, "convert timestamp failed")
}
return timestamp, nil
}
// PressBack simulates a short press on the BACK button.
func (ad *adbDriver) PressBack(options ...ActionOption) (err error) {
// adb shell input keyevent 4

View File

@@ -477,6 +477,9 @@ type WebDriver interface {
Screen() (Screen, error)
Scale() (float64, error)
// GetTimestamp returns the timestamp of the mobile device
GetTimestamp() (timestamp int64, err error)
// Homescreen Forces the device under test to switch to the home screen
Homescreen() error

View File

@@ -161,6 +161,10 @@ func (wd *wdaDriver) Screen() (screen Screen, err error) {
return
}
func (wd *wdaDriver) GetTimestamp() (timestamp int64, err error) {
return 0, errDriverNotImplemented
}
func (wd *wdaDriver) Scale() (float64, error) {
screen, err := wd.Screen()
if err != nil {