diff --git a/internal/version/VERSION b/internal/version/VERSION index 67a0fa02..1f9d25aa 100644 --- a/internal/version/VERSION +++ b/internal/version/VERSION @@ -1 +1 @@ -v5.0.0+2502111347 +v5.0.0+2502111501 diff --git a/pkg/uixt/android_driver_adb.go b/pkg/uixt/android_driver_adb.go index a00425dc..28529141 100644 --- a/pkg/uixt/android_driver_adb.go +++ b/pkg/uixt/android_driver_adb.go @@ -183,61 +183,6 @@ func (ad *ADBDriver) PressBack(opts ...option.ActionOption) (err error) { return nil } -func (ad *ADBDriver) StartCamera() (err error) { - if _, err = ad.runShellCommand("rm", "-r", "/sdcard/DCIM/Camera"); err != nil { - return errors.Wrap(err, "remove /sdcard/DCIM/Camera failed") - } - time.Sleep(5 * time.Second) - var version string - if version, err = ad.runShellCommand("getprop", "ro.build.version.release"); err != nil { - return err - } - if version == "11" || version == "12" { - if _, err = ad.runShellCommand("am", "start", "-a", "android.media.action.STILL_IMAGE_CAMERA"); err != nil { - return err - } - time.Sleep(5 * time.Second) - if _, err = ad.runShellCommand("input", "swipe", "750", "1000", "250", "1000"); err != nil { - return err - } - time.Sleep(5 * time.Second) - if _, err = ad.runShellCommand("input", "keyevent", fmt.Sprintf("%d", KCCamera)); err != nil { - return err - } - return - } else { - if _, err = ad.runShellCommand("am", "start", "-a", "android.media.action.VIDEO_CAPTURE"); err != nil { - return err - } - time.Sleep(5 * time.Second) - if _, err = ad.runShellCommand("input", "keyevent", fmt.Sprintf("%d", KCCamera)); err != nil { - return err - } - return - } -} - -func (ad *ADBDriver) StopCamera() (err error) { - err = ad.PressBack() - if err != nil { - return err - } - err = ad.Homescreen() - if err != nil { - return err - } - - // kill samsung shell command - if _, err = ad.AppTerminate("com.sec.android.app.camera"); err != nil { - return err - } - // kill other camera (huawei mi) - if _, err = ad.AppTerminate("com.android.camera2"); err != nil { - return err - } - return -} - func (ad *ADBDriver) Orientation() (orientation types.Orientation, err error) { output, err := ad.runShellCommand("dumpsys", "input", "|", "grep", "'SurfaceOrientation'") if err != nil { @@ -471,16 +416,6 @@ func (ad *ADBDriver) ForceTouchFloat(x, y, pressure float64, second ...float64) return } -func (ad *ADBDriver) SetPasteboard(contentType types.PasteboardType, content string) (err error) { - err = types.ErrDriverNotImplemented - return -} - -func (ad *ADBDriver) GetPasteboard(contentType types.PasteboardType) (raw *bytes.Buffer, err error) { - err = types.ErrDriverNotImplemented - return -} - func (ad *ADBDriver) SendKeys(text string, opts ...option.ActionOption) (err error) { err = ad.SendUnicodeKeys(text, opts...) if err == nil { @@ -590,7 +525,7 @@ func (ad *ADBDriver) Input(text string, opts ...option.ActionOption) (err error) return ad.SendKeys(text, opts...) } -func (ad *ADBDriver) Clear(packageName string) error { +func (ad *ADBDriver) AppClear(packageName string) error { if _, err := ad.runShellCommand("pm", "clear", packageName); err != nil { log.Error().Str("packageName", packageName).Err(err).Msg("failed to clear package cache") return err @@ -721,31 +656,6 @@ func (ad *ADBDriver) searchNodes(nodes []Layout, text string, opts ...option.Act return results } -func (ad *ADBDriver) AccessibleSource() (source string, err error) { - err = types.ErrDriverNotImplemented - return -} - -func (ad *ADBDriver) HealthCheck() (err error) { - err = types.ErrDriverNotImplemented - return -} - -func (ad *ADBDriver) GetAppiumSettings() (settings map[string]interface{}, err error) { - err = types.ErrDriverNotImplemented - return -} - -func (ad *ADBDriver) SetAppiumSettings(settings map[string]interface{}) (ret map[string]interface{}, err error) { - err = types.ErrDriverNotImplemented - return -} - -func (ad *ADBDriver) IsHealthy() (healthy bool, err error) { - err = types.ErrDriverNotImplemented - return -} - func (ad *ADBDriver) StartCaptureLog(identifier ...string) (err error) { log.Info().Msg("start adb log recording") // start logcat diff --git a/pkg/uixt/android_test.go b/pkg/uixt/android_test.go index bb62f118..c641a932 100644 --- a/pkg/uixt/android_test.go +++ b/pkg/uixt/android_test.go @@ -121,18 +121,6 @@ func TestDriver_BatteryInfo(t *testing.T) { t.Log(batteryInfo) } -func TestDriver_GetAppiumSettings(t *testing.T) { - appiumSettings, err := driver.GetAppiumSettings() - if err != nil { - t.Fatal(err) - } - - for k := range appiumSettings { - t.Logf("key: %s\tvalue: %v", k, appiumSettings[k]) - } - // t.Log(appiumSettings) -} - func TestDriver_DeviceInfo(t *testing.T) { devInfo, err := driver.DeviceInfo() if err != nil { diff --git a/pkg/uixt/driver.go b/pkg/uixt/driver.go index 7be2918b..8e2c8632 100644 --- a/pkg/uixt/driver.go +++ b/pkg/uixt/driver.go @@ -42,98 +42,43 @@ type IDriver interface { WindowSize() (types.Size, error) Screen() (ai.Screen, error) Scale() (float64, error) + Screenshot() (*bytes.Buffer, error) + Source(srcOpt ...option.SourceOption) (string, error) // actions Homescreen() error Unlock() (err error) + // tap + Tap(x, y float64, opts ...option.ActionOption) error + DoubleTap(x, y float64, opts ...option.ActionOption) error + TapByText(text string, opts ...option.ActionOption) error // TODO: remove + TapByTexts(actions ...TapTextAction) error // TODO: remove + // swipe + Drag(fromX, fromY, toX, toY float64, opts ...option.ActionOption) error + Swipe(fromX, fromY, toX, toY float64, opts ...option.ActionOption) error + TouchAndHold(x, y float64, opts ...option.ActionOption) error + // input + SendKeys(text string, opts ...option.ActionOption) error + Input(text string, opts ...option.ActionOption) error + // press key + PressButton(devBtn types.DeviceButton) error + PressBack(opts ...option.ActionOption) error + PressKeyCode(keyCode KeyCode) (err error) + Backspace(count int, opts ...option.ActionOption) (err error) - // AppLaunch Launch an application with given bundle identifier in scope of current session. - // !This method is only available since Xcode9 SDK + // app related AppLaunch(packageName string) error - // AppTerminate Terminate an application with the given package name. - // Either `true` if the app has been successfully terminated or `false` if it was not running AppTerminate(packageName string) (bool, error) - // GetForegroundApp returns current foreground app package name and activity name GetForegroundApp() (app types.AppInfo, err error) - // AssertForegroundApp returns nil if the given package and activity are in foreground AssertForegroundApp(packageName string, activityType ...string) error - - // StartCamera Starts a new camera for recording - StartCamera() error - // StopCamera Stops the camera for recording - StopCamera() error + AppClear(packageName string) error Orientation() (orientation types.Orientation, err error) - SetRotation(rotation types.Rotation) (err error) Rotation() (rotation types.Rotation, err error) - // Tap Sends a tap event at the coordinate. - Tap(x, y float64, opts ...option.ActionOption) error - - // DoubleTap Sends a double tap event at the coordinate. - DoubleTap(x, y float64, opts ...option.ActionOption) error - - // TouchAndHold Initiates a long-press gesture at the coordinate, holding for the specified duration. - // second: The default value is 1 - TouchAndHold(x, y float64, opts ...option.ActionOption) error - - // Drag Initiates a press-and-hold gesture at the coordinate, then drags to another coordinate. - // WithPressDurationOption option can be used to set pressForDuration (default to 1 second). - Drag(fromX, fromY, toX, toY float64, opts ...option.ActionOption) error - - // Swipe works like Drag, but `pressForDuration` value is 0 - Swipe(fromX, fromY, toX, toY float64, opts ...option.ActionOption) error - - // SetPasteboard Sets data to the general pasteboard - SetPasteboard(contentType types.PasteboardType, content string) error - // GetPasteboard Gets the data contained in the general pasteboard. - // It worked when `WDA` was foreground. https://github.com/appium/WebDriverAgent/issues/330 - GetPasteboard(contentType types.PasteboardType) (raw *bytes.Buffer, err error) - SetIme(ime string) error - // SendKeys Types a string into active element. There must be element with keyboard focus, - // otherwise an error is raised. - // WithFrequency option can be used to set frequency of typing (letters per sec). The default value is 60 - SendKeys(text string, opts ...option.ActionOption) error - - // Input works like SendKeys - Input(text string, opts ...option.ActionOption) error - - Clear(packageName string) error - - // PressButton Presses the corresponding hardware button on the device - PressButton(devBtn types.DeviceButton) error - - // PressBack Presses the back button - PressBack(opts ...option.ActionOption) error - - PressKeyCode(keyCode KeyCode) (err error) - - Backspace(count int, opts ...option.ActionOption) (err error) - - Screenshot() (*bytes.Buffer, error) - - // Source Return application elements tree - Source(srcOpt ...option.SourceOption) (string, error) - - TapByText(text string, opts ...option.ActionOption) error - TapByTexts(actions ...TapTextAction) error - - // AccessibleSource Return application elements accessibility tree - AccessibleSource() (string, error) - - // HealthCheck Health check might modify simulator state so it should only be called in-between testing sessions - // Checks health of XCTest by: - // 1) Querying application for some elements, - // 2) Triggering some device events. - HealthCheck() error - GetAppiumSettings() (map[string]interface{}, error) - SetAppiumSettings(settings map[string]interface{}) (map[string]interface{}, error) - - IsHealthy() (bool, error) - // triggers the log capture and returns the log entries StartCaptureLog(identifier ...string) (err error) StopCaptureLog() (result interface{}, err error) diff --git a/pkg/uixt/driver_action.go b/pkg/uixt/driver_action.go index fa9a5c13..ee646ec1 100644 --- a/pkg/uixt/driver_action.go +++ b/pkg/uixt/driver_action.go @@ -13,7 +13,6 @@ import ( "github.com/httprunner/httprunner/v5/code" "github.com/httprunner/httprunner/v5/internal/builtin" "github.com/httprunner/httprunner/v5/pkg/uixt/option" - "github.com/httprunner/httprunner/v5/pkg/uixt/types" ) type ActionMethod string @@ -31,10 +30,6 @@ const ( ACTION_Sleep ActionMethod = "sleep" ACTION_SleepMS ActionMethod = "sleep_ms" ACTION_SleepRandom ActionMethod = "sleep_random" - ACTION_StartCamera ActionMethod = "camera_start" // alias for app_launch camera - ACTION_StopCamera ActionMethod = "camera_stop" // alias for app_terminate camera - ACTION_SetClipboard ActionMethod = "set_clipboard" - ACTION_GetClipboard ActionMethod = "get_clipboard" ACTION_SetIme ActionMethod = "set_ime" ACTION_GetSource ActionMethod = "get_source" ACTION_GetForegroundApp ActionMethod = "get_foreground_app" @@ -158,7 +153,7 @@ func (dExt *XTDriver) DoAction(action MobileAction) (err error) { } case ACTION_AppClear: if packageName, ok := action.Params.(string); ok { - if err = dExt.Driver.Clear(packageName); err != nil { + if err = dExt.Driver.AppClear(packageName); err != nil { return errors.Wrap(err, "failed to clear app") } } @@ -200,15 +195,6 @@ func (dExt *XTDriver) DoAction(action MobileAction) (err error) { return nil } return fmt.Errorf("app_terminate params should be bundleId(string), got %v", action.Params) - case ACTION_SetClipboard: - if text, ok := action.Params.(string); ok { - err := dExt.Driver.SetPasteboard(types.PasteboardTypePlaintext, text) - if err != nil { - return errors.Wrap(err, "failed to set clipboard") - } - return nil - } - return fmt.Errorf("set_clioboard params should be text(string), got %v", action.Params) case ACTION_Home: return dExt.Driver.Homescreen() case ACTION_SetIme: @@ -331,10 +317,6 @@ func (dExt *XTDriver) DoAction(action MobileAction) (err error) { log.Info().Msg("take screenshot for current screen") _, err := dExt.GetScreenResult(action.GetScreenOptions()...) return err - case ACTION_StartCamera: - return dExt.Driver.StartCamera() - case ACTION_StopCamera: - return dExt.Driver.StopCamera() case ACTION_ClosePopups: return dExt.ClosePopupsHandler() case ACTION_CallFunction: diff --git a/pkg/uixt/driver_ext/shoots_ios_driver.go b/pkg/uixt/driver_ext/shoots_ios_driver.go index b1054bf5..11a1d7ae 100644 --- a/pkg/uixt/driver_ext/shoots_ios_driver.go +++ b/pkg/uixt/driver_ext/shoots_ios_driver.go @@ -192,24 +192,6 @@ func (s *ShootsIOSDriver) GetForegroundApp() (app types.AppInfo, err error) { return s.WDADriver.GetForegroundApp() } -// StartCamera Starts a new camera for recording -func (s *ShootsIOSDriver) StartCamera() error { - err := s.setUpWda() - if err != nil { - return err - } - return s.WDADriver.StartCamera() -} - -// StopCamera Stops the camera for recording -func (s *ShootsIOSDriver) StopCamera() error { - err := s.setUpWda() - if err != nil { - return err - } - return s.WDADriver.StopCamera() -} - func (s *ShootsIOSDriver) Orientation() (orientation types.Orientation, err error) { err = s.setUpWda() if err != nil { @@ -257,26 +239,6 @@ func (s *ShootsIOSDriver) Drag(fromX, fromY, toX, toY float64, opts ...option.Ac return s.WDADriver.Drag(fromX, fromY, toX, toY, opts...) } -// SetPasteboard Sets data to the general pasteboard -func (s *ShootsIOSDriver) SetPasteboard(contentType types.PasteboardType, content string) error { - err := s.setUpWda() - if err != nil { - return err - } - return s.WDADriver.SetPasteboard(contentType, content) -} - -// GetPasteboard Gets the data contained in the general pasteboard. -// -// It worked when `WDA` was foreground. https://github.com/appium/WebDriverAgent/issues/330 -func (s *ShootsIOSDriver) GetPasteboard(contentType types.PasteboardType) (raw *bytes.Buffer, err error) { - err = s.setUpWda() - if err != nil { - return nil, err - } - return s.WDADriver.GetPasteboard(contentType) -} - func (s *ShootsIOSDriver) SetIme(ime string) error { err := s.setUpWda() if err != nil { @@ -305,12 +267,12 @@ func (s *ShootsIOSDriver) Input(text string, opts ...option.ActionOption) error return s.WDADriver.Input(text, opts...) } -func (s *ShootsIOSDriver) Clear(packageName string) error { +func (s *ShootsIOSDriver) AppClear(packageName string) error { err := s.setUpWda() if err != nil { return err } - return s.WDADriver.Clear(packageName) + return s.WDADriver.AppClear(packageName) } // PressButton Presses the corresponding hardware button on the device @@ -376,52 +338,6 @@ func (s *ShootsIOSDriver) TapByTexts(actions ...uixt.TapTextAction) error { return s.WDADriver.TapByTexts(actions...) } -// AccessibleSource Return application elements accessibility tree -func (s *ShootsIOSDriver) AccessibleSource() (string, error) { - err := s.setUpWda() - if err != nil { - return "", err - } - return s.WDADriver.AccessibleSource() -} - -// HealthCheck Health check might modify simulator state so it should only be called in-between testing sessions -// -// Checks health of XCTest by: -// 1) Querying application for some elements, -// 2) Triggering some device events. -func (s *ShootsIOSDriver) HealthCheck() error { - err := s.setUpWda() - if err != nil { - return err - } - return s.WDADriver.HealthCheck() -} - -func (s *ShootsIOSDriver) GetAppiumSettings() (map[string]interface{}, error) { - err := s.setUpWda() - if err != nil { - return nil, err - } - return s.WDADriver.GetAppiumSettings() -} - -func (s *ShootsIOSDriver) SetAppiumSettings(settings map[string]interface{}) (map[string]interface{}, error) { - err := s.setUpWda() - if err != nil { - return nil, err - } - return s.WDADriver.SetAppiumSettings(settings) -} - -func (s *ShootsIOSDriver) IsHealthy() (bool, error) { - err := s.setUpWda() - if err != nil { - return false, err - } - return s.WDADriver.IsHealthy() -} - // triggers the log capture and returns the log entries func (s *ShootsIOSDriver) StartCaptureLog(identifier ...string) (err error) { err = s.setUpWda() diff --git a/pkg/uixt/harmony_driver_hdc.go b/pkg/uixt/harmony_driver_hdc.go index 70a8412f..9a6c08ef 100644 --- a/pkg/uixt/harmony_driver_hdc.go +++ b/pkg/uixt/harmony_driver_hdc.go @@ -147,14 +147,6 @@ func (hd *HDCDriver) AssertForegroundApp(packageName string, activityType ...str return nil } -func (hd *HDCDriver) StartCamera() error { - return types.ErrDriverNotImplemented -} - -func (hd *HDCDriver) StopCamera() error { - return types.ErrDriverNotImplemented -} - func (hd *HDCDriver) Orientation() (orientation types.Orientation, err error) { return types.OrientationPortrait, nil } @@ -213,14 +205,6 @@ func (hd *HDCDriver) Swipe(fromX, fromY, toX, toY float64, opts ...option.Action return hd.uiDriver.InjectGesture(ghdc.NewGesture().Start(ghdc.Point{X: int(fromX), Y: int(fromY)}).MoveTo(ghdc.Point{X: int(toX), Y: int(toY)}, duration)) } -func (hd *HDCDriver) SetPasteboard(contentType types.PasteboardType, content string) error { - return types.ErrDriverNotImplemented -} - -func (hd *HDCDriver) GetPasteboard(contentType types.PasteboardType) (raw *bytes.Buffer, err error) { - return nil, types.ErrDriverNotImplemented -} - func (hd *HDCDriver) SetIme(ime string) error { return types.ErrDriverNotImplemented } @@ -233,7 +217,7 @@ func (hd *HDCDriver) Input(text string, opts ...option.ActionOption) error { return hd.uiDriver.InputText(text) } -func (hd *HDCDriver) Clear(packageName string) error { +func (hd *HDCDriver) AppClear(packageName string) error { return types.ErrDriverNotImplemented } @@ -289,26 +273,6 @@ func (hd *HDCDriver) TapByTexts(actions ...TapTextAction) error { return types.ErrDriverNotImplemented } -func (hd *HDCDriver) AccessibleSource() (string, error) { - return "", types.ErrDriverNotImplemented -} - -func (hd *HDCDriver) HealthCheck() error { - return types.ErrDriverNotImplemented -} - -func (hd *HDCDriver) GetAppiumSettings() (map[string]interface{}, error) { - return nil, types.ErrDriverNotImplemented -} - -func (hd *HDCDriver) SetAppiumSettings(settings map[string]interface{}) (map[string]interface{}, error) { - return nil, types.ErrDriverNotImplemented -} - -func (hd *HDCDriver) IsHealthy() (bool, error) { - return false, types.ErrDriverNotImplemented -} - func (hd *HDCDriver) StartCaptureLog(identifier ...string) (err error) { return types.ErrDriverNotImplemented } diff --git a/pkg/uixt/ios_device.go b/pkg/uixt/ios_device.go index 21d7f523..dcccf4bd 100644 --- a/pkg/uixt/ios_device.go +++ b/pkg/uixt/ios_device.go @@ -203,11 +203,11 @@ func (dev *IOSDevice) getAppInfo(packageName string) (appInfo types.AppInfo, err } func (dev *IOSDevice) NewDriver() (driver IDriver, err error) { - driver, err = NewWDADriver(dev) + wdaDriver, err := NewWDADriver(dev) if err != nil { return nil, errors.Wrap(err, "failed to init WDA driver") } - settings, err := driver.SetAppiumSettings(map[string]interface{}{ + settings, err := wdaDriver.SetAppiumSettings(map[string]interface{}{ "snapshotMaxDepth": dev.Options.SnapshotMaxDepth, "acceptAlertButtonSelector": dev.Options.AcceptAlertButtonSelector, }) @@ -218,22 +218,22 @@ func (dev *IOSDevice) NewDriver() (driver IDriver, err error) { if dev.Options.ResetHomeOnStartup { log.Info().Msg("go back to home screen") - if err = driver.Homescreen(); err != nil { + if err = wdaDriver.Homescreen(); err != nil { return nil, errors.Wrap(code.MobileUIDriverError, fmt.Sprintf("go back to home screen failed: %v", err)) } } if dev.Options.LogOn { - err = driver.StartCaptureLog("hrp_wda_log") + err = wdaDriver.StartCaptureLog("hrp_wda_log") if err != nil { return nil, err } } // setup driver - if err := driver.Setup(); err != nil { + if err := wdaDriver.Setup(); err != nil { return nil, err } - return driver, nil + return wdaDriver, nil } func (dev *IOSDevice) Install(appPath string, opts ...option.InstallOption) (err error) { diff --git a/pkg/uixt/ios_driver_wda.go b/pkg/uixt/ios_driver_wda.go index 69795cca..ceaa6d95 100644 --- a/pkg/uixt/ios_driver_wda.go +++ b/pkg/uixt/ios_driver_wda.go @@ -674,7 +674,7 @@ func (wd *WDADriver) Input(text string, opts ...option.ActionOption) (err error) return wd.SendKeys(text, opts...) } -func (wd *WDADriver) Clear(packageName string) error { +func (wd *WDADriver) AppClear(packageName string) error { return types.ErrDriverNotImplemented } @@ -722,23 +722,6 @@ func (wd *WDADriver) PressButton(devBtn types.DeviceButton) (err error) { return } -func (wd *WDADriver) StartCamera() (err error) { - // start camera, alias for app_launch com.apple.camera - return wd.AppLaunch("com.apple.camera") -} - -func (wd *WDADriver) StopCamera() (err error) { - // stop camera, alias for app_terminate com.apple.camera - success, err := wd.AppTerminate("com.apple.camera") - if err != nil { - return errors.Wrap(err, "failed to terminate camera") - } - if !success { - log.Warn().Msg("camera was not running") - } - return nil -} - func (wd *WDADriver) Orientation() (orientation types.Orientation, err error) { // [[FBRoute GET:@"/orientation"] respondWithTarget:self action:@selector(handleGetOrientation:)] var rawResp DriverRawResponse @@ -859,6 +842,17 @@ func (wd *WDADriver) HealthCheck() (err error) { return } +func (wd *WDADriver) IsHealthy() (healthy bool, err error) { + var rawResp DriverRawResponse + if rawResp, err = wd.httpGET("/health"); err != nil { + return false, err + } + if string(rawResp) != "I-AM-ALIVE" { + return false, nil + } + return true, nil +} + func (wd *WDADriver) GetAppiumSettings() (settings map[string]interface{}, err error) { // [[FBRoute GET:@"/appium/settings"] respondWithTarget:self action:@selector(handleGetSettings:)] var rawResp DriverRawResponse @@ -888,17 +882,6 @@ func (wd *WDADriver) SetAppiumSettings(settings map[string]interface{}) (ret map return } -func (wd *WDADriver) IsHealthy() (healthy bool, err error) { - var rawResp DriverRawResponse - if rawResp, err = wd.httpGET("/health"); err != nil { - return false, err - } - if string(rawResp) != "I-AM-ALIVE" { - return false, nil - } - return true, nil -} - func (wd *WDADriver) WdaShutdown() (err error) { _, err = wd.httpGET("/wda/shutdown") return diff --git a/pkg/uixt/ios_test.go b/pkg/uixt/ios_test.go index d1c16b7f..1544daba 100644 --- a/pkg/uixt/ios_test.go +++ b/pkg/uixt/ios_test.go @@ -3,7 +3,6 @@ package uixt import ( - "bytes" "fmt" "testing" "time" @@ -128,7 +127,7 @@ func Test_remoteWD_DeleteSession(t *testing.T) { func Test_remoteWD_HealthCheck(t *testing.T) { setup(t) - err := driver.HealthCheck() + err := driver.(*WDADriver).HealthCheck() if err != nil { t.Fatal(err) } @@ -137,7 +136,7 @@ func Test_remoteWD_HealthCheck(t *testing.T) { func Test_remoteWD_GetAppiumSettings(t *testing.T) { setup(t) - settings, err := driver.GetAppiumSettings() + settings, err := driver.(*WDADriver).GetAppiumSettings() if err != nil { t.Fatal(err) } @@ -154,7 +153,7 @@ func Test_remoteWD_SetAppiumSettings(t *testing.T) { value := _acceptAlertButtonSelector // settings, err := driver.SetAppiumSettings(map[string]interface{}{"dismissAlertButtonSelector": "暂不"}) - settings, err := driver.SetAppiumSettings(map[string]interface{}{key: value}) + settings, err := driver.(*WDADriver).SetAppiumSettings(map[string]interface{}{key: value}) if err != nil { t.Fatal(err) } @@ -166,7 +165,7 @@ func Test_remoteWD_SetAppiumSettings(t *testing.T) { func Test_remoteWD_IsWdaHealthy(t *testing.T) { setup(t) - healthy, err := driver.IsHealthy() + healthy, err := driver.(*WDADriver).IsHealthy() if err != nil { t.Fatal(err) } @@ -315,42 +314,6 @@ func Test_Relative_Drag(t *testing.T) { } } -func Test_remoteWD_SetPasteboard(t *testing.T) { - setup(t) - - // err := driver.SetPasteboard(PasteboardTypePlaintext, "gwda") - err := driver.SetPasteboard(types.PasteboardTypeUrl, "Clock-stopwatch://") - // userHomeDir, _ := os.UserHomeDir() - // bytesImg, _ := ioutil.ReadFile(userHomeDir + "/Pictures/IMG_0806.jpg") - // err := driver.SetPasteboard(PasteboardTypeImage, string(bytesImg)) - if err != nil { - t.Fatal(err) - } -} - -func Test_remoteWD_GetPasteboard(t *testing.T) { - setup(t) - - var buffer *bytes.Buffer - var err error - - buffer, err = driver.GetPasteboard(types.PasteboardTypePlaintext) - // buffer, err = driver.GetPasteboard(PasteboardTypeUrl) - if err != nil { - t.Fatal(err) - } - t.Log(buffer.String()) - - // buffer, err = driver.GetPasteboard(PasteboardTypeImage) - // if err != nil { - // t.Fatal(err) - // } - // userHomeDir, _ := os.UserHomeDir() - // if err = ioutil.WriteFile(userHomeDir+"/Desktop/p1.png", buffer.Bytes(), 0600); err != nil { - // t.Error(err) - // } -} - func Test_remoteWD_SendKeys(t *testing.T) { setup(t) // driver.StartCaptureLog("hrp_wda_log") @@ -460,7 +423,7 @@ func TestGetForegroundApp(t *testing.T) { func Test_remoteWD_AccessibleSource(t *testing.T) { setup(t) - source, err := driver.AccessibleSource() + source, err := driver.(*WDADriver).AccessibleSource() if err != nil { t.Fatal(err) } diff --git a/runner.go b/runner.go index f62e9496..6a2e4080 100644 --- a/runner.go +++ b/runner.go @@ -236,7 +236,7 @@ func (r *HRPRunner) Run(testcases ...ITestCase) (err error) { // release UI driver session defer func() { for _, client := range caseRunner.uixtDrivers { - client.GetDriver().DeleteSession() + client.Driver.DeleteSession() } }() diff --git a/server/app.go b/server/app.go index 348ce835..45533c6d 100644 --- a/server/app.go +++ b/server/app.go @@ -42,7 +42,7 @@ func clearAppHandler(c *gin.Context) { return } - err = dExt.GetDriver().Clear(appClearReq.PackageName) + err = dExt.Driver.AppClear(appClearReq.PackageName) if err != nil { log.Err(err).Msg(fmt.Sprintf("[%s]: failed to unlick screen", c.HandlerName())) c.JSON(http.StatusInternalServerError, diff --git a/step_mobile_ui.go b/step_mobile_ui.go index 71b4e582..f3c381c2 100644 --- a/step_mobile_ui.go +++ b/step_mobile_ui.go @@ -370,24 +370,6 @@ func (s *StepMobile) ScreenShot(opts ...option.ActionOption) *StepMobile { return s } -func (s *StepMobile) StartCamera() *StepMobile { - s.obj().Actions = append(s.obj().Actions, uixt.MobileAction{ - Method: uixt.ACTION_StartCamera, - Params: nil, - Options: nil, - }) - return s -} - -func (s *StepMobile) StopCamera() *StepMobile { - s.obj().Actions = append(s.obj().Actions, uixt.MobileAction{ - Method: uixt.ACTION_StopCamera, - Params: nil, - Options: nil, - }) - return s -} - func (s *StepMobile) DisableAutoPopupHandler() *StepMobile { s.IgnorePopup = true return s diff --git a/step_mobile_ui_test.go b/step_mobile_ui_test.go index 3959735c..7591c4df 100644 --- a/step_mobile_ui_test.go +++ b/step_mobile_ui_test.go @@ -68,54 +68,6 @@ func TestIOSAppLaunch(t *testing.T) { } } -func TestIOSCameraPhotoCapture(t *testing.T) { - testCase := &TestCase{ - Config: NewConfig("ios camera photo capture"), - TestSteps: []IStep{ - NewStep("launch camera"). - IOS().Home(). - StopCamera(). - StartCamera(). - Validate(). - AssertLabelExists("PhotoCapture", "拍照按钮不存在"), - NewStep("start recording"). - IOS().Tap("PhotoCapture"), - }, - } - err := NewRunner(t).Run(testCase) - if err != nil { - t.Fatal(err) - } -} - -func TestIOSCameraVideoCapture(t *testing.T) { - testCase := &TestCase{ - Config: NewConfig("ios camera video capture"), - TestSteps: []IStep{ - NewStep("launch camera"). - IOS().Home(). - StopCamera(). - StartCamera(). - Validate(). - AssertLabelExists("PhotoCapture", "录像按钮不存在"), - NewStep("switch to video capture"). - IOS(). - SwipeRight(). - Validate(). - AssertLabelExists("VideoCapture", "拍摄按钮不存在"), - NewStep("start recording"). - IOS(). - Tap("VideoCapture"). // 开始录像 - Sleep(5). - Tap("VideoCapture"), // 停止录像 - }, - } - err := NewRunner(t).Run(testCase) - if err != nil { - t.Fatal(err) - } -} - func TestIOSDouyinAction(t *testing.T) { testCase := &TestCase{ Config: NewConfig("ios ui action on 抖音"),