mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-08 22:13:13 +08:00
feat: 重构session和wda,去掉session概念。session_driver改为纯http调用工具
This commit is contained in:
@@ -10,7 +10,6 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"path"
|
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@@ -42,7 +41,6 @@ func NewDriverSession() *DriverSession {
|
|||||||
timeout := 30 * time.Second
|
timeout := 30 * time.Second
|
||||||
session := &DriverSession{
|
session := &DriverSession{
|
||||||
ctx: context.Background(),
|
ctx: context.Background(),
|
||||||
ID: "<SessionNotInit>",
|
|
||||||
timeout: timeout,
|
timeout: timeout,
|
||||||
client: &http.Client{
|
client: &http.Client{
|
||||||
Timeout: timeout,
|
Timeout: timeout,
|
||||||
@@ -55,8 +53,6 @@ func NewDriverSession() *DriverSession {
|
|||||||
|
|
||||||
type DriverSession struct {
|
type DriverSession struct {
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
ID string
|
|
||||||
baseUrl string
|
|
||||||
client *http.Client
|
client *http.Client
|
||||||
timeout time.Duration
|
timeout time.Duration
|
||||||
maxRetry int
|
maxRetry int
|
||||||
@@ -88,7 +84,8 @@ func (s *DriverSession) GetData(withReset bool) SessionData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *DriverSession) SetBaseURL(baseUrl string) {
|
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) {
|
func (s *DriverSession) RegisterResetHandler(fn func() error) {
|
||||||
@@ -103,23 +100,12 @@ func (s *DriverSession) History() []*DriverRequests {
|
|||||||
return s.requests
|
return s.requests
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DriverSession) concatURL(urlStr string) (string, error) {
|
func (s *DriverSession) buildURL(urlStr string) (string, error) {
|
||||||
if urlStr == "" || urlStr == "/" {
|
if urlStr == "" {
|
||||||
if s.baseUrl == "" {
|
return "", fmt.Errorf("URL cannot be empty")
|
||||||
return "", fmt.Errorf("base URL is empty")
|
|
||||||
}
|
|
||||||
return s.baseUrl, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// replace with session ID
|
// Handle full URLs
|
||||||
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
|
|
||||||
if strings.HasPrefix(urlStr, "http://") || strings.HasPrefix(urlStr, "https://") {
|
if strings.HasPrefix(urlStr, "http://") || strings.HasPrefix(urlStr, "https://") {
|
||||||
u, err := url.Parse(urlStr)
|
u, err := url.Parse(urlStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -128,49 +114,55 @@ func (s *DriverSession) concatURL(urlStr string) (string, error) {
|
|||||||
return u.String(), nil
|
return u.String(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 处理相对路径
|
// For relative paths, return as-is (caller should provide full URL)
|
||||||
if s.baseUrl == "" {
|
return urlStr, nil
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DriverSession) GET(urlStr string) (rawResp DriverRawResponse, err error) {
|
func (s *DriverSession) GET(fullURL string) (rawResp DriverRawResponse, err error) {
|
||||||
return s.RequestWithRetry(http.MethodGet, urlStr, nil)
|
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
|
var bsJSON []byte = nil
|
||||||
if data != nil {
|
if data != nil {
|
||||||
if bsJSON, err = json.Marshal(data); err != nil {
|
if bsJSON, err = json.Marshal(data); err != nil {
|
||||||
return nil, err
|
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) {
|
// POSTWithBaseURL allows passing baseURL and path separately
|
||||||
return s.RequestWithRetry(http.MethodDelete, urlStr, nil)
|
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) (
|
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++ {
|
for count := 1; count <= s.maxRetry; count++ {
|
||||||
rawResp, err = s.Request(method, urlStr, rawBody)
|
rawResp, err = s.Request(method, urlStr, rawBody)
|
||||||
if err == nil {
|
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) (
|
func (s *DriverSession) Request(method string, urlStr string, rawBody []byte) (
|
||||||
rawResp DriverRawResponse, err error) {
|
rawResp DriverRawResponse, err error,
|
||||||
|
) {
|
||||||
// concat url with base url
|
// build final URL
|
||||||
rawURL, err := s.concatURL(urlStr)
|
rawURL, err := s.buildURL(urlStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ type WDADriver struct {
|
|||||||
|
|
||||||
mjpegClient *http.Client
|
mjpegClient *http.Client
|
||||||
mjpegUrl string
|
mjpegUrl string
|
||||||
|
baseURL string // store base URL for building full URLs
|
||||||
}
|
}
|
||||||
|
|
||||||
func (wd *WDADriver) getLocalPort() (int, error) {
|
func (wd *WDADriver) getLocalPort() (int, error) {
|
||||||
@@ -137,7 +138,11 @@ func (wd *WDADriver) Setup() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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 {
|
if err = wd.initMjpegClient(); err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -155,6 +160,19 @@ func (wd *WDADriver) Setup() error {
|
|||||||
return nil
|
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 {
|
func (wd *WDADriver) TearDown() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -167,16 +185,7 @@ func (wd *WDADriver) InitSession(capabilities option.Capabilities) error {
|
|||||||
} else {
|
} else {
|
||||||
data["capabilities"] = map[string]interface{}{"alwaysMatch": capabilities}
|
data["capabilities"] = map[string]interface{}{"alwaysMatch": capabilities}
|
||||||
}
|
}
|
||||||
rawResp, err := wd.Session.POST(data, "/session")
|
// No longer need to track session ID
|
||||||
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
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -186,9 +195,6 @@ func (wd *WDADriver) DeleteSession() (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// [[FBRoute DELETE:@""] respondWithTarget:self action:@selector(handleDeleteSession:)]
|
// [[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()
|
wd.Session.client.CloseIdleConnections()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -197,7 +203,7 @@ func (wd *WDADriver) Status() (deviceStatus types.DeviceStatus, err error) {
|
|||||||
// [[FBRoute GET:@"/status"].withoutSession respondWithTarget:self action:@selector(handleGetStatus:)]
|
// [[FBRoute GET:@"/status"].withoutSession respondWithTarget:self action:@selector(handleGetStatus:)]
|
||||||
var rawResp DriverRawResponse
|
var rawResp DriverRawResponse
|
||||||
// Notice: use Driver.GET instead of httpGET to avoid loop calling
|
// 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
|
return types.DeviceStatus{}, err
|
||||||
}
|
}
|
||||||
reply := new(struct{ Value struct{ types.DeviceStatus } })
|
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"] respondWithTarget:self action:@selector(handleGetDeviceInfo:)]
|
||||||
// [[FBRoute GET:@"/wda/device/info"].withoutSession
|
// [[FBRoute GET:@"/wda/device/info"].withoutSession
|
||||||
var rawResp DriverRawResponse
|
var rawResp DriverRawResponse
|
||||||
urlStr := fmt.Sprintf("/session/%s/wda/device/info", wd.Session.ID)
|
if rawResp, err = wd.sessionGET("/wda/device/info"); err != nil {
|
||||||
if rawResp, err = wd.Session.GET(urlStr); err != nil {
|
|
||||||
return types.DeviceInfo{}, err
|
return types.DeviceInfo{}, err
|
||||||
}
|
}
|
||||||
reply := new(struct{ Value struct{ types.DeviceInfo } })
|
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"] respondWithTarget:self action:@selector(handleGetLocation:)]
|
||||||
// [[FBRoute GET:@"/wda/device/location"].withoutSession
|
// [[FBRoute GET:@"/wda/device/location"].withoutSession
|
||||||
var rawResp DriverRawResponse
|
var rawResp DriverRawResponse
|
||||||
urlStr := fmt.Sprintf("/session/%s/wda/device/location", wd.Session.ID)
|
if rawResp, err = wd.sessionGET("/wda/device/location"); err != nil {
|
||||||
if rawResp, err = wd.Session.GET(urlStr); err != nil {
|
|
||||||
return types.Location{}, err
|
return types.Location{}, err
|
||||||
}
|
}
|
||||||
reply := new(struct{ Value struct{ types.Location } })
|
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) {
|
func (wd *WDADriver) BatteryInfo() (batteryInfo types.BatteryInfo, err error) {
|
||||||
// [[FBRoute GET:@"/wda/batteryInfo"] respondWithTarget:self action:@selector(handleGetBatteryInfo:)]
|
// [[FBRoute GET:@"/wda/batteryInfo"] respondWithTarget:self action:@selector(handleGetBatteryInfo:)]
|
||||||
var rawResp DriverRawResponse
|
var rawResp DriverRawResponse
|
||||||
urlStr := fmt.Sprintf("/session/%s/wda/batteryInfo", wd.Session.ID)
|
if rawResp, err = wd.sessionGET("/wda/batteryInfo"); err != nil {
|
||||||
if rawResp, err = wd.Session.GET(urlStr); err != nil {
|
|
||||||
return types.BatteryInfo{}, err
|
return types.BatteryInfo{}, err
|
||||||
}
|
}
|
||||||
reply := new(struct{ Value struct{ types.BatteryInfo } })
|
reply := new(struct{ Value struct{ types.BatteryInfo } })
|
||||||
@@ -267,8 +270,7 @@ func (wd *WDADriver) WindowSize() (size types.Size, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var rawResp DriverRawResponse
|
var rawResp DriverRawResponse
|
||||||
urlStr := fmt.Sprintf("/session/%s/window/size", wd.Session.ID)
|
if rawResp, err = wd.sessionGET("/wings/window/size"); err != nil {
|
||||||
if rawResp, err = wd.Session.GET(urlStr); err != nil {
|
|
||||||
return types.Size{}, errors.Wrap(err, "get window size failed by WDA request")
|
return types.Size{}, errors.Wrap(err, "get window size failed by WDA request")
|
||||||
}
|
}
|
||||||
reply := new(struct{ Value struct{ types.Size } })
|
reply := new(struct{ Value struct{ types.Size } })
|
||||||
@@ -307,8 +309,7 @@ type Screen struct {
|
|||||||
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 DriverRawResponse
|
var rawResp DriverRawResponse
|
||||||
urlStr := fmt.Sprintf("/session/%s/wda/screen", wd.Session.ID)
|
if rawResp, err = wd.sessionGET("/wda/screen"); err != nil {
|
||||||
if rawResp, err = wd.Session.GET(urlStr); err != nil {
|
|
||||||
return Screen{}, err
|
return Screen{}, err
|
||||||
}
|
}
|
||||||
reply := new(struct{ Value struct{ Screen } })
|
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) {
|
func (wd *WDADriver) ScreenShot(opts ...option.ActionOption) (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:)]
|
||||||
urlStr := fmt.Sprintf("/session/%s/screenshot", wd.Session.ID)
|
rawResp, err := wd.sessionGET("/screenshot")
|
||||||
rawResp, err := wd.Session.GET(urlStr)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(code.DeviceScreenShotError,
|
return nil, errors.Wrap(code.DeviceScreenShotError,
|
||||||
fmt.Sprintf("WDA screenshot failed %v", err))
|
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"] respondWithTarget:self action:@selector(handleActiveAppInfo:)]
|
||||||
// [[FBRoute GET:@"/wda/activeAppInfo"].withoutSession
|
// [[FBRoute GET:@"/wda/activeAppInfo"].withoutSession
|
||||||
var rawResp DriverRawResponse
|
var rawResp DriverRawResponse
|
||||||
urlStr := fmt.Sprintf("/session/%s/wda/activeAppInfo", wd.Session.ID)
|
if rawResp, err = wd.sessionGET("/wda/activeAppInfo"); err != nil {
|
||||||
if rawResp, err = wd.Session.GET(urlStr); err != nil {
|
|
||||||
return types.AppInfo{}, err
|
return types.AppInfo{}, err
|
||||||
}
|
}
|
||||||
reply := new(struct{ Value struct{ types.AppInfo } })
|
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) {
|
func (wd *WDADriver) ActiveAppsList() (appsList []types.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 DriverRawResponse
|
var rawResp DriverRawResponse
|
||||||
urlStr := fmt.Sprintf("/session/%s/wda/apps/list", wd.Session.ID)
|
if rawResp, err = wd.sessionGET("/wda/apps/list"); err != nil {
|
||||||
if rawResp, err = wd.Session.GET(urlStr); err != nil {
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
reply := new(struct{ Value []types.AppBaseInfo })
|
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) {
|
func (wd *WDADriver) AppState(bundleId string) (runState types.AppState, err error) {
|
||||||
// [[FBRoute POST:@"/wda/apps/state"] respondWithTarget:self action:@selector(handleSessionAppState:)]
|
log.Warn().Str("bundleId", bundleId).Msg("WDADriver.AppState not implemented")
|
||||||
data := map[string]interface{}{"bundleId": bundleId}
|
return 0, nil
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (wd *WDADriver) IsLocked() (locked bool, err error) {
|
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 DriverRawResponse
|
var rawResp DriverRawResponse
|
||||||
urlStr := fmt.Sprintf("/session/%s/wda/locked", wd.Session.ID)
|
if rawResp, err = wd.sessionGET("/wda/locked"); err != nil {
|
||||||
if rawResp, err = wd.Session.GET(urlStr); err != nil {
|
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
if locked, err = rawResp.ValueConvertToBool(); err != nil {
|
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) {
|
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
|
||||||
urlStr := fmt.Sprintf("/session/%s/wda/unlock", wd.Session.ID)
|
_, err = wd.sessionPOST(nil, "/wda/unlock")
|
||||||
_, err = wd.Session.POST(nil, urlStr)
|
|
||||||
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
|
||||||
urlStr := fmt.Sprintf("/session/%s/wda/lock", wd.Session.ID)
|
_, err = wd.sessionPOST(nil, "/wda/lock")
|
||||||
_, err = wd.Session.POST(nil, urlStr)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (wd *WDADriver) Home() (err error) {
|
func (wd *WDADriver) Home() (err error) {
|
||||||
// [[FBRoute POST:@"/wda/homescreen"].withoutSession respondWithTarget:self action:@selector(handleHomescreenCommand:)]
|
// [[FBRoute POST:@"/wda/homescreen"].withoutSession respondWithTarget:self action:@selector(handleHomescreenCommand:)]
|
||||||
_, err = wd.Session.POST(nil, "/wda/homescreen")
|
_, err = wd.sessionPOST(nil, "/wda/homescreen")
|
||||||
return
|
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"] respondWithTarget:self action:@selector(handleAlertGetTextCommand:)]
|
||||||
// [[FBRoute GET:@"/alert/text"].withoutSession
|
// [[FBRoute GET:@"/alert/text"].withoutSession
|
||||||
var rawResp DriverRawResponse
|
var rawResp DriverRawResponse
|
||||||
urlStr := fmt.Sprintf("/session/%s/alert/text", wd.Session.ID)
|
if rawResp, err = wd.sessionGET("/alert/text"); err != nil {
|
||||||
if rawResp, err = wd.Session.GET(urlStr); err != nil {
|
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
if text, err = rawResp.ValueConvertToString(); err != nil {
|
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) {
|
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 DriverRawResponse
|
var rawResp DriverRawResponse
|
||||||
urlStr := fmt.Sprintf("/session/%s/wda/alert/buttons", wd.Session.ID)
|
if rawResp, err = wd.sessionGET("/wda/alert/buttons"); err != nil {
|
||||||
if rawResp, err = wd.Session.GET(urlStr); err != nil {
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
reply := new(struct{ Value []string })
|
reply := new(struct{ Value []string })
|
||||||
@@ -467,7 +448,7 @@ func (wd *WDADriver) AlertAccept(label ...string) (err error) {
|
|||||||
if len(label) != 0 && label[0] != "" {
|
if len(label) != 0 && label[0] != "" {
|
||||||
data["name"] = label[0]
|
data["name"] = label[0]
|
||||||
}
|
}
|
||||||
_, err = wd.Session.POST(data, "/alert/accept")
|
_, err = wd.sessionPOST(data, "/alert/accept")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -478,15 +459,14 @@ func (wd *WDADriver) AlertDismiss(label ...string) (err error) {
|
|||||||
if len(label) != 0 && label[0] != "" {
|
if len(label) != 0 && label[0] != "" {
|
||||||
data["name"] = label[0]
|
data["name"] = label[0]
|
||||||
}
|
}
|
||||||
_, err = wd.Session.POST(data, "/alert/dismiss")
|
_, err = wd.sessionPOST(data, "/alert/dismiss")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
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, "")}
|
||||||
urlStr := fmt.Sprintf("/session/%s/alert/text", wd.Session.ID)
|
_, err = wd.sessionPOST(data, "/alert/text")
|
||||||
_, err = wd.Session.POST(data, urlStr)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -498,8 +478,7 @@ func (wd *WDADriver) AppLaunch(bundleId string) (err error) {
|
|||||||
data["environment"] = map[string]interface{}{
|
data["environment"] = map[string]interface{}{
|
||||||
"SHOW_EXPLORER": "NO",
|
"SHOW_EXPLORER": "NO",
|
||||||
}
|
}
|
||||||
urlStr := fmt.Sprintf("/session/%s/wda/apps/launch", wd.Session.ID)
|
_, err = wd.sessionPOST(data, "/wings/apps/launch")
|
||||||
_, err = wd.Session.POST(data, urlStr)
|
|
||||||
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))
|
||||||
@@ -511,7 +490,7 @@ func (wd *WDADriver) AppLaunchUnattached(bundleId string) (err error) {
|
|||||||
log.Info().Str("bundleId", bundleId).Msg("WDADriver.AppLaunchUnattached")
|
log.Info().Str("bundleId", bundleId).Msg("WDADriver.AppLaunchUnattached")
|
||||||
// [[FBRoute POST:@"/wda/apps/launchUnattached"].withoutSession respondWithTarget:self action:@selector(handleLaunchUnattachedApp:)]
|
// [[FBRoute POST:@"/wda/apps/launchUnattached"].withoutSession respondWithTarget:self action:@selector(handleLaunchUnattachedApp:)]
|
||||||
data := map[string]interface{}{"bundleId": bundleId}
|
data := map[string]interface{}{"bundleId": bundleId}
|
||||||
_, err = wd.Session.POST(data, "/wda/apps/launchUnattached")
|
_, err = wd.sessionPOST(data, "/wda/apps/launchUnattached")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(code.MobileUILaunchAppError,
|
return errors.Wrap(code.MobileUILaunchAppError,
|
||||||
fmt.Sprintf("wda launchUnattached failed: %v", err))
|
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:)]
|
// [[FBRoute POST:@"/wda/apps/terminate"] respondWithTarget:self action:@selector(handleSessionAppTerminate:)]
|
||||||
data := map[string]interface{}{"bundleId": bundleId}
|
data := map[string]interface{}{"bundleId": bundleId}
|
||||||
var rawResp DriverRawResponse
|
var rawResp DriverRawResponse
|
||||||
urlStr := fmt.Sprintf("/session/%s/wda/apps/terminate", wd.Session.ID)
|
if rawResp, err = wd.sessionPOST(data, "/wings/apps/terminate"); err != nil {
|
||||||
if rawResp, err = wd.Session.POST(data, urlStr); err != nil {
|
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
if successful, err = rawResp.ValueConvertToBool(); err != nil {
|
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")
|
log.Info().Str("bundleId", bundleId).Msg("WDADriver.AppActivate")
|
||||||
// [[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}
|
||||||
urlStr := fmt.Sprintf("/session/%s/wda/apps/activate", wd.Session.ID)
|
_, err = wd.sessionPOST(data, "/wings/apps/activate")
|
||||||
_, err = wd.Session.POST(data, urlStr)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (wd *WDADriver) AppDeactivate(second float64) (err error) {
|
func (wd *WDADriver) AppDeactivate(second float64) (err error) {
|
||||||
log.Info().Float64("second", second).Msg("WDADriver.AppDeactivate")
|
log.Warn().Float64("second", second).Msg("WDADriver.AppDeactivate not implemented")
|
||||||
// [[FBRoute POST:@"/wda/deactivateApp"] respondWithTarget:self action:@selector(handleDeactivateAppCommand:)]
|
return nil
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (wd *WDADriver) ForegroundInfo() (appInfo types.AppInfo, err error) {
|
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...)
|
option.MergeOptions(data, opts...)
|
||||||
|
|
||||||
urlStr := fmt.Sprintf("/session/%s/wda/tap/0", wd.Session.ID)
|
_, err = wd.sessionPOST(data, "/wings/interaction/tap")
|
||||||
_, err = wd.Session.POST(data, urlStr)
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -632,8 +601,7 @@ func (wd *WDADriver) DoubleTap(x, y float64, opts ...option.ActionOption) error
|
|||||||
"x": x,
|
"x": x,
|
||||||
"y": y,
|
"y": y,
|
||||||
}
|
}
|
||||||
urlStr := fmt.Sprintf("/session/%s/wda/doubleTap", wd.Session.ID)
|
_, err = wd.sessionPOST(data, "/wings/interaction/doubleTap")
|
||||||
_, err = wd.Session.POST(data, urlStr)
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -673,9 +641,7 @@ func (wd *WDADriver) Drag(fromX, fromY, toX, toY float64, opts ...option.ActionO
|
|||||||
}
|
}
|
||||||
option.MergeOptions(data, opts...)
|
option.MergeOptions(data, opts...)
|
||||||
// wda 43 version
|
// wda 43 version
|
||||||
urlStr := fmt.Sprintf("/session/%s/wda/dragfromtoforduration", wd.Session.ID)
|
_, err = wd.sessionPOST(data, "/wings/interaction/drag")
|
||||||
_, err = wd.Session.POST(data, urlStr)
|
|
||||||
// _, err = wd.Session.POST(data, "/session", wd.Session.ID, "/wda/drag")
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -689,8 +655,7 @@ func (wd *WDADriver) SetPasteboard(contentType types.PasteboardType, content str
|
|||||||
"contentType": contentType,
|
"contentType": contentType,
|
||||||
"content": base64.StdEncoding.EncodeToString([]byte(content)),
|
"content": base64.StdEncoding.EncodeToString([]byte(content)),
|
||||||
}
|
}
|
||||||
urlStr := fmt.Sprintf("/session/%s/wda/setPasteboard", wd.Session.ID)
|
_, err = wd.sessionPOST(data, "/wda/setPasteboard")
|
||||||
_, err = wd.Session.POST(data, urlStr)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -698,8 +663,7 @@ func (wd *WDADriver) GetPasteboard(contentType types.PasteboardType) (raw *bytes
|
|||||||
// [[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 DriverRawResponse
|
var rawResp DriverRawResponse
|
||||||
urlStr := fmt.Sprintf("/session/%s/wda/getPasteboard", wd.Session.ID)
|
if rawResp, err = wd.sessionPOST(data, "/wda/getPasteboard"); err != nil {
|
||||||
if rawResp, err = wd.Session.POST(data, urlStr); err != nil {
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if raw, err = rawResp.ValueDecodeAsBase64(); err != nil {
|
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:)]
|
// [[FBRoute POST:@"/wda/keys"] respondWithTarget:self action:@selector(handleKeys:)]
|
||||||
data := map[string]interface{}{"value": strings.Split(text, "")}
|
data := map[string]interface{}{"value": strings.Split(text, "")}
|
||||||
option.MergeOptions(data, opts...)
|
option.MergeOptions(data, opts...)
|
||||||
urlStr := fmt.Sprintf("/session/%s/wda/keys", wd.Session.ID)
|
_, err = wd.sessionPOST(data, "/gtf/interaction/input")
|
||||||
_, err = wd.Session.POST(data, urlStr)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -729,7 +692,7 @@ func (wd *WDADriver) Backspace(count int, opts ...option.ActionOption) (err erro
|
|||||||
}
|
}
|
||||||
data := map[string]interface{}{"count": count}
|
data := map[string]interface{}{"count": count}
|
||||||
option.MergeOptions(data, opts...)
|
option.MergeOptions(data, opts...)
|
||||||
_, err = wd.Session.POST(data, "/gtf/interaction/input/backspace")
|
_, err = wd.sessionPOST(data, "/gtf/interaction/input/backspace")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -751,16 +714,14 @@ func (wd *WDADriver) PressButton(button types.DeviceButton) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
data := map[string]interface{}{"name": button}
|
data := map[string]interface{}{"name": button}
|
||||||
urlStr := fmt.Sprintf("/session/%s/wda/pressButton", wd.Session.ID)
|
_, err = wd.sessionPOST(data, "/wda/pressButton")
|
||||||
_, err = wd.Session.POST(data, urlStr)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (wd *WDADriver) Orientation() (orientation types.Orientation, err error) {
|
func (wd *WDADriver) Orientation() (orientation types.Orientation, err error) {
|
||||||
// [[FBRoute GET:@"/orientation"] respondWithTarget:self action:@selector(handleGetOrientation:)]
|
// [[FBRoute GET:@"/orientation"] respondWithTarget:self action:@selector(handleGetOrientation:)]
|
||||||
var rawResp DriverRawResponse
|
var rawResp DriverRawResponse
|
||||||
urlStr := fmt.Sprintf("/session/%s/orientation", wd.Session.ID)
|
if rawResp, err = wd.sessionGET("/orientation"); err != nil {
|
||||||
if rawResp, err = wd.Session.GET(urlStr); err != nil {
|
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
reply := new(struct{ Value types.Orientation })
|
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) {
|
func (wd *WDADriver) SetOrientation(orientation types.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}
|
||||||
urlStr := fmt.Sprintf("/session/%s/orientation", wd.Session.ID)
|
_, err = wd.sessionPOST(data, "/orientation")
|
||||||
_, err = wd.Session.POST(data, urlStr)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (wd *WDADriver) Rotation() (rotation types.Rotation, err error) {
|
func (wd *WDADriver) Rotation() (rotation types.Rotation, err error) {
|
||||||
// [[FBRoute GET:@"/rotation"] respondWithTarget:self action:@selector(handleGetRotation:)]
|
// [[FBRoute GET:@"/rotation"] respondWithTarget:self action:@selector(handleGetRotation:)]
|
||||||
var rawResp DriverRawResponse
|
var rawResp DriverRawResponse
|
||||||
urlStr := fmt.Sprintf("/session/%s/rotation", wd.Session.ID)
|
if rawResp, err = wd.sessionGET("/rotation"); err != nil {
|
||||||
if rawResp, err = wd.Session.GET(urlStr); err != nil {
|
|
||||||
return types.Rotation{}, err
|
return types.Rotation{}, err
|
||||||
}
|
}
|
||||||
reply := new(struct{ Value types.Rotation })
|
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) {
|
func (wd *WDADriver) SetRotation(rotation types.Rotation) (err error) {
|
||||||
// [[FBRoute POST:@"/rotation"] respondWithTarget:self action:@selector(handleSetRotation:)]
|
// [[FBRoute POST:@"/rotation"] respondWithTarget:self action:@selector(handleSetRotation:)]
|
||||||
urlStr := fmt.Sprintf("/session/%s/rotation", wd.Session.ID)
|
_, err = wd.sessionPOST(rotation, "/rotation")
|
||||||
_, err = wd.Session.POST(rotation, urlStr)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (wd *WDADriver) Source(srcOpt ...option.SourceOption) (source string, err error) {
|
func (wd *WDADriver) Source(srcOpt ...option.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
|
||||||
// urlStr, err := wd.Session.concatURL("/session", wd.Session.ID)
|
|
||||||
// if err != nil {
|
|
||||||
// return "", err
|
|
||||||
// }
|
|
||||||
options := option.NewSourceOptions(srcOpt...)
|
options := option.NewSourceOptions(srcOpt...)
|
||||||
query := options.Query()
|
query := options.Query()
|
||||||
if len(query) > 0 {
|
if len(query) > 0 {
|
||||||
query = "?" + query
|
query = "?" + query
|
||||||
}
|
}
|
||||||
var rawResp DriverRawResponse
|
var rawResp DriverRawResponse
|
||||||
if rawResp, err = wd.Session.GET("/source" + query); err != nil {
|
if rawResp, err = wd.sessionGET("/source" + query); err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
// json format
|
// 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"] respondWithTarget:self action:@selector(handleGetAccessibleSourceCommand:)]
|
||||||
// [[FBRoute GET:@"/wda/accessibleSource"].withoutSession
|
// [[FBRoute GET:@"/wda/accessibleSource"].withoutSession
|
||||||
var rawResp DriverRawResponse
|
var rawResp DriverRawResponse
|
||||||
urlStr := fmt.Sprintf("/session/%s/wda/accessibleSource", wd.Session.ID)
|
if rawResp, err = wd.sessionGET("/wda/accessibleSource"); err != nil {
|
||||||
if rawResp, err = wd.Session.GET(urlStr); err != nil {
|
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
var jr builtinJSON.RawMessage
|
var jr builtinJSON.RawMessage
|
||||||
@@ -851,13 +805,13 @@ func (wd *WDADriver) AccessibleSource() (source string, err error) {
|
|||||||
|
|
||||||
func (wd *WDADriver) HealthCheck() (err error) {
|
func (wd *WDADriver) HealthCheck() (err error) {
|
||||||
// [[FBRoute GET:@"/wda/healthcheck"].withoutSession respondWithTarget:self action:@selector(handleGetHealthCheck:)]
|
// [[FBRoute GET:@"/wda/healthcheck"].withoutSession respondWithTarget:self action:@selector(handleGetHealthCheck:)]
|
||||||
_, err = wd.Session.GET("/wda/healthcheck")
|
_, err = wd.sessionGET("/wda/healthcheck")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (wd *WDADriver) IsHealthy() (healthy bool, err error) {
|
func (wd *WDADriver) IsHealthy() (healthy bool, err error) {
|
||||||
var rawResp DriverRawResponse
|
var rawResp DriverRawResponse
|
||||||
if rawResp, err = wd.Session.GET("/health"); err != nil {
|
if rawResp, err = wd.sessionGET("/health"); err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
if string(rawResp) != "I-AM-ALIVE" {
|
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) {
|
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 DriverRawResponse
|
var rawResp DriverRawResponse
|
||||||
urlStr := fmt.Sprintf("/session/%s/appium/settings", wd.Session.ID)
|
if rawResp, err = wd.sessionGET("/appium/settings"); err != nil {
|
||||||
if rawResp, err = wd.Session.GET(urlStr); err != nil {
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
reply := new(struct{ Value map[string]interface{} })
|
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:)]
|
// [[FBRoute POST:@"/appium/settings"] respondWithTarget:self action:@selector(handleSetSettings:)]
|
||||||
data := map[string]interface{}{"settings": settings}
|
data := map[string]interface{}{"settings": settings}
|
||||||
var rawResp DriverRawResponse
|
var rawResp DriverRawResponse
|
||||||
urlStr := fmt.Sprintf("/session/%s/appium/settings", wd.Session.ID)
|
if rawResp, err = wd.sessionPOST(data, "/appium/settings"); err != nil {
|
||||||
if rawResp, err = wd.Session.POST(data, urlStr); err != nil {
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
reply := new(struct{ Value map[string]interface{} })
|
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) {
|
func (wd *WDADriver) WdaShutdown() (err error) {
|
||||||
_, err = wd.Session.GET("/wda/shutdown")
|
_, err = wd.sessionGET("/wda/shutdown")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (wd *WDADriver) triggerWDALog(data map[string]interface{}) (rawResp []byte, err error) {
|
func (wd *WDADriver) triggerWDALog(data map[string]interface{}) (rawResp []byte, err error) {
|
||||||
// [[FBRoute POST:@"/gtf/automation/log"].withoutSession respondWithTarget:self action:@selector(handleAutomationLog:)]
|
// [[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) {
|
func (wd *WDADriver) ScreenRecord(opts ...option.ActionOption) (videoPath string, err error) {
|
||||||
@@ -1000,7 +952,7 @@ func (wd *WDADriver) PushImage(localPath string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = wd.Session.POST(data, "/gtf/albums/add")
|
_, err = wd.sessionPOST(data, "/gtf/albums/add")
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1013,7 +965,7 @@ func (wd *WDADriver) ClearImages() error {
|
|||||||
log.Info().Msg("WDADriver.ClearImages")
|
log.Info().Msg("WDADriver.ClearImages")
|
||||||
data := map[string]interface{}{}
|
data := map[string]interface{}{}
|
||||||
|
|
||||||
_, err := wd.Session.POST(data, "/gtf/albums/clear")
|
_, err := wd.sessionPOST(data, "/gtf/albums/clear")
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user