From d97de403f92bf17c24478c52188d5dcab7d70f7a Mon Sep 17 00:00:00 2001 From: "lilong.129" Date: Thu, 14 Nov 2024 21:30:09 +0800 Subject: [PATCH] feat: DriverSession Get and Reset --- hrp/internal/version/VERSION | 2 +- hrp/pkg/uixt/android_adb_driver.go | 2 +- hrp/pkg/uixt/android_stub_driver.go | 2 +- hrp/pkg/uixt/android_uia2_driver.go | 2 +- hrp/pkg/uixt/client.go | 39 +++++++++++++---------------- hrp/pkg/uixt/harmony_hdc_driver.go | 2 +- hrp/pkg/uixt/ios_driver.go | 2 +- hrp/pkg/uixt/screenshot.go | 2 -- hrp/step_mobile_ui.go | 2 +- 9 files changed, 24 insertions(+), 31 deletions(-) diff --git a/hrp/internal/version/VERSION b/hrp/internal/version/VERSION index 7920650d..50551ff8 100644 --- a/hrp/internal/version/VERSION +++ b/hrp/internal/version/VERSION @@ -1 +1 @@ -v5.0.0+2411142009 +v5.0.0+2411142130 diff --git a/hrp/pkg/uixt/android_adb_driver.go b/hrp/pkg/uixt/android_adb_driver.go index 328a540b..2c676d75 100644 --- a/hrp/pkg/uixt/android_adb_driver.go +++ b/hrp/pkg/uixt/android_adb_driver.go @@ -44,7 +44,7 @@ func NewAdbDriver() *adbDriver { } func (ad *adbDriver) NewSession(capabilities Capabilities) (sessionInfo SessionInfo, err error) { - ad.Driver.session.Init() + ad.Driver.session.Reset() err = errDriverNotImplemented return } diff --git a/hrp/pkg/uixt/android_stub_driver.go b/hrp/pkg/uixt/android_stub_driver.go index 3506ec48..cd28a31b 100644 --- a/hrp/pkg/uixt/android_stub_driver.go +++ b/hrp/pkg/uixt/android_stub_driver.go @@ -95,7 +95,7 @@ func (sad *stubAndroidDriver) httpPOST(data interface{}, pathElem ...string) (ra } func (sad *stubAndroidDriver) NewSession(capabilities Capabilities) (SessionInfo, error) { - sad.Driver.session.Init() + sad.Driver.session.Reset() return SessionInfo{}, errDriverNotImplemented } diff --git a/hrp/pkg/uixt/android_uia2_driver.go b/hrp/pkg/uixt/android_uia2_driver.go index cee3fd9b..7a20276b 100644 --- a/hrp/pkg/uixt/android_uia2_driver.go +++ b/hrp/pkg/uixt/android_uia2_driver.go @@ -155,7 +155,7 @@ func (ud *uiaDriver) NewSession(capabilities Capabilities) (sessionInfo SessionI return SessionInfo{SessionId: ""}, err } sessionID := reply.Value.SessionId - ud.Driver.session.Init() + ud.Driver.session.Reset() ud.Driver.session.ID = sessionID // d.sessionIdCache[sessionID] = true return SessionInfo{SessionId: sessionID}, nil diff --git a/hrp/pkg/uixt/client.go b/hrp/pkg/uixt/client.go index c75c47fb..5350f2f7 100644 --- a/hrp/pkg/uixt/client.go +++ b/hrp/pkg/uixt/client.go @@ -19,43 +19,38 @@ type DriverSession struct { ID string // cache uia2/wda request and response requests []*DriverResult - // cache session screenshot ocr results, key is image path, value is ScreenResult - screenResults ScreenResultMap + // cache screenshot ocr results + screenResults []*ScreenResult // list of actions // cache e2e delay e2eDelay []timeLog } func (d *DriverSession) addScreenResult(screenResult *ScreenResult) { - d.screenResults[screenResult.ImagePath] = screenResult + d.screenResults = append(d.screenResults, screenResult) } func (d *DriverSession) addRequestResult(driverResult *DriverResult) { d.requests = append(d.requests, driverResult) } -func (d *DriverSession) Init() { - d.screenResults = make(map[string]*ScreenResult) - d.requests = nil +func (d *DriverSession) Reset() { + d.screenResults = make([]*ScreenResult, 0) + d.requests = make([]*DriverResult, 0) d.e2eDelay = nil } -func (d *DriverSession) GetAll() map[string]interface{} { - screenShots := make([]string, 0) - screenShotsUrls := make(map[string]string) - for _, screenResult := range d.screenResults { - screenShots = append(screenShots, screenResult.ImagePath) - if screenResult.UploadedURL == "" { - continue - } - screenShotsUrls[screenResult.ImagePath] = screenResult.UploadedURL - } - +func (d *DriverSession) Get(withReset bool) map[string]interface{} { data := map[string]interface{}{ - "screenshots": screenShots, - "screenshots_urls": screenShotsUrls, - "screen_results": d.screenResults, - "requests": d.requests, - "e2e_results": d.e2eDelay, + "screen_results": d.screenResults, + } + if len(d.e2eDelay) != 0 { + data["requests"] = d.requests + } + if d.e2eDelay != nil { + data["e2e_results"] = d.e2eDelay + } + if withReset { + d.Reset() } return data } diff --git a/hrp/pkg/uixt/harmony_hdc_driver.go b/hrp/pkg/uixt/harmony_hdc_driver.go index 606078e9..cc578ace 100644 --- a/hrp/pkg/uixt/harmony_hdc_driver.go +++ b/hrp/pkg/uixt/harmony_hdc_driver.go @@ -40,7 +40,7 @@ func newHarmonyDriver(device *ghdc.Device) (driver *hdcDriver, err error) { } func (hd *hdcDriver) NewSession(capabilities Capabilities) (SessionInfo, error) { - hd.Driver.session.Init() + hd.Driver.session.Reset() hd.Unlock() return SessionInfo{}, errDriverNotImplemented } diff --git a/hrp/pkg/uixt/ios_driver.go b/hrp/pkg/uixt/ios_driver.go index 2e21f2f9..88130b9d 100644 --- a/hrp/pkg/uixt/ios_driver.go +++ b/hrp/pkg/uixt/ios_driver.go @@ -108,7 +108,7 @@ func (wd *wdaDriver) NewSession(capabilities Capabilities) (sessionInfo SessionI if sessionInfo, err = rawResp.valueConvertToSessionInfo(); err != nil { return SessionInfo{}, err } - wd.Driver.session.Init() + wd.Driver.session.Reset() wd.Driver.session.ID = sessionInfo.SessionId return } diff --git a/hrp/pkg/uixt/screenshot.go b/hrp/pkg/uixt/screenshot.go index 958e4b7a..88ded541 100644 --- a/hrp/pkg/uixt/screenshot.go +++ b/hrp/pkg/uixt/screenshot.go @@ -32,8 +32,6 @@ type ScreenResult struct { Popup *PopupInfo `json:"popup,omitempty"` } -type ScreenResultMap map[string]*ScreenResult // key is date time - // GetScreenResult takes a screenshot, returns the image recognition result func (dExt *DriverExt) GetScreenResult(options ...ActionOption) (screenResult *ScreenResult, err error) { actionOptions := NewActionOptions(options...) diff --git a/hrp/step_mobile_ui.go b/hrp/step_mobile_ui.go index 3e0bed64..e8568ffd 100644 --- a/hrp/step_mobile_ui.go +++ b/hrp/step_mobile_ui.go @@ -682,7 +682,7 @@ func runStepMobileUI(s *SessionRunner, step IStep) (stepResult *StepResult, err // save attachments session := uiDriver.Driver.GetSession() - for key, value := range session.GetAll() { + for key, value := range session.Get(true) { attachments[key] = value } stepResult.Attachments = attachments