refactor: move sessionId to driver.session

This commit is contained in:
lilong.129
2024-09-02 14:33:49 +08:00
parent 08cb50b698
commit bfe46fa1d6
9 changed files with 78 additions and 79 deletions

View File

@@ -42,6 +42,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()
err = errDriverNotImplemented err = errDriverNotImplemented
return return
} }

View File

@@ -94,6 +94,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()
return SessionInfo{}, errDriverNotImplemented return SessionInfo{}, errDriverNotImplemented
} }

View File

@@ -62,7 +62,7 @@ func TestNewDriver(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
t.Log(driver.sessionId) t.Log(driver.session.ID)
} }
func TestDriver_Quit(t *testing.T) { func TestDriver_Quit(t *testing.T) {

View File

@@ -49,11 +49,10 @@ func NewUIADriver(capabilities Capabilities, urlPrefix string) (driver *uiaDrive
} }
driver.client = convertToHTTPClient(conn) driver.client = convertToHTTPClient(conn)
session, err := driver.NewSession(capabilities) _, err = driver.NewSession(capabilities)
if err != nil { if err != nil {
return nil, errors.Wrap(err, "create UIAutomator session failed") return nil, errors.Wrap(err, "create UIAutomator session failed")
} }
driver.sessionId = session.SessionId
return driver, nil return driver, nil
} }
@@ -91,7 +90,7 @@ func (ud *uiaDriver) resetDriver() error {
return err return err
} }
ud.client = newUIADriver.client ud.client = newUIADriver.client
ud.sessionId = newUIADriver.sessionId ud.session.ID = newUIADriver.session.ID
return nil return nil
} }
@@ -104,14 +103,14 @@ func (ud *uiaDriver) httpRequest(method string, rawURL string, rawBody []byte, d
} }
// wait for UIA2 server to resume automatically // wait for UIA2 server to resume automatically
time.Sleep(3 * time.Second) time.Sleep(3 * time.Second)
oldSessionID := ud.sessionId oldSessionID := ud.session.ID
if err2 := ud.resetDriver(); err2 != nil { if err2 := ud.resetDriver(); err2 != nil {
log.Err(err2).Msgf("failed to reset uia2 driver, retry count: %v", retryCount) log.Err(err2).Msgf("failed to reset uia2 driver, retry count: %v", retryCount)
continue 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 != "" { if oldSessionID != "" {
rawURL = strings.Replace(rawURL, oldSessionID, ud.sessionId, 1) rawURL = strings.Replace(rawURL, oldSessionID, ud.session.ID, 1)
} }
} }
return return
@@ -156,16 +155,18 @@ 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.ID = sessionID
// d.sessionIdCache[sessionID] = true // d.sessionIdCache[sessionID] = true
return SessionInfo{SessionId: sessionID}, nil return SessionInfo{SessionId: sessionID}, nil
} }
func (ud *uiaDriver) DeleteSession() (err error) { func (ud *uiaDriver) DeleteSession() (err error) {
if ud.sessionId == "" { if ud.session.ID == "" {
return nil return nil
} }
if _, err = ud.httpDELETE("/session", ud.sessionId); err == nil { if _, err = ud.httpDELETE("/session", ud.session.ID); err == nil {
ud.sessionId = "" ud.session.ID = ""
} }
return err return err
@@ -192,7 +193,7 @@ func (ud *uiaDriver) Status() (deviceStatus DeviceStatus, err error) {
func (ud *uiaDriver) DeviceInfo() (deviceInfo DeviceInfo, err error) { func (ud *uiaDriver) DeviceInfo() (deviceInfo DeviceInfo, err error) {
// register(getHandler, new GetDeviceInfo("/wd/hub/session/:sessionId/appium/device/info")) // register(getHandler, new GetDeviceInfo("/wd/hub/session/:sessionId/appium/device/info"))
var rawResp rawResponse 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 return DeviceInfo{}, err
} }
reply := new(struct{ Value struct{ DeviceInfo } }) 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) { func (ud *uiaDriver) BatteryInfo() (batteryInfo BatteryInfo, err error) {
// register(getHandler, new GetBatteryInfo("/wd/hub/session/:sessionId/appium/device/battery_info")) // register(getHandler, new GetBatteryInfo("/wd/hub/session/:sessionId/appium/device/battery_info"))
var rawResp rawResponse 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 return BatteryInfo{}, err
} }
reply := new(struct{ Value struct{ BatteryInfo } }) reply := new(struct{ Value struct{ BatteryInfo } })
@@ -226,7 +227,7 @@ func (ud *uiaDriver) WindowSize() (size Size, err error) {
size = *ud.windowSize size = *ud.windowSize
} else { } else {
var rawResp rawResponse 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") return Size{}, errors.Wrap(err, "get window size failed with uiautomator2")
} }
reply := new(struct{ Value struct{ Size } }) 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. // PressBack simulates a short press on the BACK button.
func (ud *uiaDriver) PressBack(options ...ActionOption) (err error) { func (ud *uiaDriver) PressBack(options ...ActionOption) (err error) {
// register(postHandler, new PressBack("/wd/hub/session/:sessionId/back")) // 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 return
} }
@@ -275,14 +276,14 @@ func (ud *uiaDriver) PressKeyCodes(keyCode KeyCode, metaState KeyMeta, flags ...
if len(flags) != 0 { if len(flags) != 0 {
data["flags"] = 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 return
} }
func (ud *uiaDriver) Orientation() (orientation Orientation, err error) { func (ud *uiaDriver) Orientation() (orientation Orientation, err error) {
// [[FBRoute GET:@"/orientation"] respondWithTarget:self action:@selector(handleGetOrientation:)] // [[FBRoute GET:@"/orientation"] respondWithTarget:self action:@selector(handleGetOrientation:)]
var rawResp rawResponse 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 return "", err
} }
reply := new(struct{ Value Orientation }) 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 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 // update data options in post data for extra uiautomator configurations
actionOptions.updateData(data) actionOptions.updateData(data)
_, err = ud.httpPOST(data, "/session", ud.sessionId, "actions/tap") _, err = ud.httpPOST(data, "/session", ud.session.ID, "actions/tap")
return err return err
} }
@@ -377,7 +378,7 @@ func (ud *uiaDriver) TouchAndHoldFloat(x, y float64, second ...float64) (err err
"duration": int(second[0] * 1000), "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 return
} }
@@ -413,7 +414,7 @@ func (ud *uiaDriver) DragFloat(fromX, fromY, toX, toY float64, options ...Action
actionOptions.updateData(data) actionOptions.updateData(data)
// register(postHandler, new Drag("/wd/hub/session/:sessionId/touch/drag")) // 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 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 // update data options in post data for extra uiautomator configurations
actionOptions.updateData(data) actionOptions.updateData(data)
_, err := ud.httpPOST(data, "/session", ud.sessionId, "actions/swipe") _, err := ud.httpPOST(data, "/session", ud.session.ID, "actions/swipe")
return err return err
} }
@@ -481,7 +482,7 @@ func (ud *uiaDriver) SetPasteboard(contentType PasteboardType, content string) (
"content": base64.StdEncoding.EncodeToString([]byte(content)), "content": base64.StdEncoding.EncodeToString([]byte(content)),
} }
// register(postHandler, new SetClipboard("/wd/hub/session/:sessionId/appium/device/set_clipboard")) // 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 return
} }
@@ -494,7 +495,7 @@ func (ud *uiaDriver) GetPasteboard(contentType PasteboardType) (raw *bytes.Buffe
"contentType": contentType[0], "contentType": contentType[0],
} }
var rawResp rawResponse 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 return
} }
reply := new(struct{ Value string }) 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 // new data options in post data for extra uiautomator configurations
actionOptions.updateData(data) actionOptions.updateData(data)
_, err = ud.httpPOST(data, "/session", ud.sessionId, "/keys") _, err = ud.httpPOST(data, "/session", ud.session.ID, "/keys")
} }
return 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 // new data options in post data for extra uiautomator configurations
actionOptions.updateData(data) actionOptions.updateData(data)
_, err = ud.httpPOST(data, "/session", ud.sessionId, "/actions/keys") _, err = ud.httpPOST(data, "/session", ud.session.ID, "/actions/keys")
return return
} }
@@ -593,7 +594,7 @@ func (ud *uiaDriver) Input(text string, options ...ActionOption) (err error) {
func (ud *uiaDriver) Rotation() (rotation Rotation, err error) { func (ud *uiaDriver) Rotation() (rotation Rotation, err error) {
// register(getHandler, new GetRotation("/wd/hub/session/:sessionId/rotation")) // register(getHandler, new GetRotation("/wd/hub/session/:sessionId/rotation"))
var rawResp rawResponse 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 return Rotation{}, err
} }
reply := new(struct{ Value Rotation }) 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) { func (ud *uiaDriver) Source(srcOpt ...SourceOption) (source string, err error) {
// register(getHandler, new Source("/wd/hub/session/:sessionId/source")) // register(getHandler, new Source("/wd/hub/session/:sessionId/source"))
var rawResp rawResponse 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 return "", err
} }
reply := new(struct{ Value string }) reply := new(struct{ Value string })

