diff --git a/internal/version/VERSION b/internal/version/VERSION index 6ed433db..42587f98 100644 --- a/internal/version/VERSION +++ b/internal/version/VERSION @@ -1 +1 @@ -v5.0.0+2502111534 +v5.0.0+2502111543 diff --git a/pkg/uixt/driver.go b/pkg/uixt/driver.go index 626516af..53e42771 100644 --- a/pkg/uixt/driver.go +++ b/pkg/uixt/driver.go @@ -43,6 +43,7 @@ type IDriver interface { Screen() (ai.Screen, error) Scale() (float64, error) Screenshot() (*bytes.Buffer, error) + RecordScreen(folderPath string, duration time.Duration) (videoPath string, err error) Source(srcOpt ...option.SourceOption) (string, error) // actions @@ -84,7 +85,6 @@ type IDriver interface { StopCaptureLog() (result interface{}, err error) GetDriverResults() []*DriverRequests - RecordScreen(folderPath string, duration time.Duration) (videoPath string, err error) Setup() error TearDown() error diff --git a/pkg/uixt/driver_ext/shoots_ios_driver.go b/pkg/uixt/driver_ext/shoots_ios_driver.go index 463fa566..abd5c6c7 100644 --- a/pkg/uixt/driver_ext/shoots_ios_driver.go +++ b/pkg/uixt/driver_ext/shoots_ios_driver.go @@ -1,7 +1,6 @@ package driver_ext import ( - "bytes" "encoding/json" "fmt" "net/http" @@ -13,9 +12,7 @@ import ( "github.com/httprunner/httprunner/v5/code" "github.com/httprunner/httprunner/v5/internal/builtin" "github.com/httprunner/httprunner/v5/pkg/uixt" - "github.com/httprunner/httprunner/v5/pkg/uixt/ai" "github.com/httprunner/httprunner/v5/pkg/uixt/option" - "github.com/httprunner/httprunner/v5/pkg/uixt/types" ) const ( @@ -45,9 +42,18 @@ func NewShootsIOSDriver(device *uixt.IOSDevice) (driver *ShootsIOSDriver, err er fmt.Sprintf("forward tcp port failed: %v", err)) } + capabilities := option.NewCapabilities() + capabilities.WithDefaultAlertAction(option.AlertActionAccept) + wdaDriver, err := device.NewHTTPDriver(capabilities) + if err != nil { + return nil, errors.Wrap(err, "failed to init WDA driver for shoots IOS") + } + host := "localhost" timeout := 10 * time.Second - driver = &ShootsIOSDriver{} + driver = &ShootsIOSDriver{ + WDADriver: wdaDriver.(*uixt.WDADriver), + } driver.device = device driver.bightInsightPrefix = fmt.Sprintf("http://%s:%d", host, localShootsPort) driver.serverPrefix = fmt.Sprintf("http://%s:%d", host, localServerPort) @@ -65,304 +71,6 @@ type ShootsIOSDriver struct { device *uixt.IOSDevice } -func (s *ShootsIOSDriver) setUpWda() (err error) { - if s.WDADriver == nil { - capabilities := option.NewCapabilities() - capabilities.WithDefaultAlertAction(option.AlertActionAccept) - driver, err := s.device.NewHTTPDriver(capabilities) - if err != nil { - log.Error().Err(err).Msg("failed to init WDA driver for shoots IOS") - return err - } - s.WDADriver = driver.(*uixt.WDADriver) - } - return nil -} - -// InitSession starts a new session and returns the DriverSession. -func (s *ShootsIOSDriver) InitSession(capabilities option.Capabilities) error { - return s.WDADriver.InitSession(capabilities) -} - -// DeleteSession Kills application associated with that session and removes session -// 1. alertsMonitor disable -// 2. testedApplicationBundleId terminate -func (s *ShootsIOSDriver) DeleteSession() error { - err := s.setUpWda() - if err != nil { - return err - } - return s.WDADriver.DeleteSession() -} - -func (s *ShootsIOSDriver) Status() (types.DeviceStatus, error) { - err := s.setUpWda() - if err != nil { - return types.DeviceStatus{}, err - } - return s.WDADriver.Status() -} - -func (s *ShootsIOSDriver) DeviceInfo() (types.DeviceInfo, error) { - err := s.setUpWda() - if err != nil { - return types.DeviceInfo{}, err - } - return s.WDADriver.DeviceInfo() -} - -func (s *ShootsIOSDriver) BatteryInfo() (types.BatteryInfo, error) { - err := s.setUpWda() - if err != nil { - return types.BatteryInfo{}, err - } - return s.WDADriver.BatteryInfo() -} - -// WindowSize Return the width and height in portrait mode. -// when getting the window size in wda/ui2/adb, if the device is in landscape mode, -// the width and height will be reversed. -func (s *ShootsIOSDriver) WindowSize() (types.Size, error) { - err := s.setUpWda() - if err != nil { - return types.Size{}, err - } - return s.WDADriver.WindowSize() -} - -func (s *ShootsIOSDriver) Screen() (ai.Screen, error) { - err := s.setUpWda() - if err != nil { - return ai.Screen{}, err - } - return s.WDADriver.Screen() -} - -func (s *ShootsIOSDriver) Scale() (float64, error) { - err := s.setUpWda() - if err != nil { - return 0, err - } - return s.WDADriver.Scale() -} - -// Homescreen Forces the device under test to switch to the home screen -func (s *ShootsIOSDriver) Homescreen() error { - err := s.setUpWda() - if err != nil { - return err - } - return s.WDADriver.Homescreen() -} - -func (s *ShootsIOSDriver) Unlock() (err error) { - err = s.setUpWda() - if err != nil { - return err - } - return s.WDADriver.Unlock() -} - -// AppLaunch Launch an application with given bundle identifier in scope of current session. -// !This method is only available since Xcode9 SDK -func (s *ShootsIOSDriver) AppLaunch(packageName string) error { - err := s.setUpWda() - if err != nil { - return err - } - return s.WDADriver.AppLaunch(packageName) -} - -// 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 -func (s *ShootsIOSDriver) AppTerminate(packageName string) (bool, error) { - err := s.setUpWda() - if err != nil { - return false, err - } - return s.WDADriver.AppTerminate(packageName) -} - -// GetForegroundApp returns current foreground app package name and activity name -func (s *ShootsIOSDriver) GetForegroundApp() (app types.AppInfo, err error) { - err = s.setUpWda() - if err != nil { - return types.AppInfo{}, err - } - return s.WDADriver.GetForegroundApp() -} - -func (s *ShootsIOSDriver) Orientation() (orientation types.Orientation, err error) { - err = s.setUpWda() - if err != nil { - return types.OrientationPortrait, err - } - return s.WDADriver.Orientation() -} - -// TapXY Sends a tap event at the coordinate. -func (s *ShootsIOSDriver) TapXY(x, y float64, opts ...option.ActionOption) error { - err := s.setUpWda() - if err != nil { - return err - } - return s.WDADriver.TapXY(x, y, opts...) -} - -// DoubleTapXY Sends a double tap event at the coordinate. -func (s *ShootsIOSDriver) DoubleTapXY(x, y float64, opts ...option.ActionOption) error { - err := s.setUpWda() - if err != nil { - return err - } - return s.WDADriver.DoubleTapXY(x, y, opts...) -} - -// TouchAndHold Initiates a long-press gesture at the coordinate, holding for the specified duration. -// -// second: The default value is 1 -func (s *ShootsIOSDriver) TouchAndHold(x, y float64, opts ...option.ActionOption) error { - err := s.setUpWda() - if err != nil { - return err - } - return s.WDADriver.TouchAndHold(x, y, opts...) -} - -// 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). -func (s *ShootsIOSDriver) Drag(fromX, fromY, toX, toY float64, opts ...option.ActionOption) error { - err := s.setUpWda() - if err != nil { - return err - } - return s.WDADriver.Drag(fromX, fromY, toX, toY, opts...) -} - -func (s *ShootsIOSDriver) SetIme(ime string) error { - err := s.setUpWda() - if err != nil { - return err - } - return s.WDADriver.SetIme(ime) -} - -// 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 -func (s *ShootsIOSDriver) SendKeys(text string, opts ...option.ActionOption) error { - err := s.setUpWda() - if err != nil { - return err - } - return s.WDADriver.SendKeys(text, opts...) -} - -// Input works like SendKeys -func (s *ShootsIOSDriver) Input(text string, opts ...option.ActionOption) error { - err := s.setUpWda() - if err != nil { - return err - } - return s.WDADriver.Input(text, opts...) -} - -func (s *ShootsIOSDriver) AppClear(packageName string) error { - err := s.setUpWda() - if err != nil { - return err - } - return s.WDADriver.AppClear(packageName) -} - -// PressButton Presses the corresponding hardware button on the device -func (s *ShootsIOSDriver) PressButton(devBtn types.DeviceButton) error { - err := s.setUpWda() - if err != nil { - return err - } - return s.WDADriver.PressButton(devBtn) -} - -// PressBack Presses the back button -func (s *ShootsIOSDriver) PressBack(opts ...option.ActionOption) error { - err := s.setUpWda() - if err != nil { - return err - } - return s.WDADriver.PressBack(opts...) -} - -func (s *ShootsIOSDriver) PressKeyCode(keyCode uixt.KeyCode) (err error) { - err = s.setUpWda() - if err != nil { - return err - } - return s.WDADriver.PressKeyCode(keyCode) -} - -func (s *ShootsIOSDriver) Screenshot() (*bytes.Buffer, error) { - err := s.setUpWda() - if err != nil { - return nil, err - } - return s.WDADriver.Screenshot() - //screenshotService, err := instruments.NewScreenshotService(s.device.d) - //if err != nil { - // log.Error().Err(err).Msg("Starting screenshot service failed") - // return nil, err - //} - //defer screenshotService.Close() - // - //imageBytes, err := screenshotService.TakeScreenshot() - //if err != nil { - // log.Error().Err(err).Msg("failed to task screenshot") - // return nil, err - //} - //return bytes.NewBuffer(imageBytes), nil -} - -func (s *ShootsIOSDriver) TapByText(text string, opts ...option.ActionOption) error { - err := s.setUpWda() - if err != nil { - return err - } - return s.WDADriver.TapByText(text, opts...) -} - -func (s *ShootsIOSDriver) TapByTexts(actions ...uixt.TapTextAction) error { - err := s.setUpWda() - if err != nil { - return err - } - return s.WDADriver.TapByTexts(actions...) -} - -// triggers the log capture and returns the log entries -func (s *ShootsIOSDriver) StartCaptureLog(identifier ...string) (err error) { - err = s.setUpWda() - if err != nil { - return err - } - return s.WDADriver.StartCaptureLog(identifier...) -} - -func (s *ShootsIOSDriver) StopCaptureLog() (result interface{}, err error) { - err = s.setUpWda() - if err != nil { - return nil, err - } - return s.WDADriver.StopCaptureLog() -} - -func (s *ShootsIOSDriver) GetDriverResults() []*uixt.DriverRequests { - err := s.setUpWda() - if err != nil { - return nil - } - return s.WDADriver.GetDriverResults() -} - func (s *ShootsIOSDriver) Source(srcOpt ...option.SourceOption) (string, error) { resp, err := s.Session.Request(http.MethodGet, fmt.Sprintf("%s/source?format=json&onlyWeb=false", s.bightInsightPrefix), []byte{}) if err != nil { @@ -454,7 +162,3 @@ func (s *ShootsIOSDriver) getLoginAppInfo(packageName string) (info AppLoginInfo } return info, nil } - -func (s *ShootsIOSDriver) GetSession() *uixt.Session { - return s.Session -}