mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-07 16:40:50 +08:00
fix: ignore error when get foreground app failed
This commit is contained in:
@@ -74,7 +74,8 @@ var (
|
|||||||
MobileUILaunchAppError = errors.New("mobile UI launch app error") // 71
|
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
|
||||||
MobileUIPopupError = errors.New("mobile UI popup error") // 77
|
MobileUIActivityNotMatchError = errors.New("mobile UI activity not match error") // 77
|
||||||
|
MobileUIPopupError = errors.New("mobile UI popup error") // 78
|
||||||
)
|
)
|
||||||
|
|
||||||
// OCR related: [80, 90)
|
// OCR related: [80, 90)
|
||||||
@@ -136,7 +137,8 @@ var errorsMap = map[error]int{
|
|||||||
MobileUILaunchAppError: 71,
|
MobileUILaunchAppError: 71,
|
||||||
MobileUIValidationError: 75,
|
MobileUIValidationError: 75,
|
||||||
MobileUIAppNotInForegroundError: 76,
|
MobileUIAppNotInForegroundError: 76,
|
||||||
MobileUIPopupError: 77,
|
MobileUIActivityNotMatchError: 77,
|
||||||
|
MobileUIPopupError: 78,
|
||||||
|
|
||||||
// OCR related
|
// OCR related
|
||||||
OCREnvMissedError: 80,
|
OCREnvMissedError: 80,
|
||||||
|
|||||||
+4
-2
@@ -214,9 +214,11 @@ func (dExt *DriverExt) GetStepCacheData() map[string]interface{} {
|
|||||||
for imagePath, screenResult := range dExt.cacheStepData.screenResults {
|
for imagePath, screenResult := range dExt.cacheStepData.screenResults {
|
||||||
o, _ := json.Marshal(screenResult.Texts)
|
o, _ := json.Marshal(screenResult.Texts)
|
||||||
data := map[string]interface{}{
|
data := map[string]interface{}{
|
||||||
"tags": screenResult.Tags,
|
"tags": screenResult.Tags,
|
||||||
"texts": string(o),
|
"texts": string(o),
|
||||||
|
"popularity": screenResult.Popularity,
|
||||||
}
|
}
|
||||||
|
|
||||||
screenResults[imagePath] = data
|
screenResults[imagePath] = data
|
||||||
}
|
}
|
||||||
cacheData["screen_results"] = screenResults
|
cacheData["screen_results"] = screenResults
|
||||||
|
|||||||
@@ -260,10 +260,14 @@ func (l *LiveCrawler) Run(driver *DriverExt, enterPoint PointF) error {
|
|||||||
imageResult, err := l.driver.GetScreenResult()
|
imageResult, err := l.driver.GetScreenResult()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("OCR GetTexts failed")
|
log.Error().Err(err).Msg("OCR GetTexts failed")
|
||||||
|
time.Sleep(3 * time.Second)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
screenResult := l.driver.cacheStepData.screenResults[imageResult.imagePath]
|
screenResult := l.driver.cacheStepData.screenResults[imageResult.imagePath]
|
||||||
screenResult.Tags = []string{"live"}
|
screenResult.Tags = []string{"live"}
|
||||||
|
if imageResult.LiveType != "" {
|
||||||
|
screenResult.Tags = append(screenResult.Tags, imageResult.LiveType)
|
||||||
|
}
|
||||||
|
|
||||||
// check live type and incr live count
|
// check live type and incr live count
|
||||||
if err := l.currentStat.incrLive(screenResult, l.driver); err != nil {
|
if err := l.currentStat.incrLive(screenResult, l.driver); err != nil {
|
||||||
@@ -368,6 +372,7 @@ func (dExt *DriverExt) VideoCrawler(configs *VideoCrawlerConfigs) (err error) {
|
|||||||
imageResult, err := dExt.GetScreenResult()
|
imageResult, err := dExt.GetScreenResult()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("OCR GetTexts failed")
|
log.Error().Err(err).Msg("OCR GetTexts failed")
|
||||||
|
time.Sleep(3 * time.Second)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
screenResult := dExt.cacheStepData.screenResults[imageResult.imagePath]
|
screenResult := dExt.cacheStepData.screenResults[imageResult.imagePath]
|
||||||
@@ -433,26 +438,29 @@ func (dExt *DriverExt) assertActivity(packageName, activityType string) error {
|
|||||||
Str("activity_type", activityType).Msg("assert activity")
|
Str("activity_type", activityType).Msg("assert activity")
|
||||||
app, err := dExt.Driver.GetForegroundApp()
|
app, err := dExt.Driver.GetForegroundApp()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("get foreground app failed")
|
log.Warn().Err(err).Msg("get foreground app failed, skip app/activity assertion")
|
||||||
return err
|
return nil // Notice: ignore error when get foreground app failed
|
||||||
}
|
}
|
||||||
|
|
||||||
if app.PackageName != packageName {
|
if app.PackageName != packageName {
|
||||||
return errors.Wrap(code.MobileUIAppNotInForegroundError,
|
return errors.Wrap(code.MobileUIAppNotInForegroundError,
|
||||||
fmt.Sprintf("app %s is not in foreground", packageName))
|
fmt.Sprintf("foreground app %s, expect %s", app.PackageName, packageName))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var expectActivity string
|
||||||
if activities, ok := androidActivities[app.PackageName]; ok {
|
if activities, ok := androidActivities[app.PackageName]; ok {
|
||||||
if activity, ok := activities[activityType]; ok {
|
if activity, ok := activities[activityType]; ok {
|
||||||
if strings.HasSuffix(app.Activity, activity) {
|
if strings.HasSuffix(app.Activity, activity) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
expectActivity = activity
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Error().Interface("app", app.AppBaseInfo).Msg("app activity not match")
|
log.Error().Interface("app", app.AppBaseInfo).Msg("app activity not match")
|
||||||
return errors.Wrap(code.MobileUIAppNotInForegroundError,
|
return errors.Wrap(code.MobileUIActivityNotMatchError,
|
||||||
fmt.Sprintf("%s activity is not in foreground", activityType))
|
fmt.Sprintf("foreground activity %s, expect %s %s",
|
||||||
|
app.Activity, activityType, expectActivity))
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: add more popup texts
|
// TODO: add more popup texts
|
||||||
|
|||||||
Reference in New Issue
Block a user