mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-11 01:50:31 +08:00
feat: support to reset session automatically when crashed
This commit is contained in:
@@ -1,5 +1,12 @@
|
||||
# Release History
|
||||
|
||||
## v4.3.5 (2023-07-20)
|
||||
|
||||
**go version**
|
||||
|
||||
- feat: support to reset driver automatically when uia2 crashed
|
||||
- feat: support to reset session when wda request failed
|
||||
|
||||
## v4.3.4 (2023-06-01)
|
||||
|
||||
**go version**
|
||||
|
||||
@@ -46,12 +46,10 @@ func NewUIADriver(capabilities Capabilities, urlPrefix string) (driver *uiaDrive
|
||||
driver.client = convertToHTTPClient(conn)
|
||||
|
||||
session, err := driver.NewSession(capabilities)
|
||||
if err == nil {
|
||||
driver.sessionId = session.SessionId
|
||||
} else {
|
||||
log.Warn().Msg(
|
||||
"create UIAutomator session failed, use adb driver instead")
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "create UIAutomator session failed")
|
||||
}
|
||||
driver.sessionId = session.SessionId
|
||||
return driver, nil
|
||||
}
|
||||
|
||||
@@ -87,7 +85,7 @@ func (ud *uiaDriver) NewSession(capabilities Capabilities) (sessionInfo SessionI
|
||||
// register(postHandler, new NewSession("/wd/hub/session"))
|
||||
var rawResp rawResponse
|
||||
data := map[string]interface{}{"capabilities": capabilities}
|
||||
if rawResp, err = ud.httpPOST(data, "/session"); err != nil {
|
||||
if rawResp, err = ud.uia2HttpPOST(data, "/session"); err != nil {
|
||||
return SessionInfo{SessionId: ""}, err
|
||||
}
|
||||
reply := new(struct{ Value struct{ SessionId string } })
|
||||
@@ -103,7 +101,7 @@ func (ud *uiaDriver) DeleteSession() (err error) {
|
||||
if ud.sessionId == "" {
|
||||
return nil
|
||||
}
|
||||
if _, err = ud.httpDELETE("/session", ud.sessionId); err == nil {
|
||||
if _, err = ud.uia2HttpDELETE("/session", ud.sessionId); err == nil {
|
||||
ud.sessionId = ""
|
||||
}
|
||||
|
||||
@@ -113,7 +111,7 @@ func (ud *uiaDriver) DeleteSession() (err error) {
|
||||
func (ud *uiaDriver) Status() (deviceStatus DeviceStatus, err error) {
|
||||
// register(getHandler, new Status("/wd/hub/status"))
|
||||
var rawResp rawResponse
|
||||
if rawResp, err = ud.httpGET("/status"); err != nil {
|
||||
if rawResp, err = ud.uia2HttpGET("/status"); err != nil {
|
||||
return DeviceStatus{Ready: false}, err
|
||||
}
|
||||
reply := new(struct {
|
||||
@@ -131,7 +129,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.uia2HttpGET("/session", ud.sessionId, "appium/device/info"); err != nil {
|
||||
return DeviceInfo{}, err
|
||||
}
|
||||
reply := new(struct{ Value struct{ DeviceInfo } })
|
||||
@@ -145,7 +143,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.uia2HttpGET("/session", ud.sessionId, "appium/device/battery_info"); err != nil {
|
||||
return BatteryInfo{}, err
|
||||
}
|
||||
reply := new(struct{ Value struct{ BatteryInfo } })
|
||||
@@ -162,7 +160,7 @@ func (ud *uiaDriver) BatteryInfo() (batteryInfo BatteryInfo, err error) {
|
||||
func (ud *uiaDriver) WindowSize() (size Size, err error) {
|
||||
// register(getHandler, new GetDeviceSize("/wd/hub/session/:sessionId/window/:windowHandle/size"))
|
||||
var rawResp rawResponse
|
||||
if rawResp, err = ud.httpGET("/session", ud.sessionId, "window/:windowHandle/size"); err != nil {
|
||||
if rawResp, err = ud.uia2HttpGET("/session", ud.sessionId, "window/:windowHandle/size"); err != nil {
|
||||
return Size{}, errors.Wrap(err, "get window size failed with uiautomator2")
|
||||
}
|
||||
reply := new(struct{ Value struct{ Size } })
|
||||
@@ -176,7 +174,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.uia2HttpPOST(nil, "/session", ud.sessionId, "back")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -195,7 +193,7 @@ func (ud *uiaDriver) PressKeyCode(keyCode KeyCode, metaState KeyMeta, flags ...K
|
||||
if len(flags) != 0 {
|
||||
data["flags"] = flags[0]
|
||||
}
|
||||
_, err = ud.httpPOST(data, "/session", ud.sessionId, "appium/device/press_keycode")
|
||||
_, err = ud.uia2HttpPOST(data, "/session", ud.sessionId, "appium/device/press_keycode")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -212,7 +210,7 @@ func (ud *uiaDriver) TapFloat(x, y float64, options ...ActionOption) (err error)
|
||||
// new data options in post data for extra uiautomator configurations
|
||||
newData := mergeDataWithOptions(data, options...)
|
||||
|
||||
_, err = ud.httpPOST(newData, "/session", ud.sessionId, "appium/tap")
|
||||
_, err = ud.uia2HttpPOST(newData, "/session", ud.sessionId, "appium/tap")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -232,7 +230,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.uia2HttpPOST(data, "/session", ud.sessionId, "touch/longclick")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -256,7 +254,7 @@ func (ud *uiaDriver) DragFloat(fromX, fromY, toX, toY float64, options ...Action
|
||||
newData := mergeDataWithOptions(data, options...)
|
||||
|
||||
// register(postHandler, new Drag("/wd/hub/session/:sessionId/touch/drag"))
|
||||
_, err = ud.httpPOST(newData, "/session", ud.sessionId, "touch/drag")
|
||||
_, err = ud.uia2HttpPOST(newData, "/session", ud.sessionId, "touch/drag")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -280,7 +278,7 @@ func (ud *uiaDriver) SwipeFloat(fromX, fromY, toX, toY float64, options ...Actio
|
||||
// new data options in post data for extra uiautomator configurations
|
||||
newData := mergeDataWithOptions(data, options...)
|
||||
|
||||
_, err := ud.httpPOST(newData, "/session", ud.sessionId, "touch/perform")
|
||||
_, err := ud.uia2HttpPOST(newData, "/session", ud.sessionId, "touch/perform")
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -298,7 +296,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.uia2HttpPOST(data, "/session", ud.sessionId, "appium/device/set_clipboard")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -311,7 +309,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.uia2HttpPOST(data, "/session", ud.sessionId, "appium/device/get_clipboard"); err != nil {
|
||||
return
|
||||
}
|
||||
reply := new(struct{ Value string })
|
||||
@@ -336,7 +334,7 @@ func (ud *uiaDriver) SendKeys(text string, options ...ActionOption) (err error)
|
||||
// new data options in post data for extra uiautomator configurations
|
||||
newData := mergeDataWithOptions(data, options...)
|
||||
|
||||
_, err = ud.httpPOST(newData, "/session", ud.sessionId, "keys")
|
||||
_, err = ud.uia2HttpPOST(newData, "/session", ud.sessionId, "keys")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -347,7 +345,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.uia2HttpGET("/session", ud.sessionId, "rotation"); err != nil {
|
||||
return Rotation{}, err
|
||||
}
|
||||
reply := new(struct{ Value Rotation })
|
||||
@@ -362,7 +360,7 @@ func (ud *uiaDriver) Rotation() (rotation Rotation, err error) {
|
||||
func (ud *uiaDriver) Screenshot() (raw *bytes.Buffer, err error) {
|
||||
// register(getHandler, new CaptureScreenshot("/wd/hub/session/:sessionId/screenshot"))
|
||||
var rawResp rawResponse
|
||||
if rawResp, err = ud.httpGET("/session", ud.sessionId, "screenshot"); err != nil {
|
||||
if rawResp, err = ud.uia2HttpGET("/session", ud.sessionId, "screenshot"); err != nil {
|
||||
return nil, errors.Wrap(code.AndroidScreenShotError,
|
||||
fmt.Sprintf("get UIA screenshot data failed: %v", err))
|
||||
}
|
||||
@@ -384,7 +382,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.uia2HttpGET("/session", ud.sessionId, "source"); err != nil {
|
||||
return "", err
|
||||
}
|
||||
reply := new(struct{ Value string })
|
||||
|
||||
@@ -93,6 +93,119 @@ func (wd *Driver) httpRequest(method string, rawURL string, rawBody []byte) (raw
|
||||
return
|
||||
}
|
||||
|
||||
func (wd *Driver) resetUIA2Driver() (string, error) {
|
||||
ud, err := NewUIADriver(NewCapabilities(), wd.urlPrefix.String())
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
wd.client = ud.client
|
||||
wd.sessionId = ud.sessionId
|
||||
return ud.sessionId, nil
|
||||
}
|
||||
|
||||
func (wd *Driver) uia2HttpRequest(method string, rawURL string, rawBody []byte, disableRetry ...bool) (rawResp rawResponse, err error) {
|
||||
disableRetryBool := len(disableRetry) > 0 && disableRetry[0]
|
||||
for retryCount := 1; retryCount <= 5; retryCount++ {
|
||||
rawResp, err = wd.httpRequest(method, rawURL, rawBody)
|
||||
if err == nil || disableRetryBool {
|
||||
return
|
||||
}
|
||||
// wait for UIA2 server to resume automatically
|
||||
time.Sleep(3 * time.Second)
|
||||
var oldSessionID, newSessionID string
|
||||
oldSessionID = wd.sessionId
|
||||
if newSessionID, err = wd.resetUIA2Driver(); err != nil {
|
||||
log.Err(err).Msgf("failed to reset uia2 session, retry count: %v", retryCount)
|
||||
continue
|
||||
}
|
||||
log.Debug().Str("new session", newSessionID).Str("old session", oldSessionID).Msgf("successful to reset uia2 session, retry count: %v", retryCount)
|
||||
if oldSessionID != "" {
|
||||
rawURL = strings.Replace(rawURL, oldSessionID, wd.sessionId, 1)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (wd *Driver) uia2HttpGET(pathElem ...string) (rawResp rawResponse, err error) {
|
||||
return wd.uia2HttpRequest(http.MethodGet, wd.concatURL(nil, pathElem...), nil)
|
||||
}
|
||||
|
||||
func (wd *Driver) uia2HttpGETWithRetry(pathElem ...string) (rawResp rawResponse, err error) {
|
||||
return wd.uia2HttpRequest(http.MethodGet, wd.concatURL(nil, pathElem...), nil, true)
|
||||
}
|
||||
|
||||
func (wd *Driver) uia2HttpPOST(data interface{}, pathElem ...string) (rawResp rawResponse, err error) {
|
||||
var bsJSON []byte = nil
|
||||
if data != nil {
|
||||
if bsJSON, err = json.Marshal(data); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return wd.uia2HttpRequest(http.MethodPost, wd.concatURL(nil, pathElem...), bsJSON)
|
||||
}
|
||||
|
||||
func (wd *Driver) uia2HttpDELETE(pathElem ...string) (rawResp rawResponse, err error) {
|
||||
return wd.uia2HttpRequest(http.MethodDelete, wd.concatURL(nil, pathElem...), nil)
|
||||
}
|
||||
|
||||
func (wd *Driver) resetWDASession() (string, error) {
|
||||
capabilities := NewCapabilities()
|
||||
capabilities.WithDefaultAlertAction(AlertActionAccept)
|
||||
|
||||
// [[FBRoute POST:@"/session"].withoutSession respondWithTarget:self action:@selector(handleCreateSession:)]
|
||||
data := make(map[string]interface{})
|
||||
data["capabilities"] = map[string]interface{}{"alwaysMatch": capabilities}
|
||||
|
||||
var rawResp rawResponse
|
||||
var err error
|
||||
if rawResp, err = wd.httpPOST(data, "/session"); err != nil {
|
||||
return "", err
|
||||
}
|
||||
var sessionInfo SessionInfo
|
||||
if sessionInfo, err = rawResp.valueConvertToSessionInfo(); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return sessionInfo.SessionId, nil
|
||||
}
|
||||
|
||||
func (wd *Driver) wdaHttpRequest(method string, rawURL string, rawBody []byte, disableRetry ...bool) (rawResp rawResponse, err error) {
|
||||
disableRetryBool := len(disableRetry) > 0 && disableRetry[0]
|
||||
for retryCount := 1; retryCount <= 5; retryCount++ {
|
||||
rawResp, err = wd.httpRequest(method, rawURL, rawBody)
|
||||
if err == nil || disableRetryBool {
|
||||
return
|
||||
}
|
||||
if _, err = wd.resetWDASession(); err != nil {
|
||||
log.Err(err).Msgf("failed to reset wda session, retry count: %v", retryCount)
|
||||
continue
|
||||
}
|
||||
log.Debug().Str("new session", wd.sessionId).Msgf("successful to reset wda session, retry count: %v", retryCount)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (wd *Driver) wdaHttpGET(pathElem ...string) (rawResp rawResponse, err error) {
|
||||
return wd.wdaHttpRequest(http.MethodGet, wd.concatURL(nil, pathElem...), nil)
|
||||
}
|
||||
|
||||
func (wd *Driver) wdaHttpGETWithRetry(pathElem ...string) (rawResp rawResponse, err error) {
|
||||
return wd.wdaHttpRequest(http.MethodGet, wd.concatURL(nil, pathElem...), nil, true)
|
||||
}
|
||||
|
||||
func (wd *Driver) wdaHttpPOST(data interface{}, pathElem ...string) (rawResp rawResponse, err error) {
|
||||
var bsJSON []byte = nil
|
||||
if data != nil {
|
||||
if bsJSON, err = json.Marshal(data); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return wd.wdaHttpRequest(http.MethodPost, wd.concatURL(nil, pathElem...), bsJSON)
|
||||
}
|
||||
|
||||
func (wd *Driver) wdaHttpDELETE(pathElem ...string) (rawResp rawResponse, err error) {
|
||||
return wd.wdaHttpRequest(http.MethodDelete, wd.concatURL(nil, pathElem...), nil)
|
||||
}
|
||||
|
||||
func convertToHTTPClient(conn net.Conn) *http.Client {
|
||||
return &http.Client{
|
||||
Transport: &http.Transport{
|
||||
|
||||
@@ -660,9 +660,11 @@ func (dev *IOSDevice) NewUSBDriver(capabilities Capabilities) (driver WebDriver,
|
||||
if wd.urlPrefix, err = url.Parse("http://" + dev.UDID); err != nil {
|
||||
return nil, errors.Wrap(code.IOSDeviceUSBDriverError, err.Error())
|
||||
}
|
||||
if _, err = wd.NewSession(capabilities); err != nil {
|
||||
var sessionInfo SessionInfo
|
||||
if sessionInfo, 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 {
|
||||
|
||||
@@ -45,13 +45,12 @@ func (wd *wdaDriver) NewSession(capabilities Capabilities) (sessionInfo SessionI
|
||||
}
|
||||
|
||||
var rawResp rawResponse
|
||||
if rawResp, err = wd.httpPOST(data, "/session"); err != nil {
|
||||
if rawResp, err = wd.wdaHttpPOST(data, "/session"); err != nil {
|
||||
return SessionInfo{}, err
|
||||
}
|
||||
if sessionInfo, err = rawResp.valueConvertToSessionInfo(); err != nil {
|
||||
return SessionInfo{}, err
|
||||
}
|
||||
wd.sessionId = sessionInfo.SessionId
|
||||
return
|
||||
}
|
||||
|
||||
@@ -71,14 +70,14 @@ func (wd *wdaDriver) DeleteSession() (err error) {
|
||||
}
|
||||
|
||||
// [[FBRoute DELETE:@""] respondWithTarget:self action:@selector(handleDeleteSession:)]
|
||||
_, err = wd.httpDELETE("/session", wd.sessionId)
|
||||
_, err = wd.wdaHttpDELETE("/session", wd.sessionId)
|
||||
return
|
||||
}
|
||||
|
||||
func (wd *wdaDriver) Status() (deviceStatus DeviceStatus, err error) {
|
||||
// [[FBRoute GET:@"/status"].withoutSession respondWithTarget:self action:@selector(handleGetStatus:)]
|
||||
var rawResp rawResponse
|
||||
if rawResp, err = wd.httpGET("/status"); err != nil {
|
||||
if rawResp, err = wd.wdaHttpGET("/status"); err != nil {
|
||||
return DeviceStatus{}, err
|
||||
}
|
||||
reply := new(struct{ Value struct{ DeviceStatus } })
|
||||
@@ -93,7 +92,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.wdaHttpGET("/session", wd.sessionId, "/wda/device/info"); err != nil {
|
||||
return DeviceInfo{}, err
|
||||
}
|
||||
reply := new(struct{ Value struct{ DeviceInfo } })
|
||||
@@ -108,7 +107,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.wdaHttpGET("/session", wd.sessionId, "/wda/device/location"); err != nil {
|
||||
return Location{}, err
|
||||
}
|
||||
reply := new(struct{ Value struct{ Location } })
|
||||
@@ -122,7 +121,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.wdaHttpGET("/session", wd.sessionId, "/wda/batteryInfo"); err != nil {
|
||||
return BatteryInfo{}, err
|
||||
}
|
||||
reply := new(struct{ Value struct{ BatteryInfo } })
|
||||
@@ -136,7 +135,7 @@ func (wd *wdaDriver) BatteryInfo() (batteryInfo BatteryInfo, err error) {
|
||||
func (wd *wdaDriver) WindowSize() (size Size, err error) {
|
||||
// [[FBRoute GET:@"/window/size"] respondWithTarget:self action:@selector(handleGetWindowSize:)]
|
||||
var rawResp rawResponse
|
||||
if rawResp, err = wd.httpGET("/session", wd.sessionId, "/window/size"); err != nil {
|
||||
if rawResp, err = wd.wdaHttpGET("/session", wd.sessionId, "/window/size"); err != nil {
|
||||
return Size{}, errors.Wrap(err, "get window size failed with wda")
|
||||
}
|
||||
reply := new(struct{ Value struct{ Size } })
|
||||
@@ -150,7 +149,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.wdaHttpGET("/session", wd.sessionId, "/wda/screen"); err != nil {
|
||||
return Screen{}, err
|
||||
}
|
||||
reply := new(struct{ Value struct{ Screen } })
|
||||
@@ -183,7 +182,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.wdaHttpGET("/session", wd.sessionId, "/wda/activeAppInfo"); err != nil {
|
||||
return AppInfo{}, err
|
||||
}
|
||||
reply := new(struct{ Value struct{ AppInfo } })
|
||||
@@ -197,7 +196,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.wdaHttpGET("/session", wd.sessionId, "/wda/apps/list"); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
reply := new(struct{ Value []AppBaseInfo })
|
||||
@@ -212,7 +211,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.wdaHttpPOST(data, "/session", wd.sessionId, "/wda/apps/state"); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
reply := new(struct{ Value AppState })
|
||||
@@ -228,7 +227,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.wdaHttpGET("/session", wd.sessionId, "/wda/locked"); err != nil {
|
||||
return false, err
|
||||
}
|
||||
if locked, err = rawResp.valueConvertToBool(); err != nil {
|
||||
@@ -240,20 +239,20 @@ 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.wdaHttpPOST(nil, "/session", wd.sessionId, "/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.wdaHttpPOST(nil, "/session", wd.sessionId, "/wda/lock")
|
||||
return
|
||||
}
|
||||
|
||||
func (wd *wdaDriver) Homescreen() (err error) {
|
||||
// [[FBRoute POST:@"/wda/homescreen"].withoutSession respondWithTarget:self action:@selector(handleHomescreenCommand:)]
|
||||
_, err = wd.httpPOST(nil, "/wda/homescreen")
|
||||
_, err = wd.wdaHttpPOST(nil, "/wda/homescreen")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -261,7 +260,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.wdaHttpGET("/session", wd.sessionId, "/alert/text"); err != nil {
|
||||
return "", err
|
||||
}
|
||||
if text, err = rawResp.valueConvertToString(); err != nil {
|
||||
@@ -273,7 +272,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.wdaHttpGET("/session", wd.sessionId, "/wda/alert/buttons"); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
reply := new(struct{ Value []string })
|
||||
@@ -291,7 +290,7 @@ func (wd *wdaDriver) AlertAccept(label ...string) (err error) {
|
||||
if len(label) != 0 && label[0] != "" {
|
||||
data["name"] = label[0]
|
||||
}
|
||||
_, err = wd.httpPOST(data, "/alert/accept")
|
||||
_, err = wd.wdaHttpPOST(data, "/alert/accept")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -302,14 +301,14 @@ func (wd *wdaDriver) AlertDismiss(label ...string) (err error) {
|
||||
if len(label) != 0 && label[0] != "" {
|
||||
data["name"] = label[0]
|
||||
}
|
||||
_, err = wd.httpPOST(data, "/alert/dismiss")
|
||||
_, err = wd.wdaHttpPOST(data, "/alert/dismiss")
|
||||
return
|
||||
}
|
||||
|
||||
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.wdaHttpPOST(data, "/session", wd.sessionId, "/alert/text")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -317,7 +316,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.wdaHttpPOST(data, "/session", wd.sessionId, "/wda/apps/launch")
|
||||
if err != nil {
|
||||
return errors.Wrap(code.MobileUILaunchAppError,
|
||||
fmt.Sprintf("wda launch failed: %v", err))
|
||||
@@ -328,7 +327,7 @@ func (wd *wdaDriver) AppLaunch(bundleId string) (err error) {
|
||||
func (wd *wdaDriver) AppLaunchUnattached(bundleId string) (err error) {
|
||||
// [[FBRoute POST:@"/wda/apps/launchUnattached"].withoutSession respondWithTarget:self action:@selector(handleLaunchUnattachedApp:)]
|
||||
data := map[string]interface{}{"bundleId": bundleId}
|
||||
_, err = wd.httpPOST(data, "/wda/apps/launchUnattached")
|
||||
_, err = wd.wdaHttpPOST(data, "/wda/apps/launchUnattached")
|
||||
if err != nil {
|
||||
return errors.Wrap(code.MobileUILaunchAppError,
|
||||
fmt.Sprintf("wda launchUnattached failed: %v", err))
|
||||
@@ -340,7 +339,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.wdaHttpPOST(data, "/session", wd.sessionId, "/wda/apps/terminate"); err != nil {
|
||||
return false, err
|
||||
}
|
||||
if successful, err = rawResp.valueConvertToBool(); err != nil {
|
||||
@@ -352,7 +351,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.wdaHttpPOST(data, "/session", wd.sessionId, "/wda/apps/activate")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -362,7 +361,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.wdaHttpPOST(data, "/session", wd.sessionId, "/wda/deactivateApp")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -402,7 +401,7 @@ func (wd *wdaDriver) TapFloat(x, y float64, options ...ActionOption) (err error)
|
||||
// new data options in post data for extra WDA configurations
|
||||
newData := mergeDataWithOptions(data, options...)
|
||||
|
||||
_, err = wd.httpPOST(newData, "/session", wd.sessionId, "/wda/tap/0")
|
||||
_, err = wd.wdaHttpPOST(newData, "/session", wd.sessionId, "/wda/tap/0")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -416,7 +415,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.wdaHttpPOST(data, "/session", wd.sessionId, "/wda/doubleTap")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -434,7 +433,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.wdaHttpPOST(data, "/session", wd.sessionId, "/wda/touchAndHold")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -454,7 +453,7 @@ func (wd *wdaDriver) DragFloat(fromX, fromY, toX, toY float64, options ...Action
|
||||
// new data options in post data for extra WDA configurations
|
||||
newData := mergeDataWithOptions(data, options...)
|
||||
|
||||
_, err = wd.httpPOST(newData, "/session", wd.sessionId, "/wda/dragfromtoforduration")
|
||||
_, err = wd.wdaHttpPOST(newData, "/session", wd.sessionId, "/wda/dragfromtoforduration")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -472,7 +471,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.wdaHttpPOST(data, "/session", wd.sessionId, "/wda/setPasteboard")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -480,7 +479,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.wdaHttpPOST(data, "/session", wd.sessionId, "/wda/getPasteboard"); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if raw, err = rawResp.valueDecodeAsBase64(); err != nil {
|
||||
@@ -496,7 +495,7 @@ func (wd *wdaDriver) SendKeys(text string, options ...ActionOption) (err error)
|
||||
// new data options in post data for extra WDA configurations
|
||||
newData := mergeDataWithOptions(data, options...)
|
||||
|
||||
_, err = wd.httpPOST(newData, "/session", wd.sessionId, "/wda/keys")
|
||||
_, err = wd.wdaHttpPOST(newData, "/session", wd.sessionId, "/wda/keys")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -521,14 +520,14 @@ func (wd *wdaDriver) PressBack(options ...ActionOption) (err error) {
|
||||
// new data options in post data for extra WDA configurations
|
||||
newData := mergeDataWithOptions(data, options...)
|
||||
|
||||
_, err = wd.httpPOST(newData, "/session", wd.sessionId, "/wda/dragfromtoforduration")
|
||||
_, err = wd.wdaHttpPOST(newData, "/session", wd.sessionId, "/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.wdaHttpPOST(data, "/session", wd.sessionId, "/wda/pressButton")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -552,7 +551,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.wdaHttpGET("/session", wd.sessionId, "/orientation"); err != nil {
|
||||
return "", err
|
||||
}
|
||||
reply := new(struct{ Value Orientation })
|
||||
@@ -566,14 +565,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.wdaHttpPOST(data, "/session", wd.sessionId, "/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.wdaHttpGET("/session", wd.sessionId, "/rotation"); err != nil {
|
||||
return Rotation{}, err
|
||||
}
|
||||
reply := new(struct{ Value Rotation })
|
||||
@@ -586,7 +585,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.wdaHttpPOST(rotation, "/session", wd.sessionId, "/rotation")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -594,7 +593,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.wdaHttpGET("/session", wd.sessionId, "/screenshot"); err != nil {
|
||||
return nil, errors.Wrap(code.IOSScreenShotError,
|
||||
fmt.Sprintf("get WDA screenshot data failed: %v", err))
|
||||
}
|
||||
@@ -644,7 +643,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.wdaHttpGET("/session", wd.sessionId, "/wda/accessibleSource"); err != nil {
|
||||
return "", err
|
||||
}
|
||||
var jr builtinJSON.RawMessage
|
||||
@@ -657,14 +656,14 @@ func (wd *wdaDriver) AccessibleSource() (source string, err error) {
|
||||
|
||||
func (wd *wdaDriver) HealthCheck() (err error) {
|
||||
// [[FBRoute GET:@"/wda/healthcheck"].withoutSession respondWithTarget:self action:@selector(handleGetHealthCheck:)]
|
||||
_, err = wd.httpGET("/wda/healthcheck")
|
||||
_, err = wd.wdaHttpGET("/wda/healthcheck")
|
||||
return
|
||||
}
|
||||
|
||||
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.wdaHttpGET("/session", wd.sessionId, "/appium/settings"); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
reply := new(struct{ Value map[string]interface{} })
|
||||
@@ -679,7 +678,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.wdaHttpPOST(data, "/session", wd.sessionId, "/appium/settings"); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
reply := new(struct{ Value map[string]interface{} })
|
||||
@@ -692,7 +691,7 @@ func (wd *wdaDriver) SetAppiumSettings(settings map[string]interface{}) (ret map
|
||||
|
||||
func (wd *wdaDriver) IsHealthy() (healthy bool, err error) {
|
||||
var rawResp rawResponse
|
||||
if rawResp, err = wd.httpGET("/health"); err != nil {
|
||||
if rawResp, err = wd.wdaHttpGET("/health"); err != nil {
|
||||
return false, err
|
||||
}
|
||||
if string(rawResp) != "I-AM-ALIVE" {
|
||||
@@ -702,13 +701,13 @@ func (wd *wdaDriver) IsHealthy() (healthy bool, err error) {
|
||||
}
|
||||
|
||||
func (wd *wdaDriver) WdaShutdown() (err error) {
|
||||
_, err = wd.httpGET("/wda/shutdown")
|
||||
_, err = wd.wdaHttpGET("/wda/shutdown")
|
||||
return
|
||||
}
|
||||
|
||||
func (wd *wdaDriver) triggerWDALog(data map[string]interface{}) (rawResp []byte, err error) {
|
||||
// [[FBRoute POST:@"/gtf/automation/log"].withoutSession respondWithTarget:self action:@selector(handleAutomationLog:)]
|
||||
return wd.httpPOST(data, "/gtf/automation/log")
|
||||
return wd.wdaHttpPOST(data, "/gtf/automation/log")
|
||||
}
|
||||
|
||||
func (wd *wdaDriver) StartCaptureLog(identifier ...string) error {
|
||||
|
||||
Reference in New Issue
Block a user