(action MobileAction)
| 472 | } |
| 473 | |
| 474 | func (dExt *DriverExt) DoAction(action MobileAction) (err error) { |
| 475 | log.Debug(). |
| 476 | Str("method", string(action.Method)). |
| 477 | Interface("params", action.Params). |
| 478 | Msg("uixt action start") |
| 479 | actionStartTime := time.Now() |
| 480 | |
| 481 | defer func() { |
| 482 | if err != nil { |
| 483 | log.Error().Err(err). |
| 484 | Str("method", string(action.Method)). |
| 485 | Interface("params", action.Params). |
| 486 | Int64("elapsed(ms)", time.Since(actionStartTime).Milliseconds()). |
| 487 | Msg("uixt action end") |
| 488 | } else { |
| 489 | log.Debug(). |
| 490 | Str("method", string(action.Method)). |
| 491 | Interface("params", action.Params). |
| 492 | Int64("elapsed(ms)", time.Since(actionStartTime).Milliseconds()). |
| 493 | Msg("uixt action end") |
| 494 | } |
| 495 | }() |
| 496 | |
| 497 | switch action.Method { |
| 498 | case ACTION_AppInstall: |
| 499 | // TODO |
| 500 | return errActionNotImplemented |
| 501 | case ACTION_AppLaunch: |
| 502 | if bundleId, ok := action.Params.(string); ok { |
| 503 | return dExt.Driver.AppLaunch(bundleId) |
| 504 | } |
| 505 | return fmt.Errorf("invalid %s params, should be bundleId(string), got %v", |
| 506 | ACTION_AppLaunch, action.Params) |
| 507 | case ACTION_SwipeToTapApp: |
| 508 | if appName, ok := action.Params.(string); ok { |
| 509 | return dExt.swipeToTapApp(appName, action.GetOptions()...) |
| 510 | } |
| 511 | return fmt.Errorf("invalid %s params, should be app name(string), got %v", |
| 512 | ACTION_SwipeToTapApp, action.Params) |
| 513 | case ACTION_SwipeToTapText: |
| 514 | if text, ok := action.Params.(string); ok { |
| 515 | return dExt.swipeToTapTexts([]string{text}, action.GetOptions()...) |
| 516 | } |
| 517 | return fmt.Errorf("invalid %s params, should be app text(string), got %v", |
| 518 | ACTION_SwipeToTapText, action.Params) |
| 519 | case ACTION_SwipeToTapTexts: |
| 520 | if texts, ok := action.Params.([]string); ok { |
| 521 | return dExt.swipeToTapTexts(texts, action.GetOptions()...) |
| 522 | } |
| 523 | if texts, err := builtin.ConvertToStringSlice(action.Params); err == nil { |
| 524 | return dExt.swipeToTapTexts(texts, action.GetOptions()...) |
| 525 | } |
| 526 | return fmt.Errorf("invalid %s params: %v", ACTION_SwipeToTapTexts, action.Params) |
| 527 | case ACTION_AppTerminate: |
| 528 | if bundleId, ok := action.Params.(string); ok { |
| 529 | success, err := dExt.Driver.AppTerminate(bundleId) |
| 530 | if err != nil { |
| 531 | return errors.Wrap(err, "failed to terminate app") |
no test coverage detected