feat: add code MobileUILaunchAppError

This commit is contained in:
lilong.129
2023-04-25 15:51:38 +08:00
parent f9a488c7e7
commit f9bebf7202
3 changed files with 16 additions and 6 deletions

View File

@@ -68,6 +68,7 @@ var (
// UI automation related: [70, 80) // UI automation related: [70, 80)
var ( var (
MobileUIDriverError = errors.New("mobile UI driver error") // 70 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 MobileUIValidationError = errors.New("mobile UI validation error") // 75
MobileUIAppNotInForegroundError = errors.New("mobile UI app not in foreground error") // 76 MobileUIAppNotInForegroundError = errors.New("mobile UI app not in foreground error") // 76
) )
@@ -125,6 +126,7 @@ var errorsMap = map[error]int{
// UI automation related // UI automation related
MobileUIDriverError: 70, MobileUIDriverError: 70,
MobileUILaunchAppError: 71,
MobileUIValidationError: 75, MobileUIValidationError: 75,
MobileUIAppNotInForegroundError: 76, MobileUIAppNotInForegroundError: 76,

View File

@@ -160,10 +160,12 @@ func (ad *adbDriver) AppLaunch(packageName string) (err error) {
"monkey", "-p", packageName, "-c", "android.intent.category.LAUNCHER", "1", "monkey", "-p", packageName, "-c", "android.intent.category.LAUNCHER", "1",
) )
if err != nil { if err != nil {
return err return errors.Wrap(code.MobileUILaunchAppError,
fmt.Sprintf("monkey launch failed: %v", err))
} }
if strings.Contains(sOutput, "monkey aborted") { 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 ad.lastLaunchedPackageName = packageName
return nil return nil

View File

@@ -308,17 +308,23 @@ func (wd *wdaDriver) AppLaunch(bundleId string) (err error) {
data := make(map[string]interface{}) data := make(map[string]interface{})
data["bundleId"] = bundleId data["bundleId"] = bundleId
_, err = wd.httpPOST(data, "/session", wd.sessionId, "/wda/apps/launch") _, err = wd.httpPOST(data, "/session", wd.sessionId, "/wda/apps/launch")
if err == nil { if err != nil {
wd.lastLaunchedPackageName = bundleId 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) { func (wd *wdaDriver) AppLaunchUnattached(bundleId string) (err error) {
// [[FBRoute POST:@"/wda/apps/launchUnattached"].withoutSession respondWithTarget:self action:@selector(handleLaunchUnattachedApp:)] // [[FBRoute POST:@"/wda/apps/launchUnattached"].withoutSession respondWithTarget:self action:@selector(handleLaunchUnattachedApp:)]
data := map[string]interface{}{"bundleId": bundleId} data := map[string]interface{}{"bundleId": bundleId}
_, err = wd.httpPOST(data, "/wda/apps/launchUnattached") _, 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) { func (wd *wdaDriver) AppTerminate(bundleId string) (successful bool, err error) {