refactor: update URL handling in DriverSession and WDADriver, removing base URL dependency for HTTP requests

This commit is contained in:
lilong.129
2025-06-26 14:37:41 +08:00
parent 88d255bce1
commit 3e4858db44
4 changed files with 144 additions and 129 deletions

View File

@@ -1 +1 @@
v5.0.0-beta-2506261418
v5.0.0-beta-2506261437

View File

@@ -103,8 +103,11 @@ func (s *DriverSession) History() []*DriverRequests {
}
func (s *DriverSession) buildURL(urlStr string) (string, error) {
if urlStr == "" {
return "", fmt.Errorf("URL cannot be empty")
if urlStr == "" || urlStr == "/" {
if s.baseUrl == "" {
return "", fmt.Errorf("base URL is empty")
}
return s.baseUrl, nil
}
// Handle full URLs
@@ -116,26 +119,40 @@ func (s *DriverSession) buildURL(urlStr string) (string, error) {
return u.String(), nil
}
// For relative paths, return as-is (caller should provide full URL)
return urlStr, nil
// handle relative path using ResolveReference
if s.baseUrl == "" {
return "", fmt.Errorf("base URL is empty")
}
baseURL, err := url.Parse(s.baseUrl)
if err != nil {
return "", fmt.Errorf("failed to parse base URL: %w", err)
}
relativeURL, err := url.Parse(urlStr)
if err != nil {
return "", fmt.Errorf("failed to parse relative URL: %w", err)
}
finalURL := baseURL.ResolveReference(relativeURL)
return finalURL.String(), nil
}
func (s *DriverSession) GET(fullURL string) (rawResp DriverRawResponse, err error) {
return s.RequestWithRetry(http.MethodGet, fullURL, nil)
func (s *DriverSession) GET(urlStr string) (rawResp DriverRawResponse, err error) {
return s.RequestWithRetry(http.MethodGet, urlStr, nil)
}
func (s *DriverSession) POST(data interface{}, fullURL string) (rawResp DriverRawResponse, err error) {
func (s *DriverSession) POST(data interface{}, urlStr 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, fullURL, bsJSON)
return s.RequestWithRetry(http.MethodPost, urlStr, bsJSON)
}
func (s *DriverSession) DELETE(fullURL string) (rawResp DriverRawResponse, err error) {
return s.RequestWithRetry(http.MethodDelete, fullURL, nil)
func (s *DriverSession) DELETE(urlStr string) (rawResp DriverRawResponse, err error) {
return s.RequestWithRetry(http.MethodDelete, urlStr, nil)
}
func (s *DriverSession) RequestWithRetry(method string, urlStr string, rawBody []byte) (

View File

@@ -9,17 +9,33 @@ import (
func TestDriverSession_buildURL(t *testing.T) {
tests := []struct {
name string
baseURL string
urlStr string
want string
wantErr bool
errMsg string
}{
// Error cases
{
name: "empty url",
name: "empty url without baseUrl",
urlStr: "",
wantErr: true,
errMsg: "URL cannot be empty",
errMsg: "base URL is empty",
},
{
name: "relative path without baseUrl",
urlStr: "/api/users",
wantErr: true,
errMsg: "base URL is empty",
},
{
name: "invalid absolute url",
urlStr: "http://[invalid-url",
wantErr: true,
errMsg: "failed to parse URL",
},
// Absolute URLs (no baseURL needed)
{
name: "absolute http url",
urlStr: "http://example.com/api",
@@ -30,27 +46,63 @@ func TestDriverSession_buildURL(t *testing.T) {
urlStr: "https://example.com/api",
want: "https://example.com/api",
},
// Empty/root path with baseURL
{
name: "invalid absolute url",
urlStr: "http://[invalid-url",
wantErr: true,
errMsg: "failed to parse URL",
name: "empty url with baseUrl",
baseURL: "http://localhost:8080",
urlStr: "",
want: "http://localhost:8080",
},
{
name: "relative path",
urlStr: "/api/users",
want: "/api/users",
name: "root path with baseUrl",
baseURL: "http://localhost:8080",
urlStr: "/",
want: "http://localhost:8080",
},
// Relative paths with baseURL
{
name: "relative path with leading slash",
baseURL: "http://localhost:8080",
urlStr: "/api/users",
want: "http://localhost:8080/api/users",
},
{
name: "relative path with query params",
urlStr: "/api/users?id=1&name=test",
want: "/api/users?id=1&name=test",
name: "relative path without leading slash",
baseURL: "http://localhost:8080/api",
urlStr: "users",
want: "http://localhost:8080/users",
},
{
name: "relative path with query params",
baseURL: "http://localhost:8080",
urlStr: "/api/users?id=1&name=test",
want: "http://localhost:8080/api/users?id=1&name=test",
},
// BaseURL with path scenarios
{
name: "baseUrl with path + relative path",
baseURL: "http://localhost:8080/api/v1",
urlStr: "users",
want: "http://localhost:8080/api/users",
},
{
name: "baseUrl with trailing slash + relative path",
baseURL: "http://localhost:8080/api/",
urlStr: "users",
want: "http://localhost:8080/api/users",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
s := NewDriverSession()
if tt.baseURL != "" {
s.SetBaseURL(tt.baseURL)
}
got, err := s.buildURL(tt.urlStr)
if tt.wantErr {
@@ -65,61 +117,8 @@ func TestDriverSession_buildURL(t *testing.T) {
}
}
func TestDriverSession_WithBaseURL(t *testing.T) {
tests := []struct {
name string
baseURL string
path string
want string
}{
{
name: "base url with root path",
baseURL: "http://localhost:8080",
path: "/",
want: "http://localhost:8080/",
},
{
name: "base url with api path",
baseURL: "http://localhost:8080",
path: "/api/users",
want: "http://localhost:8080/api/users",
},
{
name: "base url with path and query params",
baseURL: "http://localhost:8080",
path: "/api/users?id=1&name=test",
want: "http://localhost:8080/api/users?id=1&name=test",
},
{
name: "base url with trailing slash and path",
baseURL: "http://localhost:8080/",
path: "api/users",
want: "http://localhost:8080/api/users",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
s := NewDriverSession()
// Test that the URL concatenation works as expected
fullURL := tt.baseURL + tt.path
assert.Equal(t, tt.want, fullURL)
// Test that buildURL handles the resulting full URL correctly
if fullURL != "" {
got, err := s.buildURL(fullURL)
assert.NoError(t, err)
assert.Equal(t, tt.want, got)
}
})
}
}
func TestDriverSession(t *testing.T) {
session := NewDriverSession()
// Test backward compatibility with SetBaseURL (should not error)
session.SetBaseURL("https://postman-echo.com")
// Test GET with full URL
@@ -132,21 +131,22 @@ func TestDriverSession(t *testing.T) {
assert.Nil(t, err)
t.Log(resp)
// Test GETWithBaseURL
baseURL := "https://postman-echo.com"
resp, err = session.GET(baseURL + "/get")
// Test GET with relative path (using baseURL)
resp, err = session.GET("/get")
assert.Nil(t, err)
t.Log(resp)
// Verify request history
driverRequests := session.History()
assert.Equal(t, 3, len(driverRequests))
// Test reset functionality
session.Reset()
driverRequests = session.History()
assert.Equal(t, 0, len(driverRequests))
// Test POST with base URL and path
resp, err = session.POST(nil, baseURL+"/post")
// Test POST with relative path
resp, err = session.POST(nil, "/post")
assert.Nil(t, err)
t.Log(resp)

View File

@@ -59,7 +59,6 @@ type WDADriver struct {
mjpegClient *http.Client
mjpegUrl string
baseURL string // store base URL for building full URLs
}
func (wd *WDADriver) getLocalPort() (int, error) {
@@ -140,9 +139,8 @@ func (wd *WDADriver) Setup() error {
}
// 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)
baseURL := fmt.Sprintf("http://localhost:%d", localPort)
wd.Session.SetBaseURL(baseURL)
if err = wd.initMjpegClient(); err != nil {
return err
@@ -190,7 +188,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(wd.baseURL + "/status"); err != nil {
if rawResp, err = wd.Session.GET("/status"); err != nil {
return types.DeviceStatus{}, err
}
reply := new(struct{ Value struct{ types.DeviceStatus } })
@@ -209,7 +207,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
if rawResp, err = wd.Session.GET(wd.baseURL + "/wda/device/info"); err != nil {
if rawResp, err = wd.Session.GET("/wda/device/info"); err != nil {
return types.DeviceInfo{}, err
}
reply := new(struct{ Value struct{ types.DeviceInfo } })
@@ -224,7 +222,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
if rawResp, err = wd.Session.GET(wd.baseURL + "/wda/device/location"); err != nil {
if rawResp, err = wd.Session.GET("/wda/device/location"); err != nil {
return types.Location{}, err
}
reply := new(struct{ Value struct{ types.Location } })
@@ -238,7 +236,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
if rawResp, err = wd.Session.GET(wd.baseURL + "/wda/batteryInfo"); err != nil {
if rawResp, err = wd.Session.GET("/wda/batteryInfo"); err != nil {
return types.BatteryInfo{}, err
}
reply := new(struct{ Value struct{ types.BatteryInfo } })
@@ -257,7 +255,7 @@ func (wd *WDADriver) WindowSize() (size types.Size, err error) {
}
var rawResp DriverRawResponse
if rawResp, err = wd.Session.GET(wd.baseURL + "/wings/window/size"); err != nil {
if rawResp, err = wd.Session.GET("/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 } })
@@ -296,7 +294,7 @@ type Screen struct {
func (wd *WDADriver) Screen() (screen Screen, err error) {
// [[FBRoute GET:@"/wda/screen"] respondWithTarget:self action:@selector(handleGetScreen:)]
var rawResp DriverRawResponse
if rawResp, err = wd.Session.GET(wd.baseURL + "/wda/screen"); err != nil {
if rawResp, err = wd.Session.GET("/wda/screen"); err != nil {
return Screen{}, err
}
reply := new(struct{ Value struct{ Screen } })
@@ -310,7 +308,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:)]
rawResp, err := wd.Session.GET(wd.baseURL + "/screenshot")
rawResp, err := wd.Session.GET("/screenshot")
if err != nil {
return nil, errors.Wrap(code.DeviceScreenShotError,
fmt.Sprintf("WDA screenshot failed %v", err))
@@ -338,7 +336,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
if rawResp, err = wd.Session.GET(wd.baseURL + "/wda/activeAppInfo"); err != nil {
if rawResp, err = wd.Session.GET("/wda/activeAppInfo"); err != nil {
return types.AppInfo{}, err
}
reply := new(struct{ Value struct{ types.AppInfo } })
@@ -352,7 +350,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
if rawResp, err = wd.Session.GET(wd.baseURL + "/wda/apps/list"); err != nil {
if rawResp, err = wd.Session.GET("/wda/apps/list"); err != nil {
return nil, err
}
reply := new(struct{ Value []types.AppBaseInfo })
@@ -372,7 +370,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 DriverRawResponse
if rawResp, err = wd.Session.GET(wd.baseURL + "/wda/locked"); err != nil {
if rawResp, err = wd.Session.GET("/wda/locked"); err != nil {
return false, err
}
if locked, err = rawResp.ValueConvertToBool(); err != nil {
@@ -384,20 +382,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.Session.POST(nil, wd.baseURL+"/wda/unlock")
_, err = wd.Session.POST(nil, "/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.Session.POST(nil, wd.baseURL+"/wda/lock")
_, err = wd.Session.POST(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, wd.baseURL+"/wda/homescreen")
_, err = wd.Session.POST(nil, "/wda/homescreen")
return
}
@@ -405,7 +403,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
if rawResp, err = wd.Session.GET(wd.baseURL + "/alert/text"); err != nil {
if rawResp, err = wd.Session.GET("/alert/text"); err != nil {
return "", err
}
if text, err = rawResp.ValueConvertToString(); err != nil {
@@ -417,7 +415,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
if rawResp, err = wd.Session.GET(wd.baseURL + "/wda/alert/buttons"); err != nil {
if rawResp, err = wd.Session.GET("/wda/alert/buttons"); err != nil {
return nil, err
}
reply := new(struct{ Value []string })
@@ -435,7 +433,7 @@ func (wd *WDADriver) AlertAccept(label ...string) (err error) {
if len(label) != 0 && label[0] != "" {
data["name"] = label[0]
}
_, err = wd.Session.POST(data, wd.baseURL+"/alert/accept")
_, err = wd.Session.POST(data, "/alert/accept")
return
}
@@ -446,14 +444,14 @@ func (wd *WDADriver) AlertDismiss(label ...string) (err error) {
if len(label) != 0 && label[0] != "" {
data["name"] = label[0]
}
_, err = wd.Session.POST(data, wd.baseURL+"/alert/dismiss")
_, err = wd.Session.POST(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.Session.POST(data, wd.baseURL+"/alert/text")
_, err = wd.Session.POST(data, "/alert/text")
return
}
@@ -465,7 +463,7 @@ func (wd *WDADriver) AppLaunch(bundleId string) (err error) {
data["environment"] = map[string]interface{}{
"SHOW_EXPLORER": "NO",
}
_, err = wd.Session.POST(data, wd.baseURL+"/wings/apps/launch")
_, err = wd.Session.POST(data, "/wings/apps/launch")
if err != nil {
return errors.Wrap(code.MobileUILaunchAppError,
fmt.Sprintf("wda launch failed: %v", err))
@@ -477,7 +475,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, wd.baseURL+"/wda/apps/launchUnattached")
_, err = wd.Session.POST(data, "/wda/apps/launchUnattached")
if err != nil {
return errors.Wrap(code.MobileUILaunchAppError,
fmt.Sprintf("wda launchUnattached failed: %v", err))
@@ -490,7 +488,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
if rawResp, err = wd.Session.POST(data, wd.baseURL+"/wings/apps/terminate"); err != nil {
if rawResp, err = wd.Session.POST(data, "/wings/apps/terminate"); err != nil {
return false, err
}
if successful, err = rawResp.ValueConvertToBool(); err != nil {
@@ -503,7 +501,7 @@ 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}
_, err = wd.Session.POST(data, wd.baseURL+"/wings/apps/activate")
_, err = wd.Session.POST(data, "/wings/apps/activate")
return
}
@@ -566,7 +564,7 @@ func (wd *WDADriver) TapAbsXY(x, y float64, opts ...option.ActionOption) error {
}
option.MergeOptions(data, opts...)
_, err = wd.Session.POST(data, wd.baseURL+"/wings/interaction/tap")
_, err = wd.Session.POST(data, "/wings/interaction/tap")
return err
}
@@ -588,7 +586,7 @@ func (wd *WDADriver) DoubleTap(x, y float64, opts ...option.ActionOption) error
"x": x,
"y": y,
}
_, err = wd.Session.POST(data, wd.baseURL+"/wings/interaction/doubleTap")
_, err = wd.Session.POST(data, "/wings/interaction/doubleTap")
return err
}
@@ -628,7 +626,7 @@ func (wd *WDADriver) Drag(fromX, fromY, toX, toY float64, opts ...option.ActionO
}
option.MergeOptions(data, opts...)
// wda 43 version
_, err = wd.Session.POST(data, wd.baseURL+"/wings/interaction/drag")
_, err = wd.Session.POST(data, "/wings/interaction/drag")
return err
}
@@ -642,7 +640,7 @@ func (wd *WDADriver) SetPasteboard(contentType types.PasteboardType, content str
"contentType": contentType,
"content": base64.StdEncoding.EncodeToString([]byte(content)),
}
_, err = wd.Session.POST(data, wd.baseURL+"/wda/setPasteboard")
_, err = wd.Session.POST(data, "/wda/setPasteboard")
return
}
@@ -650,7 +648,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
if rawResp, err = wd.Session.POST(data, wd.baseURL+"/wda/getPasteboard"); err != nil {
if rawResp, err = wd.Session.POST(data, "/wda/getPasteboard"); err != nil {
return nil, err
}
if raw, err = rawResp.ValueDecodeAsBase64(); err != nil {
@@ -668,7 +666,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...)
_, err = wd.Session.POST(data, wd.baseURL+"/gtf/interaction/input")
_, err = wd.Session.POST(data, "/gtf/interaction/input")
return
}
@@ -679,7 +677,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, wd.baseURL+"/gtf/interaction/input/backspace")
_, err = wd.Session.POST(data, "/gtf/interaction/input/backspace")
return
}
@@ -701,14 +699,14 @@ func (wd *WDADriver) PressButton(button types.DeviceButton) (err error) {
}
data := map[string]interface{}{"name": button}
_, err = wd.Session.POST(data, wd.baseURL+"/wda/pressButton")
_, err = wd.Session.POST(data, "/wda/pressButton")
return
}
func (wd *WDADriver) Orientation() (orientation types.Orientation, err error) {
// [[FBRoute GET:@"/orientation"] respondWithTarget:self action:@selector(handleGetOrientation:)]
var rawResp DriverRawResponse
if rawResp, err = wd.Session.GET(wd.baseURL + "/orientation"); err != nil {
if rawResp, err = wd.Session.GET("/orientation"); err != nil {
return "", err
}
reply := new(struct{ Value types.Orientation })
@@ -722,14 +720,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}
_, err = wd.Session.POST(data, wd.baseURL+"/orientation")
_, err = wd.Session.POST(data, "/orientation")
return
}
func (wd *WDADriver) Rotation() (rotation types.Rotation, err error) {
// [[FBRoute GET:@"/rotation"] respondWithTarget:self action:@selector(handleGetRotation:)]
var rawResp DriverRawResponse
if rawResp, err = wd.Session.GET(wd.baseURL + "/rotation"); err != nil {
if rawResp, err = wd.Session.GET("/rotation"); err != nil {
return types.Rotation{}, err
}
reply := new(struct{ Value types.Rotation })
@@ -742,7 +740,7 @@ 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:)]
_, err = wd.Session.POST(rotation, wd.baseURL+"/rotation")
_, err = wd.Session.POST(rotation, "/rotation")
return
}
@@ -756,7 +754,7 @@ func (wd *WDADriver) Source(srcOpt ...option.SourceOption) (source string, err e
query = "?" + query
}
var rawResp DriverRawResponse
if rawResp, err = wd.Session.GET(wd.baseURL + "/source" + query); err != nil {
if rawResp, err = wd.Session.GET("/source" + query); err != nil {
return "", err
}
// json format
@@ -779,7 +777,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
if rawResp, err = wd.Session.GET(wd.baseURL + "/wda/accessibleSource"); err != nil {
if rawResp, err = wd.Session.GET("/wda/accessibleSource"); err != nil {
return "", err
}
var jr builtinJSON.RawMessage
@@ -792,13 +790,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(wd.baseURL + "/wda/healthcheck")
_, err = wd.Session.GET("/wda/healthcheck")
return
}
func (wd *WDADriver) IsHealthy() (healthy bool, err error) {
var rawResp DriverRawResponse
if rawResp, err = wd.Session.GET(wd.baseURL + "/health"); err != nil {
if rawResp, err = wd.Session.GET("/health"); err != nil {
return false, err
}
if string(rawResp) != "I-AM-ALIVE" {
@@ -810,7 +808,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
if rawResp, err = wd.Session.GET(wd.baseURL + "/appium/settings"); err != nil {
if rawResp, err = wd.Session.GET("/appium/settings"); err != nil {
return nil, err
}
reply := new(struct{ Value map[string]interface{} })
@@ -825,7 +823,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
if rawResp, err = wd.Session.POST(data, wd.baseURL+"/appium/settings"); err != nil {
if rawResp, err = wd.Session.POST(data, "/appium/settings"); err != nil {
return nil, err
}
reply := new(struct{ Value map[string]interface{} })
@@ -837,13 +835,13 @@ func (wd *WDADriver) SetAppiumSettings(settings map[string]interface{}) (ret map
}
func (wd *WDADriver) WdaShutdown() (err error) {
_, err = wd.Session.GET(wd.baseURL + "/wda/shutdown")
_, err = wd.Session.GET("/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, wd.baseURL+"/gtf/automation/log")
return wd.Session.POST(data, "/gtf/automation/log")
}
func (wd *WDADriver) ScreenRecord(opts ...option.ActionOption) (videoPath string, err error) {
@@ -939,7 +937,7 @@ func (wd *WDADriver) PushImage(localPath string) error {
return err
}
_, err = wd.Session.POST(data, wd.baseURL+"/gtf/albums/add")
_, err = wd.Session.POST(data, "/gtf/albums/add")
return err
}
@@ -952,7 +950,7 @@ func (wd *WDADriver) ClearImages() error {
log.Info().Msg("WDADriver.ClearImages")
data := map[string]interface{}{}
_, err := wd.Session.POST(data, wd.baseURL+"/gtf/albums/clear")
_, err := wd.Session.POST(data, "/gtf/albums/clear")
return err
}