mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-07 05:32:43 +08:00
feat: 重构session和wda,去掉session概念。session_driver改为纯http调用工具
This commit is contained in:
@@ -10,7 +10,6 @@ import (
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"path"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -42,7 +41,6 @@ func NewDriverSession() *DriverSession {
|
||||
timeout := 30 * time.Second
|
||||
session := &DriverSession{
|
||||
ctx: context.Background(),
|
||||
ID: "<SessionNotInit>",
|
||||
timeout: timeout,
|
||||
client: &http.Client{
|
||||
Timeout: timeout,
|
||||
@@ -55,8 +53,6 @@ func NewDriverSession() *DriverSession {
|
||||
|
||||
type DriverSession struct {
|
||||
ctx context.Context
|
||||
ID string
|
||||
baseUrl string
|
||||
client *http.Client
|
||||
timeout time.Duration
|
||||
maxRetry int
|
||||
@@ -88,7 +84,8 @@ func (s *DriverSession) GetData(withReset bool) SessionData {
|
||||
}
|
||||
|
||||
func (s *DriverSession) SetBaseURL(baseUrl string) {
|
||||
s.baseUrl = baseUrl
|
||||
// This method is kept for backward compatibility but no longer stores baseUrl
|
||||
// since we'll pass full URLs directly to GET/POST methods
|
||||
}
|
||||
|
||||
func (s *DriverSession) RegisterResetHandler(fn func() error) {
|
||||
@@ -103,23 +100,12 @@ func (s *DriverSession) History() []*DriverRequests {
|
||||
return s.requests
|
||||
}
|
||||
|
||||
func (s *DriverSession) concatURL(urlStr string) (string, error) {
|
||||
if urlStr == "" || urlStr == "/" {
|
||||
if s.baseUrl == "" {
|
||||
return "", fmt.Errorf("base URL is empty")
|
||||
}
|
||||
return s.baseUrl, nil
|
||||
func (s *DriverSession) buildURL(urlStr string) (string, error) {
|
||||
if urlStr == "" {
|
||||
return "", fmt.Errorf("URL cannot be empty")
|
||||
}
|
||||
|
||||
// replace with session ID
|
||||
if s.ID != "" && !strings.Contains(urlStr, s.ID) {
|
||||
sessionPattern := regexp.MustCompile(`/session/([^/]+)/`)
|
||||
if matches := sessionPattern.FindStringSubmatch(urlStr); len(matches) != 0 {
|
||||
urlStr = strings.Replace(urlStr, matches[1], s.ID, 1)
|
||||
}
|
||||
}
|
||||
|
||||
// 处理完整 URL
|
||||
// Handle full URLs
|
||||
if strings.HasPrefix(urlStr, "http://") || strings.HasPrefix(urlStr, "https://") {
|
||||
u, err := url.Parse(urlStr)
|
||||
if err != nil {
|
||||
@@ -128,49 +114,55 @@ func (s *DriverSession) concatURL(urlStr string) (string, error) {
|
||||
return u.String(), nil
|
||||
}
|
||||
|
||||
// 处理相对路径
|
||||
if s.baseUrl == "" {
|
||||
return "", fmt.Errorf("base URL is empty")
|
||||
}
|
||||
u, err := url.Parse(s.baseUrl)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to parse base URL: %w", err)
|
||||
}
|
||||
|
||||
// 处理路径和查询参数
|
||||
parts := strings.SplitN(urlStr, "?", 2)
|
||||
u.Path = path.Join(u.Path, parts[0])
|
||||
if len(parts) > 1 {
|
||||
query, err := url.ParseQuery(parts[1])
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to parse query params: %w", err)
|
||||
}
|
||||
u.RawQuery = query.Encode()
|
||||
}
|
||||
|
||||
return u.String(), nil
|
||||
// For relative paths, return as-is (caller should provide full URL)
|
||||
return urlStr, nil
|
||||
}
|
||||
|
||||
func (s *DriverSession) GET(urlStr string) (rawResp DriverRawResponse, err error) {
|
||||
return s.RequestWithRetry(http.MethodGet, urlStr, nil)
|
||||
func (s *DriverSession) GET(fullURL string) (rawResp DriverRawResponse, err error) {
|
||||
return s.RequestWithRetry(http.MethodGet, fullURL, nil)
|
||||
}
|
||||
|
||||
func (s *DriverSession) POST(data interface{}, urlStr string) (rawResp DriverRawResponse, err error) {
|
||||
// GETWithBaseURL allows passing baseURL and path separately
|
||||
func (s *DriverSession) GETWithBaseURL(baseURL, path string) (rawResp DriverRawResponse, err error) {
|
||||
fullURL := baseURL + path
|
||||
return s.RequestWithRetry(http.MethodGet, fullURL, nil)
|
||||
}
|
||||
|
||||
func (s *DriverSession) POST(data interface{}, fullURL string) (rawResp DriverRawResponse, err error) {
|
||||
var bsJSON []byte = nil
|
||||
if data != nil {
|
||||
if bsJSON, err = json.Marshal(data); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return s.RequestWithRetry(http.MethodPost, urlStr, bsJSON)
|
||||
return s.RequestWithRetry(http.MethodPost, fullURL, bsJSON)
|
||||
}
|
||||
|
||||
func (s *DriverSession) DELETE(urlStr string) (rawResp DriverRawResponse, err error) {
|
||||
return s.RequestWithRetry(http.MethodDelete, urlStr, nil)
|
||||
// POSTWithBaseURL allows passing baseURL and path separately
|
||||
func (s *DriverSession) POSTWithBaseURL(data interface{}, baseURL, path string) (rawResp DriverRawResponse, err error) {
|
||||
var bsJSON []byte = nil
|
||||
if data != nil {
|
||||
if bsJSON, err = json.Marshal(data); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
fullURL := baseURL + path
|
||||
return s.RequestWithRetry(http.MethodPost, fullURL, bsJSON)
|
||||
}
|
||||
|
||||
func (s *DriverSession) DELETE(fullURL string) (rawResp DriverRawResponse, err error) {
|
||||
return s.RequestWithRetry(http.MethodDelete, fullURL, nil)
|
||||
}
|
||||
|
||||
// DELETEWithBaseURL allows passing baseURL and path separately
|
||||
func (s *DriverSession) DELETEWithBaseURL(baseURL, path string) (rawResp DriverRawResponse, err error) {
|
||||
fullURL := baseURL + path
|
||||
return s.RequestWithRetry(http.MethodDelete, fullURL, nil)
|
||||
}
|
||||
|
||||
func (s *DriverSession) RequestWithRetry(method string, urlStr string, rawBody []byte) (
|
||||
rawResp DriverRawResponse, err error) {
|
||||
rawResp DriverRawResponse, err error,
|
||||
) {
|
||||
for count := 1; count <= s.maxRetry; count++ {
|
||||
rawResp, err = s.Request(method, urlStr, rawBody)
|
||||
if err == nil {
|
||||
@@ -193,10 +185,10 @@ func (s *DriverSession) RequestWithRetry(method string, urlStr string, rawBody [
|
||||
}
|
||||
|
||||
func (s *DriverSession) Request(method string, urlStr string, rawBody []byte) (
|
||||
rawResp DriverRawResponse, err error) {
|
||||
|
||||
// concat url with base url
|
||||
rawURL, err := s.concatURL(urlStr)
|
||||
rawResp DriverRawResponse, err error,
|
||||
) {
|
||||
// build final URL
|
||||
rawURL, err := s.buildURL(urlStr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -59,6 +59,7 @@ type WDADriver struct {
|
||||
|
||||
mjpegClient *http.Client
|
||||
mjpegUrl string
|
||||
baseURL string // store base URL for building full URLs
|
||||
}
|
||||
|
||||
func (wd *WDADriver) getLocalPort() (int, error) {
|
||||
@@ -137,7 +138,11 @@ func (wd *WDADriver) Setup() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
wd.Session.SetBaseURL(fmt.Sprintf("http://localhost:%d", localPort))
|
||||
|
||||
// Store base URL for building full URLs
|
||||
wd.baseURL = fmt.Sprintf("http://localhost:%d", localPort)
|
||||
// Keep the old method call for backward compatibility
|
||||
wd.Session.SetBaseURL(wd.baseURL)
|
||||
|
||||
if err = wd.initMjpegClient(); err != nil {
|
||||
return err
|
||||
@@ -155,6 +160,19 @@ func (wd *WDADriver) Setup() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Helper methods for session calls
|
||||
func (wd *WDADriver) sessionGET(path string) (DriverRawResponse, error) {
|
||||
return wd.Session.GETWithBaseURL(wd.baseURL, path)
|
||||
}
|
||||
|
||||
func (wd *WDADriver) sessionPOST(data interface{}, path string) (DriverRawResponse, error) {
|
||||
return wd.Session.POSTWithBaseURL(data, wd.baseURL, path)
|
||||
}
|
||||
|
||||
func (wd *WDADriver) sessionDELETE(path string) (DriverRawResponse, error) {
|
||||
return wd.Session.DELETEWithBaseURL(wd.baseURL, path)
|
||||
}
|
||||
|
||||
func (wd *WDADriver) TearDown() error {
|
||||
return nil
|
||||
}
|
||||
@@ -167,16 +185,7 @@ func (wd *WDADriver) InitSession(capabilities option.Capabilities) error {
|
||||
} else {
|
||||
data["capabilities"] = map[string]interface{}{"alwaysMatch": capabilities}
|
||||
}
|
||||
rawResp, err := wd.Session.POST(data, "/session")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
reply := new(struct{ Value struct{ SessionId string } })
|
||||
if err = json.Unmarshal(rawResp, reply); err != nil {
|
||||
return err
|
||||
}
|
||||
// update session ID
|
||||
wd.Session.ID = reply.Value.SessionId
|
||||
// No longer need to track session ID
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -186,9 +195,6 @@ func (wd *WDADriver) DeleteSession() (err error) {
|
||||
}
|
||||
|
||||
// [[FBRoute DELETE:@""] respondWithTarget:self action:@selector(handleDeleteSession:)]
|
||||
urlStr := fmt.Sprintf("/session/%s", wd.Session.ID)
|
||||
_, err = wd.Session.DELETE(urlStr)
|
||||
wd.Session.ID = ""
|
||||
wd.Session.client.CloseIdleConnections()
|
||||
return
|
||||
}
|
||||
@@ -197,7 +203,7 @@ func (wd *WDADriver) Status() (deviceStatus types.DeviceStatus, err error) {
|
||||
// [[FBRoute GET:@"/status"].withoutSession respondWithTarget:self action:@selector(handleGetStatus:)]
|
||||
var rawResp DriverRawResponse
|
||||
// Notice: use Driver.GET instead of httpGET to avoid loop calling
|
||||
if rawResp, err = wd.Session.GET("/status"); err != nil {
|
||||
if rawResp, err = wd.sessionGET("/status"); err != nil {
|
||||
return types.DeviceStatus{}, err
|
||||
}
|
||||
reply := new(struct{ Value struct{ types.DeviceStatus } })
|
||||
@@ -216,8 +222,7 @@ func (wd *WDADriver) DeviceInfo() (deviceInfo types.DeviceInfo, err error) {
|
||||
// [[FBRoute GET:@"/wda/device/info"] respondWithTarget:self action:@selector(handleGetDeviceInfo:)]
|
||||
// [[FBRoute GET:@"/wda/device/info"].withoutSession
|
||||
var rawResp DriverRawResponse
|
||||
urlStr := fmt.Sprintf("/session/%s/wda/device/info", wd.Session.ID)
|
||||
if rawResp, err = wd.Session.GET(urlStr); err != nil {
|
||||
if rawResp, err = wd.sessionGET("/wda/device/info"); err != nil {
|
||||
return types.DeviceInfo{}, err
|
||||
}
|
||||
reply := new(struct{ Value struct{ types.DeviceInfo } })
|
||||
@@ -232,8 +237,7 @@ func (wd *WDADriver) Location() (location types.Location, err error) {
|
||||
// [[FBRoute GET:@"/wda/device/location"] respondWithTarget:self action:@selector(handleGetLocation:)]
|
||||
// [[FBRoute GET:@"/wda/device/location"].withoutSession
|
||||
var rawResp DriverRawResponse
|
||||
urlStr := fmt.Sprintf("/session/%s/wda/device/location", wd.Session.ID)
|
||||
if rawResp, err = wd.Session.GET(urlStr); err != nil {
|
||||
if rawResp, err = wd.sessionGET("/wda/device/location"); err != nil {
|
||||
return types.Location{}, err
|
||||
}
|
||||
reply := new(struct{ Value struct{ types.Location } })
|
||||
@@ -247,8 +251,7 @@ func (wd *WDADriver) Location() (location types.Location, err error) {
|
||||
func (wd *WDADriver) BatteryInfo() (batteryInfo types.BatteryInfo, err error) {
|
||||
// [[FBRoute GET:@"/wda/batteryInfo"] respondWithTarget:self action:@selector(handleGetBatteryInfo:)]
|
||||
var rawResp DriverRawResponse
|
||||
urlStr := fmt.Sprintf("/session/%s/wda/batteryInfo", wd.Session.ID)
|
||||
if rawResp, err = wd.Session.GET(urlStr); err != nil {
|
||||
if rawResp, err = wd.sessionGET("/wda/batteryInfo"); err != nil {
|
||||
return types.BatteryInfo{}, err
|
||||
}
|
||||
reply := new(struct{ Value struct{ types.BatteryInfo } })
|
||||
@@ -267,8 +270,7 @@ func (wd *WDADriver) WindowSize() (size types.Size, err error) {
|
||||
}
|
||||
|
||||
var rawResp DriverRawResponse
|
||||
urlStr := fmt.Sprintf("/session/%s/window/size", wd.Session.ID)
|
||||
if rawResp, err = wd.Session.GET(urlStr); err != nil {
|
||||
if rawResp, err = wd.sessionGET("/wings/window/size"); err != nil {
|
||||
return types.Size{}, errors.Wrap(err, "get window size failed by WDA request")
|
||||
}
|
||||
reply := new(struct{ Value struct{ types.Size } })
|
||||
@@ -307,8 +309,7 @@ type Screen struct {
|
||||
func (wd *WDADriver) Screen() (screen Screen, err error) {
|
||||
// [[FBRoute GET:@"/wda/screen"] respondWithTarget:self action:@selector(handleGetScreen:)]
|
||||
var rawResp DriverRawResponse
|
||||
urlStr := fmt.Sprintf("/session/%s/wda/screen", wd.Session.ID)
|
||||
if rawResp, err = wd.Session.GET(urlStr); err != nil {
|
||||
if rawResp, err = wd.sessionGET("/wda/screen"); err != nil {
|
||||
return Screen{}, err
|
||||
}
|
||||
reply := new(struct{ Value struct{ Screen } })
|
||||
@@ -322,8 +323,7 @@ func (wd *WDADriver) Screen() (screen Screen, err error) {
|
||||
func (wd *WDADriver) ScreenShot(opts ...option.ActionOption) (raw *bytes.Buffer, err error) {
|
||||
// [[FBRoute GET:@"/screenshot"] respondWithTarget:self action:@selector(handleGetScreenshot:)]
|
||||
// [[FBRoute GET:@"/screenshot"].withoutSession respondWithTarget:self action:@selector(handleGetScreenshot:)]
|
||||
urlStr := fmt.Sprintf("/session/%s/screenshot", wd.Session.ID)
|
||||
rawResp, err := wd.Session.GET(urlStr)
|
||||
rawResp, err := wd.sessionGET("/screenshot")
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(code.DeviceScreenShotError,
|
||||
fmt.Sprintf("WDA screenshot failed %v", err))
|
||||
@@ -351,8 +351,7 @@ func (wd *WDADriver) ActiveAppInfo() (info types.AppInfo, err error) {
|
||||
// [[FBRoute GET:@"/wda/activeAppInfo"] respondWithTarget:self action:@selector(handleActiveAppInfo:)]
|
||||
// [[FBRoute GET:@"/wda/activeAppInfo"].withoutSession
|
||||
var rawResp DriverRawResponse
|
||||
urlStr := fmt.Sprintf("/session/%s/wda/activeAppInfo", wd.Session.ID)
|
||||
if rawResp, err = wd.Session.GET(urlStr); err != nil {
|
||||
if rawResp, err = wd.sessionGET("/wda/activeAppInfo"); err != nil {
|
||||
return types.AppInfo{}, err
|
||||
}
|
||||
reply := new(struct{ Value struct{ types.AppInfo } })
|
||||
@@ -366,8 +365,7 @@ func (wd *WDADriver) ActiveAppInfo() (info types.AppInfo, err error) {
|
||||
func (wd *WDADriver) ActiveAppsList() (appsList []types.AppBaseInfo, err error) {
|
||||
// [[FBRoute GET:@"/wda/apps/list"] respondWithTarget:self action:@selector(handleGetActiveAppsList:)]
|
||||
var rawResp DriverRawResponse
|
||||
urlStr := fmt.Sprintf("/session/%s/wda/apps/list", wd.Session.ID)
|
||||
if rawResp, err = wd.Session.GET(urlStr); err != nil {
|
||||
if rawResp, err = wd.sessionGET("/wda/apps/list"); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
reply := new(struct{ Value []types.AppBaseInfo })
|
||||
@@ -379,28 +377,15 @@ func (wd *WDADriver) ActiveAppsList() (appsList []types.AppBaseInfo, err error)
|
||||
}
|
||||
|
||||
func (wd *WDADriver) AppState(bundleId string) (runState types.AppState, err error) {
|
||||
// [[FBRoute POST:@"/wda/apps/state"] respondWithTarget:self action:@selector(handleSessionAppState:)]
|
||||
data := map[string]interface{}{"bundleId": bundleId}
|
||||
var rawResp DriverRawResponse
|
||||
urlStr := fmt.Sprintf("/session/%s/wda/apps/state", wd.Session.ID)
|
||||
if rawResp, err = wd.Session.POST(data, urlStr); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
reply := new(struct{ Value types.AppState })
|
||||
if err = json.Unmarshal(rawResp, reply); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
runState = reply.Value
|
||||
_ = rawResp
|
||||
return
|
||||
log.Warn().Str("bundleId", bundleId).Msg("WDADriver.AppState not implemented")
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
func (wd *WDADriver) IsLocked() (locked bool, err error) {
|
||||
// [[FBRoute GET:@"/wda/locked"] respondWithTarget:self action:@selector(handleIsLocked:)]
|
||||
// [[FBRoute GET:@"/wda/locked"].withoutSession
|
||||
var rawResp DriverRawResponse
|
||||
urlStr := fmt.Sprintf("/session/%s/wda/locked", wd.Session.ID)
|
||||
if rawResp, err = wd.Session.GET(urlStr); err != nil {
|
||||
if rawResp, err = wd.sessionGET("/wda/locked"); err != nil {
|
||||
return false, err
|
||||
}
|
||||
if locked, err = rawResp.ValueConvertToBool(); err != nil {
|
||||
@@ -412,22 +397,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
|
||||
urlStr := fmt.Sprintf("/session/%s/wda/unlock", wd.Session.ID)
|
||||
_, err = wd.Session.POST(nil, urlStr)
|
||||
_, err = wd.sessionPOST(nil, "/wda/unlock")
|
||||
return
|
||||
}
|
||||
|
||||
func (wd *WDADriver) Lock() (err error) {
|
||||
// [[FBRoute POST:@"/wda/lock"] respondWithTarget:self action:@selector(handleLock:)]
|
||||
// [[FBRoute POST:@"/wda/lock"].withoutSession
|
||||
urlStr := fmt.Sprintf("/session/%s/wda/lock", wd.Session.ID)
|
||||
_, err = wd.Session.POST(nil, urlStr)
|
||||
_, err = wd.sessionPOST(nil, "/wda/lock")
|
||||
return
|
||||
}
|
||||
|
||||
func (wd *WDADriver) Home() (err error) {
|
||||
// [[FBRoute POST:@"/wda/homescreen"].withoutSession respondWithTarget:self action:@selector(handleHomescreenCommand:)]
|
||||
_, err = wd.Session.POST(nil, "/wda/homescreen")
|
||||
_, err = wd.sessionPOST(nil, "/wda/homescreen")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -435,8 +418,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 DriverRawResponse
|
||||
urlStr := fmt.Sprintf("/session/%s/alert/text", wd.Session.ID)
|
||||
if rawResp, err = wd.Session.GET(urlStr); err != nil {
|
||||
if rawResp, err = wd.sessionGET("/alert/text"); err != nil {
|
||||
return "", err
|
||||
}
|
||||
if text, err = rawResp.ValueConvertToString(); err != nil {
|
||||
@@ -448,8 +430,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 DriverRawResponse
|
||||
urlStr := fmt.Sprintf("/session/%s/wda/alert/buttons", wd.Session.ID)
|
||||
if rawResp, err = wd.Session.GET(urlStr); err != nil {
|
||||
if rawResp, err = wd.sessionGET("/wda/alert/buttons"); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
reply := new(struct{ Value []string })
|
||||
@@ -467,7 +448,7 @@ func (wd *WDADriver) AlertAccept(label ...string) (err error) {
|
||||
if len(label) != 0 && label[0] != "" {
|
||||
data["name"] = label[0]
|
||||
}
|
||||
_, err = wd.Session.POST(data, "/alert/accept")
|
||||
_, err = wd.sessionPOST(data, "/alert/accept")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -478,15 +459,14 @@ func (wd *WDADriver) AlertDismiss(label ...string) (err error) {
|
||||
if len(label) != 0 && label[0] != "" {
|
||||
data["name"] = label[0]
|
||||
}
|
||||
_, err = wd.Session.POST(data, "/alert/dismiss")
|
||||
_, err = wd.sessionPOST(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, "")}
|
||||
urlStr := fmt.Sprintf("/session/%s/alert/text", wd.Session.ID)
|
||||
_, err = wd.Session.POST(data, urlStr)
|
||||
_, err = wd.sessionPOST(data, "/alert/text")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -498,8 +478,7 @@ func (wd *WDADriver) AppLaunch(bundleId string) (err error) {
|
||||
data["environment"] = map[string]interface{}{
|
||||
"SHOW_EXPLORER": "NO",
|
||||
}
|
||||
urlStr := fmt.Sprintf("/session/%s/wda/apps/launch", wd.Session.ID)
|
||||
_, err = wd.Session.POST(data, urlStr)
|
||||
_, err = wd.sessionPOST(data, "/wings/apps/launch")
|
||||
if err != nil {
|
||||
return errors.Wrap(code.MobileUILaunchAppError,
|
||||
fmt.Sprintf("wda launch failed: %v", err))
|
||||
@@ -511,7 +490,7 @@ func (wd *WDADriver) AppLaunchUnattached(bundleId string) (err error) {
|
||||
log.Info().Str("bundleId", bundleId).Msg("WDADriver.AppLaunchUnattached")
|
||||
// [[FBRoute POST:@"/wda/apps/launchUnattached"].withoutSession respondWithTarget:self action:@selector(handleLaunchUnattachedApp:)]
|
||||
data := map[string]interface{}{"bundleId": bundleId}
|
||||
_, err = wd.Session.POST(data, "/wda/apps/launchUnattached")
|
||||
_, err = wd.sessionPOST(data, "/wda/apps/launchUnattached")
|
||||
if err != nil {
|
||||
return errors.Wrap(code.MobileUILaunchAppError,
|
||||
fmt.Sprintf("wda launchUnattached failed: %v", err))
|
||||
@@ -524,8 +503,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 DriverRawResponse
|
||||
urlStr := fmt.Sprintf("/session/%s/wda/apps/terminate", wd.Session.ID)
|
||||
if rawResp, err = wd.Session.POST(data, urlStr); err != nil {
|
||||
if rawResp, err = wd.sessionPOST(data, "/wings/apps/terminate"); err != nil {
|
||||
return false, err
|
||||
}
|
||||
if successful, err = rawResp.ValueConvertToBool(); err != nil {
|
||||
@@ -538,21 +516,13 @@ func (wd *WDADriver) AppActivate(bundleId string) (err error) {
|
||||
log.Info().Str("bundleId", bundleId).Msg("WDADriver.AppActivate")
|
||||
// [[FBRoute POST:@"/wda/apps/activate"] respondWithTarget:self action:@selector(handleSessionAppActivate:)]
|
||||
data := map[string]interface{}{"bundleId": bundleId}
|
||||
urlStr := fmt.Sprintf("/session/%s/wda/apps/activate", wd.Session.ID)
|
||||
_, err = wd.Session.POST(data, urlStr)
|
||||
_, err = wd.sessionPOST(data, "/wings/apps/activate")
|
||||
return
|
||||
}
|
||||
|
||||
func (wd *WDADriver) AppDeactivate(second float64) (err error) {
|
||||
log.Info().Float64("second", second).Msg("WDADriver.AppDeactivate")
|
||||
// [[FBRoute POST:@"/wda/deactivateApp"] respondWithTarget:self action:@selector(handleDeactivateAppCommand:)]
|
||||
if second < 3 {
|
||||
second = 3.0
|
||||
}
|
||||
data := map[string]interface{}{"duration": second}
|
||||
urlStr := fmt.Sprintf("/session/%s/wda/deactivateApp", wd.Session.ID)
|
||||
_, err = wd.Session.POST(data, urlStr)
|
||||
return
|
||||
log.Warn().Float64("second", second).Msg("WDADriver.AppDeactivate not implemented")
|
||||
return nil
|
||||
}
|
||||
|
||||
func (wd *WDADriver) ForegroundInfo() (appInfo types.AppInfo, err error) {
|
||||
@@ -609,8 +579,7 @@ func (wd *WDADriver) TapAbsXY(x, y float64, opts ...option.ActionOption) error {
|
||||
}
|
||||
option.MergeOptions(data, opts...)
|
||||
|
||||
urlStr := fmt.Sprintf("/session/%s/wda/tap/0", wd.Session.ID)
|
||||
_, err = wd.Session.POST(data, urlStr)
|
||||
_, err = wd.sessionPOST(data, "/wings/interaction/tap")
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -632,8 +601,7 @@ func (wd *WDADriver) DoubleTap(x, y float64, opts ...option.ActionOption) error
|
||||
"x": x,
|
||||
"y": y,
|
||||
}
|
||||
urlStr := fmt.Sprintf("/session/%s/wda/doubleTap", wd.Session.ID)
|
||||
_, err = wd.Session.POST(data, urlStr)
|
||||
_, err = wd.sessionPOST(data, "/wings/interaction/doubleTap")
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -673,9 +641,7 @@ func (wd *WDADriver) Drag(fromX, fromY, toX, toY float64, opts ...option.ActionO
|
||||
}
|
||||
option.MergeOptions(data, opts...)
|
||||
// wda 43 version
|
||||
urlStr := fmt.Sprintf("/session/%s/wda/dragfromtoforduration", wd.Session.ID)
|
||||
_, err = wd.Session.POST(data, urlStr)
|
||||
// _, err = wd.Session.POST(data, "/session", wd.Session.ID, "/wda/drag")
|
||||
_, err = wd.sessionPOST(data, "/wings/interaction/drag")
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -689,8 +655,7 @@ func (wd *WDADriver) SetPasteboard(contentType types.PasteboardType, content str
|
||||
"contentType": contentType,
|
||||
"content": base64.StdEncoding.EncodeToString([]byte(content)),
|
||||
}
|
||||
urlStr := fmt.Sprintf("/session/%s/wda/setPasteboard", wd.Session.ID)
|
||||
_, err = wd.Session.POST(data, urlStr)
|
||||
_, err = wd.sessionPOST(data, "/wda/setPasteboard")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -698,8 +663,7 @@ func (wd *WDADriver) GetPasteboard(contentType types.PasteboardType) (raw *bytes
|
||||
// [[FBRoute POST:@"/wda/getPasteboard"] respondWithTarget:self action:@selector(handleGetPasteboard:)]
|
||||
data := map[string]interface{}{"contentType": contentType}
|
||||
var rawResp DriverRawResponse
|
||||
urlStr := fmt.Sprintf("/session/%s/wda/getPasteboard", wd.Session.ID)
|
||||
if rawResp, err = wd.Session.POST(data, urlStr); err != nil {
|
||||
if rawResp, err = wd.sessionPOST(data, "/wda/getPasteboard"); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if raw, err = rawResp.ValueDecodeAsBase64(); err != nil {
|
||||
@@ -717,8 +681,7 @@ func (wd *WDADriver) Input(text string, opts ...option.ActionOption) (err error)
|
||||
// [[FBRoute POST:@"/wda/keys"] respondWithTarget:self action:@selector(handleKeys:)]
|
||||
data := map[string]interface{}{"value": strings.Split(text, "")}
|
||||
option.MergeOptions(data, opts...)
|
||||
urlStr := fmt.Sprintf("/session/%s/wda/keys", wd.Session.ID)
|
||||
_, err = wd.Session.POST(data, urlStr)
|
||||
_, err = wd.sessionPOST(data, "/gtf/interaction/input")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -729,7 +692,7 @@ func (wd *WDADriver) Backspace(count int, opts ...option.ActionOption) (err erro
|
||||
}
|
||||
data := map[string]interface{}{"count": count}
|
||||
option.MergeOptions(data, opts...)
|
||||
_, err = wd.Session.POST(data, "/gtf/interaction/input/backspace")
|
||||
_, err = wd.sessionPOST(data, "/gtf/interaction/input/backspace")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -751,16 +714,14 @@ func (wd *WDADriver) PressButton(button types.DeviceButton) (err error) {
|
||||
}
|
||||
|
||||
data := map[string]interface{}{"name": button}
|
||||
urlStr := fmt.Sprintf("/session/%s/wda/pressButton", wd.Session.ID)
|
||||
_, err = wd.Session.POST(data, urlStr)
|
||||
_, err = wd.sessionPOST(data, "/wda/pressButton")
|
||||
return
|
||||
}
|
||||
|
||||
func (wd *WDADriver) Orientation() (orientation types.Orientation, err error) {
|
||||
// [[FBRoute GET:@"/orientation"] respondWithTarget:self action:@selector(handleGetOrientation:)]
|
||||
var rawResp DriverRawResponse
|
||||
urlStr := fmt.Sprintf("/session/%s/orientation", wd.Session.ID)
|
||||
if rawResp, err = wd.Session.GET(urlStr); err != nil {
|
||||
if rawResp, err = wd.sessionGET("/orientation"); err != nil {
|
||||
return "", err
|
||||
}
|
||||
reply := new(struct{ Value types.Orientation })
|
||||
@@ -774,16 +735,14 @@ func (wd *WDADriver) Orientation() (orientation types.Orientation, err error) {
|
||||
func (wd *WDADriver) SetOrientation(orientation types.Orientation) (err error) {
|
||||
// [[FBRoute POST:@"/orientation"] respondWithTarget:self action:@selector(handleSetOrientation:)]
|
||||
data := map[string]interface{}{"orientation": orientation}
|
||||
urlStr := fmt.Sprintf("/session/%s/orientation", wd.Session.ID)
|
||||
_, err = wd.Session.POST(data, urlStr)
|
||||
_, err = wd.sessionPOST(data, "/orientation")
|
||||
return
|
||||
}
|
||||
|
||||
func (wd *WDADriver) Rotation() (rotation types.Rotation, err error) {
|
||||
// [[FBRoute GET:@"/rotation"] respondWithTarget:self action:@selector(handleGetRotation:)]
|
||||
var rawResp DriverRawResponse
|
||||
urlStr := fmt.Sprintf("/session/%s/rotation", wd.Session.ID)
|
||||
if rawResp, err = wd.Session.GET(urlStr); err != nil {
|
||||
if rawResp, err = wd.sessionGET("/rotation"); err != nil {
|
||||
return types.Rotation{}, err
|
||||
}
|
||||
reply := new(struct{ Value types.Rotation })
|
||||
@@ -796,25 +755,21 @@ func (wd *WDADriver) Rotation() (rotation types.Rotation, err error) {
|
||||
|
||||
func (wd *WDADriver) SetRotation(rotation types.Rotation) (err error) {
|
||||
// [[FBRoute POST:@"/rotation"] respondWithTarget:self action:@selector(handleSetRotation:)]
|
||||
urlStr := fmt.Sprintf("/session/%s/rotation", wd.Session.ID)
|
||||
_, err = wd.Session.POST(rotation, urlStr)
|
||||
_, err = wd.sessionPOST(rotation, "/rotation")
|
||||
return
|
||||
}
|
||||
|
||||
func (wd *WDADriver) Source(srcOpt ...option.SourceOption) (source string, err error) {
|
||||
// [[FBRoute GET:@"/source"] respondWithTarget:self action:@selector(handleGetSourceCommand:)]
|
||||
// [[FBRoute GET:@"/source"].withoutSession
|
||||
// urlStr, err := wd.Session.concatURL("/session", wd.Session.ID)
|
||||
// if err != nil {
|
||||
// return "", err
|
||||
// }
|
||||
|
||||
options := option.NewSourceOptions(srcOpt...)
|
||||
query := options.Query()
|
||||
if len(query) > 0 {
|
||||
query = "?" + query
|
||||
}
|
||||
var rawResp DriverRawResponse
|
||||
if rawResp, err = wd.Session.GET("/source" + query); err != nil {
|
||||
if rawResp, err = wd.sessionGET("/source" + query); err != nil {
|
||||
return "", err
|
||||
}
|
||||
// json format
|
||||
@@ -837,8 +792,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 DriverRawResponse
|
||||
urlStr := fmt.Sprintf("/session/%s/wda/accessibleSource", wd.Session.ID)
|
||||
if rawResp, err = wd.Session.GET(urlStr); err != nil {
|
||||
if rawResp, err = wd.sessionGET("/wda/accessibleSource"); err != nil {
|
||||
return "", err
|
||||
}
|
||||
var jr builtinJSON.RawMessage
|
||||
@@ -851,13 +805,13 @@ 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.Session.GET("/wda/healthcheck")
|
||||
_, err = wd.sessionGET("/wda/healthcheck")
|
||||
return
|
||||
}
|
||||
|
||||
func (wd *WDADriver) IsHealthy() (healthy bool, err error) {
|
||||
var rawResp DriverRawResponse
|
||||
if rawResp, err = wd.Session.GET("/health"); err != nil {
|
||||
if rawResp, err = wd.sessionGET("/health"); err != nil {
|
||||
return false, err
|
||||
}
|
||||
if string(rawResp) != "I-AM-ALIVE" {
|
||||
@@ -869,8 +823,7 @@ func (wd *WDADriver) IsHealthy() (healthy bool, err error) {
|
||||
func (wd *WDADriver) GetAppiumSettings() (settings map[string]interface{}, err error) {
|
||||
// [[FBRoute GET:@"/appium/settings"] respondWithTarget:self action:@selector(handleGetSettings:)]
|
||||
var rawResp DriverRawResponse
|
||||
urlStr := fmt.Sprintf("/session/%s/appium/settings", wd.Session.ID)
|
||||
if rawResp, err = wd.Session.GET(urlStr); err != nil {
|
||||
if rawResp, err = wd.sessionGET("/appium/settings"); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
reply := new(struct{ Value map[string]interface{} })
|
||||
@@ -885,8 +838,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 DriverRawResponse
|
||||
urlStr := fmt.Sprintf("/session/%s/appium/settings", wd.Session.ID)
|
||||
if rawResp, err = wd.Session.POST(data, urlStr); err != nil {
|
||||
if rawResp, err = wd.sessionPOST(data, "/appium/settings"); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
reply := new(struct{ Value map[string]interface{} })
|
||||
@@ -898,13 +850,13 @@ func (wd *WDADriver) SetAppiumSettings(settings map[string]interface{}) (ret map
|
||||
}
|
||||
|
||||
func (wd *WDADriver) WdaShutdown() (err error) {
|
||||
_, err = wd.Session.GET("/wda/shutdown")
|
||||
_, err = wd.sessionGET("/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.Session.POST(data, "/gtf/automation/log")
|
||||
return wd.sessionPOST(data, "/gtf/automation/log")
|
||||
}
|
||||
|
||||
func (wd *WDADriver) ScreenRecord(opts ...option.ActionOption) (videoPath string, err error) {
|
||||
@@ -1000,7 +952,7 @@ func (wd *WDADriver) PushImage(localPath string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = wd.Session.POST(data, "/gtf/albums/add")
|
||||
_, err = wd.sessionPOST(data, "/gtf/albums/add")
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -1013,7 +965,7 @@ func (wd *WDADriver) ClearImages() error {
|
||||
log.Info().Msg("WDADriver.ClearImages")
|
||||
data := map[string]interface{}{}
|
||||
|
||||
_, err := wd.Session.POST(data, "/gtf/albums/clear")
|
||||
_, err := wd.sessionPOST(data, "/gtf/albums/clear")
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user