diff --git a/hrp/pkg/uixt/android_adb_driver.go b/hrp/pkg/uixt/android_adb_driver.go index 0ac9b3b2..6b057be3 100644 --- a/hrp/pkg/uixt/android_adb_driver.go +++ b/hrp/pkg/uixt/android_adb_driver.go @@ -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 diff --git a/hrp/pkg/uixt/interface.go b/hrp/pkg/uixt/interface.go index d19ea31b..edb1f266 100644 --- a/hrp/pkg/uixt/interface.go +++ b/hrp/pkg/uixt/interface.go @@ -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 diff --git a/hrp/pkg/uixt/ios_driver.go b/hrp/pkg/uixt/ios_driver.go index 004e7a62..e83331ae 100644 --- a/hrp/pkg/uixt/ios_driver.go +++ b/hrp/pkg/uixt/ios_driver.go @@ -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 {