View File

@@ -16,6 +16,7 @@ import (
) )
type DriverSession struct { type DriverSession struct {
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 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) d.requests = append(d.requests, driverResult)
} }
func (d *DriverSession) Clear() { func (d *DriverSession) Init() {
d.screenResults = make(map[string]*ScreenResult) d.screenResults = make(map[string]*ScreenResult)
d.requests = nil d.requests = nil
d.e2eDelay = nil d.e2eDelay = nil
@@ -61,7 +62,6 @@ func (d *DriverSession) GetAll() map[string]interface{} {
type Driver struct { type Driver struct {
urlPrefix *url.URL urlPrefix *url.URL
sessionId string
client *http.Client client *http.Client
// cache to avoid repeated query // cache to avoid repeated query

View File

@@ -27,7 +27,6 @@ func newDriverExt(device IDevice, driver IWebDriver, options ...DriverOption) (d
option(driverOptions) option(driverOptions)
} }
driver.GetSession().Clear()
dExt = &DriverExt{ dExt = &DriverExt{
Device: device, Device: device,
Driver: driver, Driver: driver,

View File

@@ -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 { if wd.urlPrefix, err = url.Parse(fmt.Sprintf("http://%s:%d", host, localPort)); err != nil {
return nil, errors.Wrap(code.IOSDeviceHTTPDriverError, err.Error()) return nil, errors.Wrap(code.IOSDeviceHTTPDriverError, err.Error())
} }
var sessionInfo SessionInfo if _, err = wd.NewSession(capabilities); err != nil {
if sessionInfo, err = wd.NewSession(capabilities); err != nil {
return nil, errors.Wrap(code.IOSDeviceHTTPDriverError, err.Error()) return nil, errors.Wrap(code.IOSDeviceHTTPDriverError, err.Error())
} }
wd.sessionId = sessionInfo.SessionId
if wd.mjpegHTTPConn, err = net.Dial( if wd.mjpegHTTPConn, err = net.Dial(
"tcp", "tcp",
@@ -697,11 +695,9 @@ func (dev *IOSDevice) NewUSBDriver(capabilities Capabilities) (driver IWebDriver
if wd.urlPrefix, err = url.Parse("http://" + dev.UDID); err != nil { if wd.urlPrefix, err = url.Parse("http://" + dev.UDID); err != nil {
return nil, errors.Wrap(code.IOSDeviceUSBDriverError, err.Error()) return nil, errors.Wrap(code.IOSDeviceUSBDriverError, err.Error())
} }
var sessionInfo SessionInfo if _, err = wd.NewSession(capabilities); err != nil {
if sessionInfo, err = wd.NewSession(capabilities); err != nil {
return nil, errors.Wrap(code.IOSDeviceUSBDriverError, err.Error()) return nil, errors.Wrap(code.IOSDeviceUSBDriverError, err.Error())
} }
wd.sessionId = sessionInfo.SessionId
// init WDA scale // init WDA scale
if wd.scale, err = wd.Scale(); err != nil { if wd.scale, err = wd.Scale(); err != nil {

View File

@@ -37,11 +37,10 @@ func (wd *wdaDriver) resetSession() error {
capabilities := NewCapabilities() capabilities := NewCapabilities()
capabilities.WithDefaultAlertAction(AlertActionAccept) capabilities.WithDefaultAlertAction(AlertActionAccept)
sessionInfo, err := wd.NewSession(capabilities) _, err := wd.NewSession(capabilities)
if err != nil { if err != nil {
return err return err
} }
wd.sessionId = sessionInfo.SessionId
return nil 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 // TODO: polling WDA to check if resumed automatically
time.Sleep(5 * time.Second) time.Sleep(5 * time.Second)
oldSessionID := wd.sessionId oldSessionID := wd.session.ID
if err2 := wd.resetSession(); err2 != nil { if err2 := wd.resetSession(); err2 != nil {
log.Err(err2).Msgf("failed to reset wda driver, retry count: %v", retryCount) log.Err(err2).Msgf("failed to reset wda driver, retry count: %v", retryCount)
continue 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 != "" { if oldSessionID != "" {
rawURL = strings.Replace(rawURL, oldSessionID, wd.sessionId, 1) rawURL = strings.Replace(rawURL, oldSessionID, wd.session.ID, 1)
} }
} }
return return
@@ -109,6 +108,8 @@ 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.ID = sessionInfo.SessionId
return return
} }
@@ -128,7 +129,7 @@ func (wd *wdaDriver) DeleteSession() (err error) {
} }
// [[FBRoute DELETE:@""] respondWithTarget:self action:@selector(handleDeleteSession:)] // [[FBRoute DELETE:@""] respondWithTarget:self action:@selector(handleDeleteSession:)]
_, err = wd.httpDELETE("/session", wd.sessionId) _, err = wd.httpDELETE("/session", wd.session.ID)
return 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"] respondWithTarget:self action:@selector(handleGetDeviceInfo:)]
// [[FBRoute GET:@"/wda/device/info"].withoutSession // [[FBRoute GET:@"/wda/device/info"].withoutSession
var rawResp rawResponse 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 return DeviceInfo{}, err
} }
reply := new(struct{ Value struct{ DeviceInfo } }) 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"] respondWithTarget:self action:@selector(handleGetLocation:)]
// [[FBRoute GET:@"/wda/device/location"].withoutSession // [[FBRoute GET:@"/wda/device/location"].withoutSession
var rawResp rawResponse 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 return Location{}, err
} }
reply := new(struct{ Value struct{ Location } }) 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) { func (wd *wdaDriver) BatteryInfo() (batteryInfo BatteryInfo, err error) {
// [[FBRoute GET:@"/wda/batteryInfo"] respondWithTarget:self action:@selector(handleGetBatteryInfo:)] // [[FBRoute GET:@"/wda/batteryInfo"] respondWithTarget:self action:@selector(handleGetBatteryInfo:)]
var rawResp rawResponse 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 return BatteryInfo{}, err
} }
reply := new(struct{ Value struct{ BatteryInfo } }) reply := new(struct{ Value struct{ BatteryInfo } })
@@ -196,7 +197,7 @@ func (wd *wdaDriver) WindowSize() (size Size, err error) {
size = *wd.windowSize size = *wd.windowSize
} else { } else {
var rawResp rawResponse 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") return Size{}, errors.Wrap(err, "get window size failed with wda")
} }
reply := new(struct{ Value struct{ Size } }) 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) { func (wd *wdaDriver) Screen() (screen Screen, err error) {
// [[FBRoute GET:@"/wda/screen"] respondWithTarget:self action:@selector(handleGetScreen:)] // [[FBRoute GET:@"/wda/screen"] respondWithTarget:self action:@selector(handleGetScreen:)]
var rawResp rawResponse 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 return Screen{}, err
} }
reply := new(struct{ Value struct{ Screen } }) 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"] respondWithTarget:self action:@selector(handleActiveAppInfo:)]
// [[FBRoute GET:@"/wda/activeAppInfo"].withoutSession // [[FBRoute GET:@"/wda/activeAppInfo"].withoutSession
var rawResp rawResponse 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 return AppInfo{}, err
} }
reply := new(struct{ Value struct{ AppInfo } }) 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) { func (wd *wdaDriver) ActiveAppsList() (appsList []AppBaseInfo, err error) {
// [[FBRoute GET:@"/wda/apps/list"] respondWithTarget:self action:@selector(handleGetActiveAppsList:)] // [[FBRoute GET:@"/wda/apps/list"] respondWithTarget:self action:@selector(handleGetActiveAppsList:)]
var rawResp rawResponse 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 return nil, err
} }
reply := new(struct{ Value []AppBaseInfo }) 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:)] // [[FBRoute POST:@"/wda/apps/state"] respondWithTarget:self action:@selector(handleSessionAppState:)]
data := map[string]interface{}{"bundleId": bundleId} data := map[string]interface{}{"bundleId": bundleId}
var rawResp rawResponse 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 return 0, err
} }
reply := new(struct{ Value AppState }) 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"] respondWithTarget:self action:@selector(handleIsLocked:)]
// [[FBRoute GET:@"/wda/locked"].withoutSession // [[FBRoute GET:@"/wda/locked"].withoutSession
var rawResp rawResponse 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 return false, err
} }
if locked, err = rawResp.valueConvertToBool(); err != nil { 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) { func (wd *wdaDriver) Unlock() (err error) {
// [[FBRoute POST:@"/wda/unlock"] respondWithTarget:self action:@selector(handleUnlock:)] // [[FBRoute POST:@"/wda/unlock"] respondWithTarget:self action:@selector(handleUnlock:)]
// [[FBRoute POST:@"/wda/unlock"].withoutSession // [[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 return
} }
func (wd *wdaDriver) Lock() (err error) { func (wd *wdaDriver) Lock() (err error) {
// [[FBRoute POST:@"/wda/lock"] respondWithTarget:self action:@selector(handleLock:)] // [[FBRoute POST:@"/wda/lock"] respondWithTarget:self action:@selector(handleLock:)]
// [[FBRoute POST:@"/wda/lock"].withoutSession // [[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 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"] respondWithTarget:self action:@selector(handleAlertGetTextCommand:)]
// [[FBRoute GET:@"/alert/text"].withoutSession // [[FBRoute GET:@"/alert/text"].withoutSession
var rawResp rawResponse 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 return "", err
} }
if text, err = rawResp.valueConvertToString(); err != nil { 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) { func (wd *wdaDriver) AlertButtons() (btnLabels []string, err error) {
// [[FBRoute GET:@"/wda/alert/buttons"] respondWithTarget:self action:@selector(handleGetAlertButtonsCommand:)] // [[FBRoute GET:@"/wda/alert/buttons"] respondWithTarget:self action:@selector(handleGetAlertButtonsCommand:)]
var rawResp rawResponse 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 return nil, err
} }
reply := new(struct{ Value []string }) 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) { func (wd *wdaDriver) AlertSendKeys(text string) (err error) {
// [[FBRoute POST:@"/alert/text"] respondWithTarget:self action:@selector(handleAlertSetTextCommand:)] // [[FBRoute POST:@"/alert/text"] respondWithTarget:self action:@selector(handleAlertSetTextCommand:)]
data := map[string]interface{}{"value": strings.Split(text, "")} 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 return
} }
@@ -398,7 +399,7 @@ func (wd *wdaDriver) AppLaunch(bundleId string) (err error) {
// [[FBRoute POST:@"/wda/apps/launch"] respondWithTarget:self action:@selector(handleSessionAppLaunch:)] // [[FBRoute POST:@"/wda/apps/launch"] respondWithTarget:self action:@selector(handleSessionAppLaunch:)]
data := make(map[string]interface{}) data := make(map[string]interface{})
data["bundleId"] = bundleId 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 { if err != nil {
return errors.Wrap(code.MobileUILaunchAppError, return errors.Wrap(code.MobileUILaunchAppError,
fmt.Sprintf("wda launch failed: %v", err)) 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:)] // [[FBRoute POST:@"/wda/apps/terminate"] respondWithTarget:self action:@selector(handleSessionAppTerminate:)]
data := map[string]interface{}{"bundleId": bundleId} data := map[string]interface{}{"bundleId": bundleId}
var rawResp rawResponse 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 return false, err
} }
if successful, err = rawResp.valueConvertToBool(); err != nil { 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) { func (wd *wdaDriver) AppActivate(bundleId string) (err error) {
// [[FBRoute POST:@"/wda/apps/activate"] respondWithTarget:self action:@selector(handleSessionAppActivate:)] // [[FBRoute POST:@"/wda/apps/activate"] respondWithTarget:self action:@selector(handleSessionAppActivate:)]
data := map[string]interface{}{"bundleId": bundleId} 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 return
} }
@@ -443,7 +444,7 @@ func (wd *wdaDriver) AppDeactivate(second float64) (err error) {
second = 3.0 second = 3.0
} }
data := map[string]interface{}{"duration": second} 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 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 // update data options in post data for extra WDA configurations
actionOptions.updateData(data) 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 return
} }
@@ -508,7 +509,7 @@ func (wd *wdaDriver) DoubleTapFloat(x, y float64) (err error) {
"x": wd.toScale(x), "x": wd.toScale(x),
"y": wd.toScale(y), "y": wd.toScale(y),
} }
_, err = wd.httpPOST(data, "/session", wd.sessionId, "/wda/doubleTap") _, err = wd.httpPOST(data, "/session", wd.session.ID, "/wda/doubleTap")
return return
} }
@@ -526,7 +527,7 @@ func (wd *wdaDriver) TouchAndHoldFloat(x, y float64, second ...float64) (err err
second = []float64{1.0} second = []float64{1.0}
} }
data["duration"] = second[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 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 // update data options in post data for extra WDA configurations
actionOptions.updateData(data) actionOptions.updateData(data)
// wda 43 version // wda 43 version
_, err = wd.httpPOST(data, "/session", wd.sessionId, "/wda/drag") _, err = wd.httpPOST(data, "/session", wd.session.ID, "/wda/drag")
return return
} }
@@ -581,7 +582,7 @@ func (wd *wdaDriver) SetPasteboard(contentType PasteboardType, content string) (
"contentType": contentType, "contentType": contentType,
"content": base64.StdEncoding.EncodeToString([]byte(content)), "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 return
} }
@@ -589,7 +590,7 @@ func (wd *wdaDriver) GetPasteboard(contentType PasteboardType) (raw *bytes.Buffe
// [[FBRoute POST:@"/wda/getPasteboard"] respondWithTarget:self action:@selector(handleGetPasteboard:)] // [[FBRoute POST:@"/wda/getPasteboard"] respondWithTarget:self action:@selector(handleGetPasteboard:)]
data := map[string]interface{}{"contentType": contentType} data := map[string]interface{}{"contentType": contentType}
var rawResp rawResponse 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 return nil, err
} }
if raw, err = rawResp.valueDecodeAsBase64(); err != nil { 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 // new data options in post data for extra WDA configurations
actionOptions.updateData(data) actionOptions.updateData(data)
_, err = wd.httpPOST(data, "/session", wd.sessionId, "/wda/keys") _, err = wd.httpPOST(data, "/session", wd.session.ID, "/wda/keys")
return return
} }
@@ -659,14 +660,14 @@ func (wd *wdaDriver) PressBack(options ...ActionOption) (err error) {
// update data options in post data for extra WDA configurations // update data options in post data for extra WDA configurations
actionOptions.updateData(data) actionOptions.updateData(data)
_, err = wd.httpPOST(data, "/session", wd.sessionId, "/wda/dragfromtoforduration") _, err = wd.httpPOST(data, "/session", wd.session.ID, "/wda/dragfromtoforduration")
return return
} }
func (wd *wdaDriver) PressButton(devBtn DeviceButton) (err error) { func (wd *wdaDriver) PressButton(devBtn DeviceButton) (err error) {
// [[FBRoute POST:@"/wda/pressButton"] respondWithTarget:self action:@selector(handlePressButtonCommand:)] // [[FBRoute POST:@"/wda/pressButton"] respondWithTarget:self action:@selector(handlePressButtonCommand:)]
data := map[string]interface{}{"name": devBtn} 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 return
} }
@@ -698,7 +699,7 @@ func (wd *wdaDriver) StopCamera() (err error) {
func (wd *wdaDriver) Orientation() (orientation Orientation, err error) { func (wd *wdaDriver) Orientation() (orientation Orientation, err error) {
// [[FBRoute GET:@"/orientation"] respondWithTarget:self action:@selector(handleGetOrientation:)] // [[FBRoute GET:@"/orientation"] respondWithTarget:self action:@selector(handleGetOrientation:)]
var rawResp rawResponse 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 return "", err
} }
reply := new(struct{ Value Orientation }) 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) { func (wd *wdaDriver) SetOrientation(orientation Orientation) (err error) {
// [[FBRoute POST:@"/orientation"] respondWithTarget:self action:@selector(handleSetOrientation:)] // [[FBRoute POST:@"/orientation"] respondWithTarget:self action:@selector(handleSetOrientation:)]
data := map[string]interface{}{"orientation": orientation} data := map[string]interface{}{"orientation": orientation}
_, err = wd.httpPOST(data, "/session", wd.sessionId, "/orientation") _, err = wd.httpPOST(data, "/session", wd.session.ID, "/orientation")
return return
} }
func (wd *wdaDriver) Rotation() (rotation Rotation, err error) { func (wd *wdaDriver) Rotation() (rotation Rotation, err error) {
// [[FBRoute GET:@"/rotation"] respondWithTarget:self action:@selector(handleGetRotation:)] // [[FBRoute GET:@"/rotation"] respondWithTarget:self action:@selector(handleGetRotation:)]
var rawResp rawResponse 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 return Rotation{}, err
} }
reply := new(struct{ Value Rotation }) 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) { func (wd *wdaDriver) SetRotation(rotation Rotation) (err error) {
// [[FBRoute POST:@"/rotation"] respondWithTarget:self action:@selector(handleSetRotation:)] // [[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 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"] respondWithTarget:self action:@selector(handleGetScreenshot:)]
// [[FBRoute GET:@"/screenshot"].withoutSession respondWithTarget:self action:@selector(handleGetScreenshot:)] // [[FBRoute GET:@"/screenshot"].withoutSession respondWithTarget:self action:@selector(handleGetScreenshot:)]
var rawResp rawResponse 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, return nil, errors.Wrap(code.IOSScreenShotError,
fmt.Sprintf("get WDA screenshot data failed: %v", err)) 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) { func (wd *wdaDriver) Source(srcOpt ...SourceOption) (source string, err error) {
// [[FBRoute GET:@"/source"] respondWithTarget:self action:@selector(handleGetSourceCommand:)] // [[FBRoute GET:@"/source"] respondWithTarget:self action:@selector(handleGetSourceCommand:)]
// [[FBRoute GET:@"/source"].withoutSession // [[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 toJsonRaw := false
if len(srcOpt) != 0 { if len(srcOpt) != 0 {
q := tmp.Query() 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"] respondWithTarget:self action:@selector(handleGetAccessibleSourceCommand:)]
// [[FBRoute GET:@"/wda/accessibleSource"].withoutSession // [[FBRoute GET:@"/wda/accessibleSource"].withoutSession
var rawResp rawResponse 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 return "", err
} }
var jr builtinJSON.RawMessage var jr builtinJSON.RawMessage
@@ -818,7 +819,7 @@ func (wd *wdaDriver) HealthCheck() (err error) {
func (wd *wdaDriver) GetAppiumSettings() (settings map[string]interface{}, err error) { func (wd *wdaDriver) GetAppiumSettings() (settings map[string]interface{}, err error) {
// [[FBRoute GET:@"/appium/settings"] respondWithTarget:self action:@selector(handleGetSettings:)] // [[FBRoute GET:@"/appium/settings"] respondWithTarget:self action:@selector(handleGetSettings:)]
var rawResp rawResponse 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 return nil, err
} }
reply := new(struct{ Value map[string]interface{} }) 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:)] // [[FBRoute POST:@"/appium/settings"] respondWithTarget:self action:@selector(handleSetSettings:)]
data := map[string]interface{}{"settings": settings} data := map[string]interface{}{"settings": settings}
var rawResp rawResponse 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 return nil, err
} }
reply := new(struct{ Value map[string]interface{} }) reply := new(struct{ Value map[string]interface{} })

View File

@@ -652,7 +652,7 @@ func runStepMobileUI(s *SessionRunner, step *TStep) (stepResult *StepResult, err
for key, value := range session.GetAll() { for key, value := range session.GetAll() {
attachments[key] = value attachments[key] = value
} }
session.Clear() // clear step cache session.Init() // clear step cache
stepResult.Attachments = attachments stepResult.Attachments = attachments
}() }()