feat: check if app is in foreground when step failed

This commit is contained in:
lilong.129
2023-04-14 18:57:36 +08:00
parent 75997b1178
commit 2ce6ce371b
2 changed files with 11 additions and 2 deletions

View File

@@ -67,8 +67,9 @@ var (
// UI automation related: [70, 80)
var (
MobileUIDriverError = errors.New("mobile UI driver error") // 70
MobileUIValidationError = errors.New("mobile UI validation error") // 75
MobileUIDriverError = errors.New("mobile UI driver error") // 70
MobileUIValidationError = errors.New("mobile UI validation error") // 75
MobileUIAppNotInForegroundError = errors.New("mobile UI app not in foreground error") // 76
)
// OCR related: [80, 90)

View File

@@ -561,6 +561,14 @@ func runStepMobileUI(s *SessionRunner, step *TStep) (stepResult *StepResult, err
attachments := make(map[string]interface{})
if err != nil {
attachments["error"] = err.Error()
// check if app is in foreground
packageName := uiDriver.Driver.GetLastLaunchedApp()
yes, err2 := uiDriver.Driver.IsAppInForeground(packageName)
if packageName != "" && (!yes || err2 != nil) {
log.Error().Err(err2).Str("packageName", packageName).Msg("app is not in foreground")
err = errors.Wrap(code.MobileUIAppNotInForegroundError, err.Error())
}
}
// take screenshot after each step