diff --git a/hrp/internal/code/code.go b/hrp/internal/code/code.go index 3479c8b6..71f9226c 100644 --- a/hrp/internal/code/code.go +++ b/hrp/internal/code/code.go @@ -68,6 +68,7 @@ var ( // UI automation related: [70, 80) var ( MobileUIDriverError = errors.New("mobile UI driver error") // 70 + MobileUILaunchAppError = errors.New("mobile UI launch app error") // 71 MobileUIValidationError = errors.New("mobile UI validation error") // 75 MobileUIAppNotInForegroundError = errors.New("mobile UI app not in foreground error") // 76 ) @@ -125,6 +126,7 @@ var errorsMap = map[error]int{ // UI automation related MobileUIDriverError: 70, + MobileUILaunchAppError: 71, MobileUIValidationError: 75, MobileUIAppNotInForegroundError: 76, diff --git a/hrp/pkg/uixt/android_adb_driver.go b/hrp/pkg/uixt/android_adb_driver.go index 68f8c28b..388c444e 100644 --- a/hrp/pkg/uixt/android_adb_driver.go +++ b/hrp/pkg/uixt/android_adb_driver.go @@ -160,10 +160,12 @@ func (ad *adbDriver) AppLaunch(packageName string) (err error) { "monkey", "-p", packageName, "-c", "android.intent.category.LAUNCHER", "1", ) if err != nil { - return err + return errors.Wrap(code.MobileUILaunchAppError, + fmt.Sprintf("monkey launch failed: %v", err)) } if strings.Contains(sOutput, "monkey aborted") { - return fmt.Errorf("app launch: %s", strings.TrimSpace(sOutput)) + return errors.Wrap(code.MobileUILaunchAppError, + fmt.Sprintf("monkey aborted: %s", strings.TrimSpace(sOutput))) } ad.lastLaunchedPackageName = packageName return nil diff --git a/hrp/pkg/uixt/ios_driver.go b/hrp/pkg/uixt/ios_driver.go index 33bbe0ed..830d78cc 100644 --- a/hrp/pkg/uixt/ios_driver.go +++ b/hrp/pkg/uixt/ios_driver.go @@ -308,17 +308,23 @@ func (wd *wdaDriver) AppLaunch(bundleId string) (err error) { data := make(map[string]interface{}) data["bundleId"] = bundleId _, err = wd.httpPOST(data, "/session", wd.sessionId, "/wda/apps/launch") - if err == nil { - wd.lastLaunchedPackageName = bundleId + if err != nil { + return errors.Wrap(code.MobileUILaunchAppError, + fmt.Sprintf("wda launch failed: %v", err)) } - return + wd.lastLaunchedPackageName = bundleId + return nil } func (wd *wdaDriver) AppLaunchUnattached(bundleId string) (err error) { // [[FBRoute POST:@"/wda/apps/launchUnattached"].withoutSession respondWithTarget:self action:@selector(handleLaunchUnattachedApp:)] data := map[string]interface{}{"bundleId": bundleId} _, err = wd.httpPOST(data, "/wda/apps/launchUnattached") - return + if err != nil { + return errors.Wrap(code.MobileUILaunchAppError, + fmt.Sprintf("wda launchUnattached failed: %v", err)) + } + return nil } func (wd *wdaDriver) AppTerminate(bundleId string) (successful bool, err error) {