mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-13 04:20:31 +08:00
feat: get android device timestamp
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user