mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-12 16:01:27 +08:00
feat: DriverSession Get and Reset
This commit is contained in:
@@ -1 +1 @@
|
|||||||
v5.0.0+2411142009
|
v5.0.0+2411142130
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ func NewAdbDriver() *adbDriver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (ad *adbDriver) NewSession(capabilities Capabilities) (sessionInfo SessionInfo, err error) {
|
func (ad *adbDriver) NewSession(capabilities Capabilities) (sessionInfo SessionInfo, err error) {
|
||||||
ad.Driver.session.Init()
|
ad.Driver.session.Reset()
|
||||||
err = errDriverNotImplemented
|
err = errDriverNotImplemented
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ func (sad *stubAndroidDriver) httpPOST(data interface{}, pathElem ...string) (ra
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (sad *stubAndroidDriver) NewSession(capabilities Capabilities) (SessionInfo, error) {
|
func (sad *stubAndroidDriver) NewSession(capabilities Capabilities) (SessionInfo, error) {
|
||||||
sad.Driver.session.Init()
|
sad.Driver.session.Reset()
|
||||||
return SessionInfo{}, errDriverNotImplemented
|
return SessionInfo{}, errDriverNotImplemented
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -155,7 +155,7 @@ func (ud *uiaDriver) NewSession(capabilities Capabilities) (sessionInfo SessionI
|
|||||||
return SessionInfo{SessionId: ""}, err
|
return SessionInfo{SessionId: ""}, err
|
||||||
}
|
}
|
||||||
sessionID := reply.Value.SessionId
|
sessionID := reply.Value.SessionId
|
||||||
ud.Driver.session.Init()
|
ud.Driver.session.Reset()
|
||||||
ud.Driver.session.ID = sessionID
|
ud.Driver.session.ID = sessionID
|
||||||
// d.sessionIdCache[sessionID] = true
|
// d.sessionIdCache[sessionID] = true
|
||||||
return SessionInfo{SessionId: sessionID}, nil
|
return SessionInfo{SessionId: sessionID}, nil
|
||||||
|
|||||||
@@ -19,43 +19,38 @@ type DriverSession struct {
|
|||||||
ID string
|
ID string
|
||||||
// cache uia2/wda request and response
|
// cache uia2/wda request and response
|
||||||
requests []*DriverResult
|
requests []*DriverResult
|
||||||
// cache session screenshot ocr results, key is image path, value is ScreenResult
|
// cache screenshot ocr results
|
||||||
screenResults ScreenResultMap
|
screenResults []*ScreenResult // list of actions
|
||||||
// cache e2e delay
|
// cache e2e delay
|
||||||
e2eDelay []timeLog
|
e2eDelay []timeLog
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DriverSession) addScreenResult(screenResult *ScreenResult) {
|
func (d *DriverSession) addScreenResult(screenResult *ScreenResult) {
|
||||||
d.screenResults[screenResult.ImagePath] = screenResult
|
d.screenResults = append(d.screenResults, screenResult)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DriverSession) addRequestResult(driverResult *DriverResult) {
|
func (d *DriverSession) addRequestResult(driverResult *DriverResult) {
|
||||||
d.requests = append(d.requests, driverResult)
|
d.requests = append(d.requests, driverResult)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DriverSession) Init() {
|
func (d *DriverSession) Reset() {
|
||||||
d.screenResults = make(map[string]*ScreenResult)
|
d.screenResults = make([]*ScreenResult, 0)
|
||||||
d.requests = nil
|
d.requests = make([]*DriverResult, 0)
|
||||||
d.e2eDelay = nil
|
d.e2eDelay = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DriverSession) GetAll() map[string]interface{} {
|
func (d *DriverSession) Get(withReset bool) 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
|
|
||||||
}
|
|
||||||
|
|
||||||
data := map[string]interface{}{
|
data := map[string]interface{}{
|
||||||
"screenshots": screenShots,
|
"screen_results": d.screenResults,
|
||||||
"screenshots_urls": screenShotsUrls,
|
}
|
||||||
"screen_results": d.screenResults,
|
if len(d.e2eDelay) != 0 {
|
||||||
"requests": d.requests,
|
data["requests"] = d.requests
|
||||||
"e2e_results": d.e2eDelay,
|
}
|
||||||
|
if d.e2eDelay != nil {
|
||||||
|
data["e2e_results"] = d.e2eDelay
|
||||||
|
}
|
||||||
|
if withReset {
|
||||||
|
d.Reset()
|
||||||
}
|
}
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ func newHarmonyDriver(device *ghdc.Device) (driver *hdcDriver, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (hd *hdcDriver) NewSession(capabilities Capabilities) (SessionInfo, error) {
|
func (hd *hdcDriver) NewSession(capabilities Capabilities) (SessionInfo, error) {
|
||||||
hd.Driver.session.Init()
|
hd.Driver.session.Reset()
|
||||||
hd.Unlock()
|
hd.Unlock()
|
||||||
return SessionInfo{}, errDriverNotImplemented
|
return SessionInfo{}, errDriverNotImplemented
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ func (wd *wdaDriver) NewSession(capabilities Capabilities) (sessionInfo SessionI
|
|||||||
if sessionInfo, err = rawResp.valueConvertToSessionInfo(); err != nil {
|
if sessionInfo, err = rawResp.valueConvertToSessionInfo(); err != nil {
|
||||||
return SessionInfo{}, err
|
return SessionInfo{}, err
|
||||||
}
|
}
|
||||||
wd.Driver.session.Init()
|
wd.Driver.session.Reset()
|
||||||
wd.Driver.session.ID = sessionInfo.SessionId
|
wd.Driver.session.ID = sessionInfo.SessionId
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,8 +32,6 @@ type ScreenResult struct {
|
|||||||
Popup *PopupInfo `json:"popup,omitempty"`
|
Popup *PopupInfo `json:"popup,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ScreenResultMap map[string]*ScreenResult // key is date time
|
|
||||||
|
|
||||||
// GetScreenResult takes a screenshot, returns the image recognition result
|
// GetScreenResult takes a screenshot, returns the image recognition result
|
||||||
func (dExt *DriverExt) GetScreenResult(options ...ActionOption) (screenResult *ScreenResult, err error) {
|
func (dExt *DriverExt) GetScreenResult(options ...ActionOption) (screenResult *ScreenResult, err error) {
|
||||||
actionOptions := NewActionOptions(options...)
|
actionOptions := NewActionOptions(options...)
|
||||||
|
|||||||
@@ -682,7 +682,7 @@ func runStepMobileUI(s *SessionRunner, step IStep) (stepResult *StepResult, err
|
|||||||
|
|
||||||
// save attachments
|
// save attachments
|
||||||
session := uiDriver.Driver.GetSession()
|
session := uiDriver.Driver.GetSession()
|
||||||
for key, value := range session.GetAll() {
|
for key, value := range session.Get(true) {
|
||||||
attachments[key] = value
|
attachments[key] = value
|
||||||
}
|
}
|
||||||
stepResult.Attachments = attachments
|
stepResult.Attachments = attachments
|
||||||
|
|||||||
Reference in New Issue
Block a user