diff --git a/internal/version/VERSION b/internal/version/VERSION index 42587f98..c954c36b 100644 --- a/internal/version/VERSION +++ b/internal/version/VERSION @@ -1 +1 @@ -v5.0.0+2502111543 +v5.0.0+2502111557 diff --git a/pkg/uixt/android_driver_adb.go b/pkg/uixt/android_driver_adb.go index b6bcec9d..7eb59b08 100644 --- a/pkg/uixt/android_driver_adb.go +++ b/pkg/uixt/android_driver_adb.go @@ -23,7 +23,6 @@ import ( "github.com/httprunner/httprunner/v5/code" "github.com/httprunner/httprunner/v5/internal/config" "github.com/httprunner/httprunner/v5/internal/utf7" - "github.com/httprunner/httprunner/v5/pkg/uixt/ai" "github.com/httprunner/httprunner/v5/pkg/uixt/option" "github.com/httprunner/httprunner/v5/pkg/uixt/types" ) @@ -164,11 +163,6 @@ func (ad *ADBDriver) WindowSize() (size types.Size, err error) { return size, nil } -func (ad *ADBDriver) Screen() (screen ai.Screen, err error) { - err = types.ErrDriverNotImplemented - return -} - func (ad *ADBDriver) Scale() (scale float64, err error) { return 1, nil } @@ -549,7 +543,7 @@ func (ad *ADBDriver) SetRotation(rotation types.Rotation) (err error) { return } -func (ad *ADBDriver) Screenshot() (raw *bytes.Buffer, err error) { +func (ad *ADBDriver) ScreenShot() (raw *bytes.Buffer, err error) { resp, err := ad.runShellCommand("screencap", "-p") if err != nil { return nil, errors.Wrap(err, "adb screencap failed") @@ -735,10 +729,6 @@ func (ad *ADBDriver) GetSession() *Session { return ad.Session } -func (ad *ADBDriver) GetDriverResults() []*DriverRequests { - return nil -} - func (ad *ADBDriver) GetForegroundApp() (app types.AppInfo, err error) { packageInfo, err := ad.runShellCommand( "CLASSPATH=/data/local/tmp/evalite", "app_process", "/", @@ -905,7 +895,7 @@ var androidActivities = map[string]map[string][]string{ // TODO: SPH, XHS } -func (ad *ADBDriver) RecordScreen(folderPath string, duration time.Duration) (videoPath string, err error) { +func (ad *ADBDriver) ScreenRecord(folderPath string, duration time.Duration) (videoPath string, err error) { // 获取当前时间戳 timestamp := time.Now().Format("20060102_150405") + fmt.Sprintf("_%03d", time.Now().UnixNano()/1e6%1000) // 创建文件名 diff --git a/pkg/uixt/android_driver_uia2.go b/pkg/uixt/android_driver_uia2.go index 2c00f94b..27a39fee 100644 --- a/pkg/uixt/android_driver_uia2.go +++ b/pkg/uixt/android_driver_uia2.go @@ -543,10 +543,10 @@ func (ud *UIA2Driver) Rotation() (rotation types.Rotation, err error) { return } -func (ud *UIA2Driver) Screenshot() (raw *bytes.Buffer, err error) { +func (ud *UIA2Driver) ScreenShot() (raw *bytes.Buffer, err error) { // https://bytedance.larkoffice.com/docx/C8qEdmSHnoRvMaxZauocMiYpnLh // ui2截图受内存影响,改为adb截图 - return ud.ADBDriver.Screenshot() + return ud.ADBDriver.ScreenShot() } func (ud *UIA2Driver) Source(srcOpt ...option.SourceOption) (source string, err error) { diff --git a/pkg/uixt/android_test.go b/pkg/uixt/android_test.go index 376d9a2d..5fc732d8 100644 --- a/pkg/uixt/android_test.go +++ b/pkg/uixt/android_test.go @@ -68,7 +68,7 @@ func TestDriver_Status(t *testing.T) { } func TestDriver_Screenshot(t *testing.T) { - screenshot, err := driver.Screenshot() + screenshot, err := driver.ScreenShot() if err != nil { t.Fatal(err) } @@ -250,7 +250,7 @@ func TestDriver_AppLaunch(t *testing.T) { t.Fatal(err) } - raw, err := driver.Screenshot() + raw, err := driver.ScreenShot() if err != nil { t.Fatal(err) } @@ -303,14 +303,14 @@ func TestDriver_KeepAlive(t *testing.T) { t.Fatal(err) } - _, err = driver.Screenshot() + _, err = driver.ScreenShot() if err != nil { t.Fatal(err) } time.Sleep(60 * time.Second) - _, err = driver.Screenshot() + _, err = driver.ScreenShot() if err != nil { t.Fatal(err) } @@ -350,7 +350,7 @@ func TestDriver_ShellInputUnicode(t *testing.T) { t.Fatal(err) } - raw, err := driver.Screenshot() + raw, err := driver.ScreenShot() if err != nil { t.Fatal(err) } @@ -393,7 +393,7 @@ func TestTapTexts(t *testing.T) { func TestRecordVideo(t *testing.T) { setupAndroidAdbDriver(t) - path, err := driverExt.RecordScreen("", 5*time.Second) + path, err := driverExt.ScreenRecord("", 5*time.Second) if err != nil { t.Fatal(err) } diff --git a/pkg/uixt/driver.go b/pkg/uixt/driver.go index 53e42771..c4763b7b 100644 --- a/pkg/uixt/driver.go +++ b/pkg/uixt/driver.go @@ -29,21 +29,22 @@ var ( // current implemeted driver: ADBDriver, UIA2Driver, WDADriver, HDCDriver type IDriver interface { GetDevice() IDevice + Setup() error + TearDown() error // session InitSession(capabilities option.Capabilities) error - DeleteSession() error GetSession() *Session + DeleteSession() error // device info and status Status() (types.DeviceStatus, error) DeviceInfo() (types.DeviceInfo, error) BatteryInfo() (types.BatteryInfo, error) WindowSize() (types.Size, error) - Screen() (ai.Screen, error) Scale() (float64, error) - Screenshot() (*bytes.Buffer, error) - RecordScreen(folderPath string, duration time.Duration) (videoPath string, err error) + ScreenShot() (*bytes.Buffer, error) + ScreenRecord(folderPath string, duration time.Duration) (videoPath string, err error) Source(srcOpt ...option.SourceOption) (string, error) // actions @@ -70,9 +71,9 @@ type IDriver interface { // app related AppLaunch(packageName string) error AppTerminate(packageName string) (bool, error) - GetForegroundApp() (app types.AppInfo, err error) - AssertForegroundApp(packageName string, activityType ...string) error AppClear(packageName string) error + GetForegroundApp() (app types.AppInfo, err error) + AssertForegroundApp(packageName string, activityType ...string) error // TODO: remove Orientation() (orientation types.Orientation, err error) SetRotation(rotation types.Rotation) (err error) @@ -83,11 +84,6 @@ type IDriver interface { // triggers the log capture and returns the log entries StartCaptureLog(identifier ...string) (err error) StopCaptureLog() (result interface{}, err error) - - GetDriverResults() []*DriverRequests - - Setup() error - TearDown() error } func NewXTDriver(driver IDriver, opts ...ai.AIServiceOption) *XTDriver { diff --git a/pkg/uixt/driver_ext/shoots_android_driver_test.go b/pkg/uixt/driver_ext/shoots_android_driver_test.go index 42ea77d5..44c68f1f 100644 --- a/pkg/uixt/driver_ext/shoots_android_driver_test.go +++ b/pkg/uixt/driver_ext/shoots_android_driver_test.go @@ -106,7 +106,7 @@ func TestInput(t *testing.T) { func TestSave(t *testing.T) { setupShootsAndroidDriver(t) - raw, err := shootsAndroidDriver.Screenshot() + raw, err := shootsAndroidDriver.ScreenShot() if err != nil { t.Fatal(err) } diff --git a/pkg/uixt/driver_ext/shoots_ios_driver_test.go b/pkg/uixt/driver_ext/shoots_ios_driver_test.go index 5905c6e8..55b55704 100644 --- a/pkg/uixt/driver_ext/shoots_ios_driver_test.go +++ b/pkg/uixt/driver_ext/shoots_ios_driver_test.go @@ -66,7 +66,7 @@ func TestIOSSwipe(t *testing.T) { func TestIOSSave(t *testing.T) { setupShootsIOSDriver(t) - raw, err := shootsIOSDriver.Screenshot() + raw, err := shootsIOSDriver.ScreenShot() if err != nil { t.Fatal(err) } diff --git a/pkg/uixt/driver_screenshot.go b/pkg/uixt/driver_screenshot.go index bcce10c0..b4860e79 100644 --- a/pkg/uixt/driver_screenshot.go +++ b/pkg/uixt/driver_screenshot.go @@ -200,7 +200,7 @@ func (dExt *XTDriver) FindUIResult(opts ...option.ActionOption) (point ai.PointF // GetScreenShot takes screenshot and saves image file to $CWD/screenshots/ folder func (dExt *XTDriver) GetScreenShot(fileName string) (raw *bytes.Buffer, path string, err error) { - if raw, err = dExt.Screenshot(); err != nil { + if raw, err = dExt.ScreenShot(); err != nil { log.Error().Err(err).Msg("capture screenshot data failed") return nil, "", errors.Wrap(code.DeviceScreenShotError, err.Error()) } diff --git a/pkg/uixt/harmony_driver_hdc.go b/pkg/uixt/harmony_driver_hdc.go index 23dfd334..3d46ef3d 100644 --- a/pkg/uixt/harmony_driver_hdc.go +++ b/pkg/uixt/harmony_driver_hdc.go @@ -10,7 +10,6 @@ import ( "code.byted.org/iesqa/ghdc" "github.com/rs/zerolog/log" - "github.com/httprunner/httprunner/v5/pkg/uixt/ai" "github.com/httprunner/httprunner/v5/pkg/uixt/option" "github.com/httprunner/httprunner/v5/pkg/uixt/types" ) @@ -81,10 +80,6 @@ func (hd *HDCDriver) WindowSize() (size types.Size, err error) { return size, err } -func (hd *HDCDriver) Screen() (ai.Screen, error) { - return ai.Screen{}, types.ErrDriverNotImplemented -} - func (hd *HDCDriver) Scale() (float64, error) { return 1, nil } @@ -241,7 +236,7 @@ func (hd *HDCDriver) PressHarmonyKeyCode(keyCode ghdc.KeyCode) (err error) { return hd.uiDriver.PressKey(keyCode) } -func (hd *HDCDriver) Screenshot() (*bytes.Buffer, error) { +func (hd *HDCDriver) ScreenShot() (*bytes.Buffer, error) { tempDir := os.TempDir() screenshotPath := fmt.Sprintf("%s/screenshot_%d.png", tempDir, time.Now().Unix()) err := hd.uiDriver.Screenshot(screenshotPath) @@ -282,11 +277,7 @@ func (hd *HDCDriver) StopCaptureLog() (result interface{}, err error) { return hd.points, nil } -func (hd *HDCDriver) GetDriverResults() []*DriverRequests { - return nil -} - -func (hd *HDCDriver) RecordScreen(folderPath string, duration time.Duration) (videoPath string, err error) { +func (hd *HDCDriver) ScreenRecord(folderPath string, duration time.Duration) (videoPath string, err error) { return "", nil } diff --git a/pkg/uixt/harmony_test.go b/pkg/uixt/harmony_test.go index 3283b44d..1f316bfc 100644 --- a/pkg/uixt/harmony_test.go +++ b/pkg/uixt/harmony_test.go @@ -86,7 +86,7 @@ func TestPressBack(t *testing.T) { func TestScreenshot(t *testing.T) { setupHarmonyDevice(t) - screenshot, err := driver.Screenshot() + screenshot, err := driver.ScreenShot() if err != nil { t.Fatal(err) } diff --git a/pkg/uixt/ios_driver_wda.go b/pkg/uixt/ios_driver_wda.go index 02641948..1475f377 100644 --- a/pkg/uixt/ios_driver_wda.go +++ b/pkg/uixt/ios_driver_wda.go @@ -267,6 +267,22 @@ func (wd *WDADriver) Screen() (screen ai.Screen, err error) { return } +func (wd *WDADriver) ScreenShot() (raw *bytes.Buffer, err error) { + // [[FBRoute GET:@"/screenshot"] respondWithTarget:self action:@selector(handleGetScreenshot:)] + // [[FBRoute GET:@"/screenshot"].withoutSession respondWithTarget:self action:@selector(handleGetScreenshot:)] + var rawResp DriverRawResponse + if rawResp, err = wd.httpGET("/session", wd.Session.ID, "/screenshot"); err != nil { + return nil, errors.Wrap(code.DeviceScreenShotError, + fmt.Sprintf("get WDA screenshot data failed: %v", err)) + } + + if raw, err = rawResp.ValueDecodeAsBase64(); err != nil { + return nil, errors.Wrap(code.DeviceScreenShotError, + fmt.Sprintf("decode WDA screenshot data failed: %v", err)) + } + return +} + func (wd *WDADriver) Scale() (float64, error) { if !builtin.IsZeroFloat64(wd.Session.scale) { return wd.Session.scale, nil @@ -763,22 +779,6 @@ func (wd *WDADriver) SetRotation(rotation types.Rotation) (err error) { return } -func (wd *WDADriver) Screenshot() (raw *bytes.Buffer, err error) { - // [[FBRoute GET:@"/screenshot"] respondWithTarget:self action:@selector(handleGetScreenshot:)] - // [[FBRoute GET:@"/screenshot"].withoutSession respondWithTarget:self action:@selector(handleGetScreenshot:)] - var rawResp DriverRawResponse - if rawResp, err = wd.httpGET("/session", wd.Session.ID, "/screenshot"); err != nil { - return nil, errors.Wrap(code.DeviceScreenShotError, - fmt.Sprintf("get WDA screenshot data failed: %v", err)) - } - - if raw, err = rawResp.ValueDecodeAsBase64(); err != nil { - return nil, errors.Wrap(code.DeviceScreenShotError, - fmt.Sprintf("decode WDA screenshot data failed: %v", err)) - } - return -} - func (wd *WDADriver) Source(srcOpt ...option.SourceOption) (source string, err error) { // [[FBRoute GET:@"/source"] respondWithTarget:self action:@selector(handleGetSourceCommand:)] // [[FBRoute GET:@"/source"].withoutSession @@ -892,7 +892,7 @@ func (wd *WDADriver) triggerWDALog(data map[string]interface{}) (rawResp []byte, return wd.httpPOST(data, "/gtf/automation/log") } -func (wd *WDADriver) RecordScreen(folderPath string, duration time.Duration) (videoPath string, err error) { +func (wd *WDADriver) ScreenRecord(folderPath string, duration time.Duration) (videoPath string, err error) { // 获取当前时间戳 timestamp := time.Now().Format("20060102_150405") + fmt.Sprintf("_%03d", time.Now().UnixNano()/1e6%1000) // 创建文件名 @@ -999,13 +999,6 @@ func (wd *WDADriver) GetSession() *Session { return wd.Session } -func (wd *WDADriver) GetDriverResults() []*DriverRequests { - defer func() { - wd.Session.requests = nil - }() - return wd.Session.requests -} - func (wd *WDADriver) Setup() error { return nil } diff --git a/pkg/uixt/ios_test.go b/pkg/uixt/ios_test.go index abc4a262..a772b0f2 100644 --- a/pkg/uixt/ios_test.go +++ b/pkg/uixt/ios_test.go @@ -229,7 +229,7 @@ func Test_remoteWD_WindowSize(t *testing.T) { func Test_remoteWD_Screen(t *testing.T) { setup(t) - screen, err := driver.Screen() + screen, err := driver.(*WDADriver).Screen() if err != nil { t.Fatal(err) } @@ -348,7 +348,7 @@ func Test_remoteWD_PressButton(t *testing.T) { func Test_remoteWD_Screenshot(t *testing.T) { setup(t) - screenshot, err := driver.Screenshot() + screenshot, err := driver.ScreenShot() if err != nil { t.Fatal(err) } @@ -433,7 +433,7 @@ func Test_remoteWD_AccessibleSource(t *testing.T) { func TestRecord(t *testing.T) { setup(t) - path, err := driver.(*WDADriver).RecordScreen("", 5*time.Second) + path, err := driver.ScreenRecord("", 5*time.Second) if err != nil { t.Fatal(err) } diff --git a/server/source.go b/server/source.go index 8fa69d7f..23409804 100644 --- a/server/source.go +++ b/server/source.go @@ -18,7 +18,7 @@ func screenshotHandler(c *gin.Context) { return } - raw, err := dExt.Screenshot() + raw, err := dExt.ScreenShot() if err != nil { log.Err(err).Msg(fmt.Sprintf("[%s]: failed to get screenshot", c.HandlerName())) c.JSON(http.StatusInternalServerError,