diff --git a/hrp/pkg/uixt/android_adb_driver.go b/hrp/pkg/uixt/android_adb_driver.go index 2968fe06..f73e73ea 100644 --- a/hrp/pkg/uixt/android_adb_driver.go +++ b/hrp/pkg/uixt/android_adb_driver.go @@ -42,6 +42,7 @@ func NewAdbDriver() *adbDriver { } func (ad *adbDriver) NewSession(capabilities Capabilities) (sessionInfo SessionInfo, err error) { + ad.Driver.session.Init() err = errDriverNotImplemented return } diff --git a/hrp/pkg/uixt/android_stub_driver.go b/hrp/pkg/uixt/android_stub_driver.go index 2f92a436..693337ee 100644 --- a/hrp/pkg/uixt/android_stub_driver.go +++ b/hrp/pkg/uixt/android_stub_driver.go @@ -94,6 +94,7 @@ func (sad *stubAndroidDriver) httpPOST(data interface{}, pathElem ...string) (ra } func (sad *stubAndroidDriver) NewSession(capabilities Capabilities) (SessionInfo, error) { + sad.Driver.session.Init() return SessionInfo{}, errDriverNotImplemented } diff --git a/hrp/pkg/uixt/android_test.go b/hrp/pkg/uixt/android_test.go index e643c42b..67f69628 100644 --- a/hrp/pkg/uixt/android_test.go +++ b/hrp/pkg/uixt/android_test.go @@ -62,7 +62,7 @@ func TestNewDriver(t *testing.T) { t.Fatal(err) } - t.Log(driver.sessionId) + t.Log(driver.session.ID) } func TestDriver_Quit(t *testing.T) { diff --git a/hrp/pkg/uixt/android_uia2_driver.go b/hrp/pkg/uixt/android_uia2_driver.go index 7632af6d..01ab463f 100644 --- a/hrp/pkg/uixt/android_uia2_driver.go +++ b/hrp/pkg/uixt/android_uia2_driver.go @@ -49,11 +49,10 @@ func NewUIADriver(capabilities Capabilities, urlPrefix string) (driver *uiaDrive } driver.client = convertToHTTPClient(conn) - session, err := driver.NewSession(capabilities) + _, err = driver.NewSession(capabilities) if err != nil { return nil, errors.Wrap(err, "create UIAutomator session failed") } - driver.sessionId = session.SessionId return driver, nil } @@ -91,7 +90,7 @@ func (ud *uiaDriver) resetDriver() error { return err } ud.client = newUIADriver.client - ud.sessionId = newUIADriver.sessionId + ud.session.ID = newUIADriver.session.ID return nil } @@ -104,14 +103,14 @@ func (ud *uiaDriver) httpRequest(method string, rawURL string, rawBody []byte, d } // wait for UIA2 server to resume automatically time.Sleep(3 * time.Second) - oldSessionID := ud.sessionId + oldSessionID := ud.session.ID if err2 := ud.resetDriver(); err2 != nil { log.Err(err2).Msgf("failed to reset uia2 driver, retry count: %v", retryCount) continue } - log.Debug().Str("new session", ud.sessionId).Str("old session", oldSessionID).Msgf("successful to reset uia2 driver, retry count: %v", retryCount) + log.Debug().Str("new session", ud.session.ID).Str("old session", oldSessionID).Msgf("successful to reset uia2 driver, retry count: %v", retryCount) if oldSessionID != "" { - rawURL = strings.Replace(rawURL, oldSessionID, ud.sessionId, 1) + rawURL = strings.Replace(rawURL, oldSessionID, ud.session.ID, 1) } } return @@ -156,16 +155,18 @@ func (ud *uiaDriver) NewSession(capabilities Capabilities) (sessionInfo SessionI return SessionInfo{SessionId: ""}, err } sessionID := reply.Value.SessionId + ud.Driver.session.Init() + ud.Driver.session.ID = sessionID // d.sessionIdCache[sessionID] = true return SessionInfo{SessionId: sessionID}, nil } func (ud *uiaDriver) DeleteSession() (err error) { - if ud.sessionId == "" { + if ud.session.ID == "" { return nil } - if _, err = ud.httpDELETE("/session", ud.sessionId); err == nil { - ud.sessionId = "" + if _, err = ud.httpDELETE("/session", ud.session.ID); err == nil { + ud.session.ID = "" } return err @@ -192,7 +193,7 @@ func (ud *uiaDriver) Status() (deviceStatus DeviceStatus, err error) { func (ud *uiaDriver) DeviceInfo() (deviceInfo DeviceInfo, err error) { // register(getHandler, new GetDeviceInfo("/wd/hub/session/:sessionId/appium/device/info")) var rawResp rawResponse - if rawResp, err = ud.httpGET("/session", ud.sessionId, "appium/device/info"); err != nil { + if rawResp, err = ud.httpGET("/session", ud.session.ID, "appium/device/info"); err != nil { return DeviceInfo{}, err } reply := new(struct{ Value struct{ DeviceInfo } }) @@ -206,7 +207,7 @@ func (ud *uiaDriver) DeviceInfo() (deviceInfo DeviceInfo, err error) { func (ud *uiaDriver) BatteryInfo() (batteryInfo BatteryInfo, err error) { // register(getHandler, new GetBatteryInfo("/wd/hub/session/:sessionId/appium/device/battery_info")) var rawResp rawResponse - if rawResp, err = ud.httpGET("/session", ud.sessionId, "appium/device/battery_info"); err != nil { + if rawResp, err = ud.httpGET("/session", ud.session.ID, "appium/device/battery_info"); err != nil { return BatteryInfo{}, err } reply := new(struct{ Value struct{ BatteryInfo } }) @@ -226,7 +227,7 @@ func (ud *uiaDriver) WindowSize() (size Size, err error) { size = *ud.windowSize } else { var rawResp rawResponse - if rawResp, err = ud.httpGET("/session", ud.sessionId, "window/:windowHandle/size"); err != nil { + if rawResp, err = ud.httpGET("/session", ud.session.ID, "window/:windowHandle/size"); err != nil { return Size{}, errors.Wrap(err, "get window size failed with uiautomator2") } reply := new(struct{ Value struct{ Size } }) @@ -252,7 +253,7 @@ func (ud *uiaDriver) WindowSize() (size Size, err error) { // PressBack simulates a short press on the BACK button. func (ud *uiaDriver) PressBack(options ...ActionOption) (err error) { // register(postHandler, new PressBack("/wd/hub/session/:sessionId/back")) - _, err = ud.httpPOST(nil, "/session", ud.sessionId, "back") + _, err = ud.httpPOST(nil, "/session", ud.session.ID, "back") return } @@ -275,14 +276,14 @@ func (ud *uiaDriver) PressKeyCodes(keyCode KeyCode, metaState KeyMeta, flags ... if len(flags) != 0 { data["flags"] = flags[0] } - _, err = ud.httpPOST(data, "/session", ud.sessionId, "appium/device/press_keycode") + _, err = ud.httpPOST(data, "/session", ud.session.ID, "appium/device/press_keycode") return } func (ud *uiaDriver) Orientation() (orientation Orientation, err error) { // [[FBRoute GET:@"/orientation"] respondWithTarget:self action:@selector(handleGetOrientation:)] var rawResp rawResponse - if rawResp, err = ud.httpGET("/session", ud.sessionId, "/orientation"); err != nil { + if rawResp, err = ud.httpGET("/session", ud.session.ID, "/orientation"); err != nil { return "", err } reply := new(struct{ Value Orientation }) @@ -315,7 +316,7 @@ func (ud *uiaDriver) DoubleFloatTap(x, y float64) error { }, } - _, err := ud.httpPOST(data, "/session", ud.sessionId, "actions/tap") + _, err := ud.httpPOST(data, "/session", ud.session.ID, "actions/tap") return err } @@ -357,7 +358,7 @@ func (ud *uiaDriver) TapFloat(x, y float64, options ...ActionOption) (err error) // update data options in post data for extra uiautomator configurations actionOptions.updateData(data) - _, err = ud.httpPOST(data, "/session", ud.sessionId, "actions/tap") + _, err = ud.httpPOST(data, "/session", ud.session.ID, "actions/tap") return err } @@ -377,7 +378,7 @@ func (ud *uiaDriver) TouchAndHoldFloat(x, y float64, second ...float64) (err err "duration": int(second[0] * 1000), }, } - _, err = ud.httpPOST(data, "/session", ud.sessionId, "touch/longclick") + _, err = ud.httpPOST(data, "/session", ud.session.ID, "touch/longclick") return } @@ -413,7 +414,7 @@ func (ud *uiaDriver) DragFloat(fromX, fromY, toX, toY float64, options ...Action actionOptions.updateData(data) // register(postHandler, new Drag("/wd/hub/session/:sessionId/touch/drag")) - _, err = ud.httpPOST(data, "/session", ud.sessionId, "touch/drag") + _, err = ud.httpPOST(data, "/session", ud.session.ID, "touch/drag") return } @@ -463,7 +464,7 @@ func (ud *uiaDriver) SwipeFloat(fromX, fromY, toX, toY float64, options ...Actio // update data options in post data for extra uiautomator configurations actionOptions.updateData(data) - _, err := ud.httpPOST(data, "/session", ud.sessionId, "actions/swipe") + _, err := ud.httpPOST(data, "/session", ud.session.ID, "actions/swipe") return err } @@ -481,7 +482,7 @@ func (ud *uiaDriver) SetPasteboard(contentType PasteboardType, content string) ( "content": base64.StdEncoding.EncodeToString([]byte(content)), } // register(postHandler, new SetClipboard("/wd/hub/session/:sessionId/appium/device/set_clipboard")) - _, err = ud.httpPOST(data, "/session", ud.sessionId, "appium/device/set_clipboard") + _, err = ud.httpPOST(data, "/session", ud.session.ID, "appium/device/set_clipboard") return } @@ -494,7 +495,7 @@ func (ud *uiaDriver) GetPasteboard(contentType PasteboardType) (raw *bytes.Buffe "contentType": contentType[0], } var rawResp rawResponse - if rawResp, err = ud.httpPOST(data, "/session", ud.sessionId, "appium/device/get_clipboard"); err != nil { + if rawResp, err = ud.httpPOST(data, "/session", ud.session.ID, "appium/device/get_clipboard"); err != nil { return } reply := new(struct{ Value string }) @@ -524,7 +525,7 @@ func (ud *uiaDriver) SendKeys(text string, options ...ActionOption) (err error) // new data options in post data for extra uiautomator configurations actionOptions.updateData(data) - _, err = ud.httpPOST(data, "/session", ud.sessionId, "/keys") + _, err = ud.httpPOST(data, "/session", ud.session.ID, "/keys") } return } @@ -582,7 +583,7 @@ func (ud *uiaDriver) SendActionKey(text string, options ...ActionOption) (err er // new data options in post data for extra uiautomator configurations actionOptions.updateData(data) - _, err = ud.httpPOST(data, "/session", ud.sessionId, "/actions/keys") + _, err = ud.httpPOST(data, "/session", ud.session.ID, "/actions/keys") return } @@ -593,7 +594,7 @@ func (ud *uiaDriver) Input(text string, options ...ActionOption) (err error) { func (ud *uiaDriver) Rotation() (rotation Rotation, err error) { // register(getHandler, new GetRotation("/wd/hub/session/:sessionId/rotation")) var rawResp rawResponse - if rawResp, err = ud.httpGET("/session", ud.sessionId, "rotation"); err != nil { + if rawResp, err = ud.httpGET("/session", ud.session.ID, "rotation"); err != nil { return Rotation{}, err } reply := new(struct{ Value Rotation }) @@ -614,7 +615,7 @@ func (ud *uiaDriver) Screenshot() (raw *bytes.Buffer, err error) { func (ud *uiaDriver) Source(srcOpt ...SourceOption) (source string, err error) { // register(getHandler, new Source("/wd/hub/session/:sessionId/source")) var rawResp rawResponse - if rawResp, err = ud.httpGET("/session", ud.sessionId, "source"); err != nil { + if rawResp, err = ud.httpGET("/session", ud.session.ID, "source"); err != nil { return "", err } reply := new(struct{ Value string }) diff --git a/hrp/pkg/uixt/client.go b/hrp/pkg/uixt/client.go index 44d8078f..f27c4dd4 100644 --- a/hrp/pkg/uixt/client.go +++ b/hrp/pkg/uixt/client.go @@ -16,6 +16,7 @@ import ( ) 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 @@ -32,7 +33,7 @@ func (d *DriverSession) addRequestResult(driverResult *DriverResult) { d.requests = append(d.requests, driverResult) } -func (d *DriverSession) Clear() { +func (d *DriverSession) Init() { d.screenResults = make(map[string]*ScreenResult) d.requests = nil d.e2eDelay = nil @@ -61,7 +62,6 @@ func (d *DriverSession) GetAll() map[string]interface{} { type Driver struct { urlPrefix *url.URL - sessionId string client *http.Client // cache to avoid repeated query diff --git a/hrp/pkg/uixt/ext.go b/hrp/pkg/uixt/ext.go index 79aac2f9..cae5a85a 100644 --- a/hrp/pkg/uixt/ext.go +++ b/hrp/pkg/uixt/ext.go @@ -27,7 +27,6 @@ func newDriverExt(device IDevice, driver IWebDriver, options ...DriverOption) (d option(driverOptions) } - driver.GetSession().Clear() dExt = &DriverExt{ Device: device, Driver: driver, diff --git a/hrp/pkg/uixt/ios_device.go b/hrp/pkg/uixt/ios_device.go index 3aa092f8..82f351e2 100644 --- a/hrp/pkg/uixt/ios_device.go +++ b/hrp/pkg/uixt/ios_device.go @@ -654,11 +654,9 @@ func (dev *IOSDevice) NewHTTPDriver(capabilities Capabilities) (driver IWebDrive if wd.urlPrefix, err = url.Parse(fmt.Sprintf("http://%s:%d", host, localPort)); err != nil { return nil, errors.Wrap(code.IOSDeviceHTTPDriverError, err.Error()) } - var sessionInfo SessionInfo - if sessionInfo, err = wd.NewSession(capabilities); err != nil { + if _, err = wd.NewSession(capabilities); err != nil { return nil, errors.Wrap(code.IOSDeviceHTTPDriverError, err.Error()) } - wd.sessionId = sessionInfo.SessionId if wd.mjpegHTTPConn, err = net.Dial( "tcp", @@ -697,11 +695,9 @@ func (dev *IOSDevice) NewUSBDriver(capabilities Capabilities) (driver IWebDriver if wd.urlPrefix, err = url.Parse("http://" + dev.UDID); err != nil { return nil, errors.Wrap(code.IOSDeviceUSBDriverError, err.Error()) } - var sessionInfo SessionInfo - if sessionInfo, err = wd.NewSession(capabilities); err != nil { + if _, err = wd.NewSession(capabilities); err != nil { return nil, errors.Wrap(code.IOSDeviceUSBDriverError, err.Error()) } - wd.sessionId = sessionInfo.SessionId // init WDA scale if wd.scale, err = wd.Scale(); err != nil { diff --git a/hrp/pkg/uixt/ios_driver.go b/hrp/pkg/uixt/ios_driver.go index fc15aaa4..d2f56df4 100644 --- a/hrp/pkg/uixt/ios_driver.go +++ b/hrp/pkg/uixt/ios_driver.go @@ -37,11 +37,10 @@ func (wd *wdaDriver) resetSession() error { capabilities := NewCapabilities() capabilities.WithDefaultAlertAction(AlertActionAccept) - sessionInfo, err := wd.NewSession(capabilities) + _, err := wd.NewSession(capabilities) if err != nil { return err } - wd.sessionId = sessionInfo.SessionId return nil } @@ -54,14 +53,14 @@ func (wd *wdaDriver) httpRequest(method string, rawURL string, rawBody []byte, d } // TODO: polling WDA to check if resumed automatically time.Sleep(5 * time.Second) - oldSessionID := wd.sessionId + oldSessionID := wd.session.ID if err2 := wd.resetSession(); err2 != nil { log.Err(err2).Msgf("failed to reset wda driver, retry count: %v", retryCount) continue } - log.Debug().Str("new session", wd.sessionId).Str("old session", oldSessionID).Msgf("successful to reset wda driver, retry count: %v", retryCount) + log.Debug().Str("new session", wd.session.ID).Str("old session", oldSessionID).Msgf("successful to reset wda driver, retry count: %v", retryCount) if oldSessionID != "" { - rawURL = strings.Replace(rawURL, oldSessionID, wd.sessionId, 1) + rawURL = strings.Replace(rawURL, oldSessionID, wd.session.ID, 1) } } return @@ -109,6 +108,8 @@ 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.ID = sessionInfo.SessionId return } @@ -128,7 +129,7 @@ func (wd *wdaDriver) DeleteSession() (err error) { } // [[FBRoute DELETE:@""] respondWithTarget:self action:@selector(handleDeleteSession:)] - _, err = wd.httpDELETE("/session", wd.sessionId) + _, err = wd.httpDELETE("/session", wd.session.ID) return } @@ -150,7 +151,7 @@ func (wd *wdaDriver) DeviceInfo() (deviceInfo DeviceInfo, err error) { // [[FBRoute GET:@"/wda/device/info"] respondWithTarget:self action:@selector(handleGetDeviceInfo:)] // [[FBRoute GET:@"/wda/device/info"].withoutSession var rawResp rawResponse - if rawResp, err = wd.httpGET("/session", wd.sessionId, "/wda/device/info"); err != nil { + if rawResp, err = wd.httpGET("/session", wd.session.ID, "/wda/device/info"); err != nil { return DeviceInfo{}, err } reply := new(struct{ Value struct{ DeviceInfo } }) @@ -165,7 +166,7 @@ func (wd *wdaDriver) Location() (location Location, err error) { // [[FBRoute GET:@"/wda/device/location"] respondWithTarget:self action:@selector(handleGetLocation:)] // [[FBRoute GET:@"/wda/device/location"].withoutSession var rawResp rawResponse - if rawResp, err = wd.httpGET("/session", wd.sessionId, "/wda/device/location"); err != nil { + if rawResp, err = wd.httpGET("/session", wd.session.ID, "/wda/device/location"); err != nil { return Location{}, err } reply := new(struct{ Value struct{ Location } }) @@ -179,7 +180,7 @@ func (wd *wdaDriver) Location() (location Location, err error) { func (wd *wdaDriver) BatteryInfo() (batteryInfo BatteryInfo, err error) { // [[FBRoute GET:@"/wda/batteryInfo"] respondWithTarget:self action:@selector(handleGetBatteryInfo:)] var rawResp rawResponse - if rawResp, err = wd.httpGET("/session", wd.sessionId, "/wda/batteryInfo"); err != nil { + if rawResp, err = wd.httpGET("/session", wd.session.ID, "/wda/batteryInfo"); err != nil { return BatteryInfo{}, err } reply := new(struct{ Value struct{ BatteryInfo } }) @@ -196,7 +197,7 @@ func (wd *wdaDriver) WindowSize() (size Size, err error) { size = *wd.windowSize } else { var rawResp rawResponse - if rawResp, err = wd.httpGET("/session", wd.sessionId, "/window/size"); err != nil { + if rawResp, err = wd.httpGET("/session", wd.session.ID, "/window/size"); err != nil { return Size{}, errors.Wrap(err, "get window size failed with wda") } reply := new(struct{ Value struct{ Size } }) @@ -228,7 +229,7 @@ func (wd *wdaDriver) WindowSize() (size Size, err error) { func (wd *wdaDriver) Screen() (screen Screen, err error) { // [[FBRoute GET:@"/wda/screen"] respondWithTarget:self action:@selector(handleGetScreen:)] var rawResp rawResponse - if rawResp, err = wd.httpGET("/session", wd.sessionId, "/wda/screen"); err != nil { + if rawResp, err = wd.httpGET("/session", wd.session.ID, "/wda/screen"); err != nil { return Screen{}, err } reply := new(struct{ Value struct{ Screen } }) @@ -264,7 +265,7 @@ func (wd *wdaDriver) ActiveAppInfo() (info AppInfo, err error) { // [[FBRoute GET:@"/wda/activeAppInfo"] respondWithTarget:self action:@selector(handleActiveAppInfo:)] // [[FBRoute GET:@"/wda/activeAppInfo"].withoutSession var rawResp rawResponse - if rawResp, err = wd.httpGET("/session", wd.sessionId, "/wda/activeAppInfo"); err != nil { + if rawResp, err = wd.httpGET("/session", wd.session.ID, "/wda/activeAppInfo"); err != nil { return AppInfo{}, err } reply := new(struct{ Value struct{ AppInfo } }) @@ -278,7 +279,7 @@ func (wd *wdaDriver) ActiveAppInfo() (info AppInfo, err error) { func (wd *wdaDriver) ActiveAppsList() (appsList []AppBaseInfo, err error) { // [[FBRoute GET:@"/wda/apps/list"] respondWithTarget:self action:@selector(handleGetActiveAppsList:)] var rawResp rawResponse - if rawResp, err = wd.httpGET("/session", wd.sessionId, "/wda/apps/list"); err != nil { + if rawResp, err = wd.httpGET("/session", wd.session.ID, "/wda/apps/list"); err != nil { return nil, err } reply := new(struct{ Value []AppBaseInfo }) @@ -293,7 +294,7 @@ func (wd *wdaDriver) AppState(bundleId string) (runState AppState, err error) { // [[FBRoute POST:@"/wda/apps/state"] respondWithTarget:self action:@selector(handleSessionAppState:)] data := map[string]interface{}{"bundleId": bundleId} var rawResp rawResponse - if rawResp, err = wd.httpPOST(data, "/session", wd.sessionId, "/wda/apps/state"); err != nil { + if rawResp, err = wd.httpPOST(data, "/session", wd.session.ID, "/wda/apps/state"); err != nil { return 0, err } reply := new(struct{ Value AppState }) @@ -309,7 +310,7 @@ func (wd *wdaDriver) IsLocked() (locked bool, err error) { // [[FBRoute GET:@"/wda/locked"] respondWithTarget:self action:@selector(handleIsLocked:)] // [[FBRoute GET:@"/wda/locked"].withoutSession var rawResp rawResponse - if rawResp, err = wd.httpGET("/session", wd.sessionId, "/wda/locked"); err != nil { + if rawResp, err = wd.httpGET("/session", wd.session.ID, "/wda/locked"); err != nil { return false, err } if locked, err = rawResp.valueConvertToBool(); err != nil { @@ -321,14 +322,14 @@ func (wd *wdaDriver) IsLocked() (locked bool, err error) { func (wd *wdaDriver) Unlock() (err error) { // [[FBRoute POST:@"/wda/unlock"] respondWithTarget:self action:@selector(handleUnlock:)] // [[FBRoute POST:@"/wda/unlock"].withoutSession - _, err = wd.httpPOST(nil, "/session", wd.sessionId, "/wda/unlock") + _, err = wd.httpPOST(nil, "/session", wd.session.ID, "/wda/unlock") return } func (wd *wdaDriver) Lock() (err error) { // [[FBRoute POST:@"/wda/lock"] respondWithTarget:self action:@selector(handleLock:)] // [[FBRoute POST:@"/wda/lock"].withoutSession - _, err = wd.httpPOST(nil, "/session", wd.sessionId, "/wda/lock") + _, err = wd.httpPOST(nil, "/session", wd.session.ID, "/wda/lock") return } @@ -342,7 +343,7 @@ func (wd *wdaDriver) AlertText() (text string, err error) { // [[FBRoute GET:@"/alert/text"] respondWithTarget:self action:@selector(handleAlertGetTextCommand:)] // [[FBRoute GET:@"/alert/text"].withoutSession var rawResp rawResponse - if rawResp, err = wd.httpGET("/session", wd.sessionId, "/alert/text"); err != nil { + if rawResp, err = wd.httpGET("/session", wd.session.ID, "/alert/text"); err != nil { return "", err } if text, err = rawResp.valueConvertToString(); err != nil { @@ -354,7 +355,7 @@ func (wd *wdaDriver) AlertText() (text string, err error) { func (wd *wdaDriver) AlertButtons() (btnLabels []string, err error) { // [[FBRoute GET:@"/wda/alert/buttons"] respondWithTarget:self action:@selector(handleGetAlertButtonsCommand:)] var rawResp rawResponse - if rawResp, err = wd.httpGET("/session", wd.sessionId, "/wda/alert/buttons"); err != nil { + if rawResp, err = wd.httpGET("/session", wd.session.ID, "/wda/alert/buttons"); err != nil { return nil, err } reply := new(struct{ Value []string }) @@ -390,7 +391,7 @@ func (wd *wdaDriver) AlertDismiss(label ...string) (err error) { func (wd *wdaDriver) AlertSendKeys(text string) (err error) { // [[FBRoute POST:@"/alert/text"] respondWithTarget:self action:@selector(handleAlertSetTextCommand:)] data := map[string]interface{}{"value": strings.Split(text, "")} - _, err = wd.httpPOST(data, "/session", wd.sessionId, "/alert/text") + _, err = wd.httpPOST(data, "/session", wd.session.ID, "/alert/text") return } @@ -398,7 +399,7 @@ func (wd *wdaDriver) AppLaunch(bundleId string) (err error) { // [[FBRoute POST:@"/wda/apps/launch"] respondWithTarget:self action:@selector(handleSessionAppLaunch:)] data := make(map[string]interface{}) data["bundleId"] = bundleId - _, err = wd.httpPOST(data, "/session", wd.sessionId, "/wda/apps/launch") + _, err = wd.httpPOST(data, "/session", wd.session.ID, "/wda/apps/launch") if err != nil { return errors.Wrap(code.MobileUILaunchAppError, fmt.Sprintf("wda launch failed: %v", err)) @@ -421,7 +422,7 @@ func (wd *wdaDriver) AppTerminate(bundleId string) (successful bool, err error) // [[FBRoute POST:@"/wda/apps/terminate"] respondWithTarget:self action:@selector(handleSessionAppTerminate:)] data := map[string]interface{}{"bundleId": bundleId} var rawResp rawResponse - if rawResp, err = wd.httpPOST(data, "/session", wd.sessionId, "/wda/apps/terminate"); err != nil { + if rawResp, err = wd.httpPOST(data, "/session", wd.session.ID, "/wda/apps/terminate"); err != nil { return false, err } if successful, err = rawResp.valueConvertToBool(); err != nil { @@ -433,7 +434,7 @@ func (wd *wdaDriver) AppTerminate(bundleId string) (successful bool, err error) func (wd *wdaDriver) AppActivate(bundleId string) (err error) { // [[FBRoute POST:@"/wda/apps/activate"] respondWithTarget:self action:@selector(handleSessionAppActivate:)] data := map[string]interface{}{"bundleId": bundleId} - _, err = wd.httpPOST(data, "/session", wd.sessionId, "/wda/apps/activate") + _, err = wd.httpPOST(data, "/session", wd.session.ID, "/wda/apps/activate") return } @@ -443,7 +444,7 @@ func (wd *wdaDriver) AppDeactivate(second float64) (err error) { second = 3.0 } data := map[string]interface{}{"duration": second} - _, err = wd.httpPOST(data, "/session", wd.sessionId, "/wda/deactivateApp") + _, err = wd.httpPOST(data, "/session", wd.session.ID, "/wda/deactivateApp") return } @@ -494,7 +495,7 @@ func (wd *wdaDriver) TapFloat(x, y float64, options ...ActionOption) (err error) // update data options in post data for extra WDA configurations actionOptions.updateData(data) - _, err = wd.httpPOST(data, "/session", wd.sessionId, "/wda/tap/0") + _, err = wd.httpPOST(data, "/session", wd.session.ID, "/wda/tap/0") return } @@ -508,7 +509,7 @@ func (wd *wdaDriver) DoubleTapFloat(x, y float64) (err error) { "x": wd.toScale(x), "y": wd.toScale(y), } - _, err = wd.httpPOST(data, "/session", wd.sessionId, "/wda/doubleTap") + _, err = wd.httpPOST(data, "/session", wd.session.ID, "/wda/doubleTap") return } @@ -526,7 +527,7 @@ func (wd *wdaDriver) TouchAndHoldFloat(x, y float64, second ...float64) (err err second = []float64{1.0} } data["duration"] = second[0] - _, err = wd.httpPOST(data, "/session", wd.sessionId, "/wda/touchAndHold") + _, err = wd.httpPOST(data, "/session", wd.session.ID, "/wda/touchAndHold") return } @@ -563,7 +564,7 @@ func (wd *wdaDriver) DragFloat(fromX, fromY, toX, toY float64, options ...Action // update data options in post data for extra WDA configurations actionOptions.updateData(data) // wda 43 version - _, err = wd.httpPOST(data, "/session", wd.sessionId, "/wda/drag") + _, err = wd.httpPOST(data, "/session", wd.session.ID, "/wda/drag") return } @@ -581,7 +582,7 @@ func (wd *wdaDriver) SetPasteboard(contentType PasteboardType, content string) ( "contentType": contentType, "content": base64.StdEncoding.EncodeToString([]byte(content)), } - _, err = wd.httpPOST(data, "/session", wd.sessionId, "/wda/setPasteboard") + _, err = wd.httpPOST(data, "/session", wd.session.ID, "/wda/setPasteboard") return } @@ -589,7 +590,7 @@ func (wd *wdaDriver) GetPasteboard(contentType PasteboardType) (raw *bytes.Buffe // [[FBRoute POST:@"/wda/getPasteboard"] respondWithTarget:self action:@selector(handleGetPasteboard:)] data := map[string]interface{}{"contentType": contentType} var rawResp rawResponse - if rawResp, err = wd.httpPOST(data, "/session", wd.sessionId, "/wda/getPasteboard"); err != nil { + if rawResp, err = wd.httpPOST(data, "/session", wd.session.ID, "/wda/getPasteboard"); err != nil { return nil, err } if raw, err = rawResp.valueDecodeAsBase64(); err != nil { @@ -614,7 +615,7 @@ func (wd *wdaDriver) SendKeys(text string, options ...ActionOption) (err error) // new data options in post data for extra WDA configurations actionOptions.updateData(data) - _, err = wd.httpPOST(data, "/session", wd.sessionId, "/wda/keys") + _, err = wd.httpPOST(data, "/session", wd.session.ID, "/wda/keys") return } @@ -659,14 +660,14 @@ func (wd *wdaDriver) PressBack(options ...ActionOption) (err error) { // update data options in post data for extra WDA configurations actionOptions.updateData(data) - _, err = wd.httpPOST(data, "/session", wd.sessionId, "/wda/dragfromtoforduration") + _, err = wd.httpPOST(data, "/session", wd.session.ID, "/wda/dragfromtoforduration") return } func (wd *wdaDriver) PressButton(devBtn DeviceButton) (err error) { // [[FBRoute POST:@"/wda/pressButton"] respondWithTarget:self action:@selector(handlePressButtonCommand:)] data := map[string]interface{}{"name": devBtn} - _, err = wd.httpPOST(data, "/session", wd.sessionId, "/wda/pressButton") + _, err = wd.httpPOST(data, "/session", wd.session.ID, "/wda/pressButton") return } @@ -698,7 +699,7 @@ func (wd *wdaDriver) StopCamera() (err error) { func (wd *wdaDriver) Orientation() (orientation Orientation, err error) { // [[FBRoute GET:@"/orientation"] respondWithTarget:self action:@selector(handleGetOrientation:)] var rawResp rawResponse - if rawResp, err = wd.httpGET("/session", wd.sessionId, "/orientation"); err != nil { + if rawResp, err = wd.httpGET("/session", wd.session.ID, "/orientation"); err != nil { return "", err } reply := new(struct{ Value Orientation }) @@ -712,14 +713,14 @@ func (wd *wdaDriver) Orientation() (orientation Orientation, err error) { func (wd *wdaDriver) SetOrientation(orientation Orientation) (err error) { // [[FBRoute POST:@"/orientation"] respondWithTarget:self action:@selector(handleSetOrientation:)] data := map[string]interface{}{"orientation": orientation} - _, err = wd.httpPOST(data, "/session", wd.sessionId, "/orientation") + _, err = wd.httpPOST(data, "/session", wd.session.ID, "/orientation") return } func (wd *wdaDriver) Rotation() (rotation Rotation, err error) { // [[FBRoute GET:@"/rotation"] respondWithTarget:self action:@selector(handleGetRotation:)] var rawResp rawResponse - if rawResp, err = wd.httpGET("/session", wd.sessionId, "/rotation"); err != nil { + if rawResp, err = wd.httpGET("/session", wd.session.ID, "/rotation"); err != nil { return Rotation{}, err } reply := new(struct{ Value Rotation }) @@ -732,7 +733,7 @@ func (wd *wdaDriver) Rotation() (rotation Rotation, err error) { func (wd *wdaDriver) SetRotation(rotation Rotation) (err error) { // [[FBRoute POST:@"/rotation"] respondWithTarget:self action:@selector(handleSetRotation:)] - _, err = wd.httpPOST(rotation, "/session", wd.sessionId, "/rotation") + _, err = wd.httpPOST(rotation, "/session", wd.session.ID, "/rotation") return } @@ -740,7 +741,7 @@ 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 rawResponse - if rawResp, err = wd.httpGET("/session", wd.sessionId, "/screenshot"); err != nil { + if rawResp, err = wd.httpGET("/session", wd.session.ID, "/screenshot"); err != nil { return nil, errors.Wrap(code.IOSScreenShotError, fmt.Sprintf("get WDA screenshot data failed: %v", err)) } @@ -755,7 +756,7 @@ func (wd *wdaDriver) Screenshot() (raw *bytes.Buffer, err error) { func (wd *wdaDriver) Source(srcOpt ...SourceOption) (source string, err error) { // [[FBRoute GET:@"/source"] respondWithTarget:self action:@selector(handleGetSourceCommand:)] // [[FBRoute GET:@"/source"].withoutSession - tmp, _ := url.Parse(wd.concatURL(nil, "/session", wd.sessionId)) + tmp, _ := url.Parse(wd.concatURL(nil, "/session", wd.session.ID)) toJsonRaw := false if len(srcOpt) != 0 { q := tmp.Query() @@ -798,7 +799,7 @@ func (wd *wdaDriver) AccessibleSource() (source string, err error) { // [[FBRoute GET:@"/wda/accessibleSource"] respondWithTarget:self action:@selector(handleGetAccessibleSourceCommand:)] // [[FBRoute GET:@"/wda/accessibleSource"].withoutSession var rawResp rawResponse - if rawResp, err = wd.httpGET("/session", wd.sessionId, "/wda/accessibleSource"); err != nil { + if rawResp, err = wd.httpGET("/session", wd.session.ID, "/wda/accessibleSource"); err != nil { return "", err } var jr builtinJSON.RawMessage @@ -818,7 +819,7 @@ func (wd *wdaDriver) HealthCheck() (err error) { func (wd *wdaDriver) GetAppiumSettings() (settings map[string]interface{}, err error) { // [[FBRoute GET:@"/appium/settings"] respondWithTarget:self action:@selector(handleGetSettings:)] var rawResp rawResponse - if rawResp, err = wd.httpGET("/session", wd.sessionId, "/appium/settings"); err != nil { + if rawResp, err = wd.httpGET("/session", wd.session.ID, "/appium/settings"); err != nil { return nil, err } reply := new(struct{ Value map[string]interface{} }) @@ -833,7 +834,7 @@ func (wd *wdaDriver) SetAppiumSettings(settings map[string]interface{}) (ret map // [[FBRoute POST:@"/appium/settings"] respondWithTarget:self action:@selector(handleSetSettings:)] data := map[string]interface{}{"settings": settings} var rawResp rawResponse - if rawResp, err = wd.httpPOST(data, "/session", wd.sessionId, "/appium/settings"); err != nil { + if rawResp, err = wd.httpPOST(data, "/session", wd.session.ID, "/appium/settings"); err != nil { return nil, err } reply := new(struct{ Value map[string]interface{} }) diff --git a/hrp/step_mobile_ui.go b/hrp/step_mobile_ui.go index 41d9b140..5890eec4 100644 --- a/hrp/step_mobile_ui.go +++ b/hrp/step_mobile_ui.go @@ -652,7 +652,7 @@ func runStepMobileUI(s *SessionRunner, step *TStep) (stepResult *StepResult, err for key, value := range session.GetAll() { attachments[key] = value } - session.Clear() // clear step cache + session.Init() // clear step cache stepResult.Attachments = attachments }()