refactor: session request url str, fix lazy setup
This commit is contained in:
parent
a4b0fc2ed5
commit
0152ec06e2
|
@ -1 +1 @@
|
||||||
v5.0.0+2502191654
|
v5.0.0+2502191738
|
||||||
|
|
|
@ -121,7 +121,8 @@ func (ud *UIA2Driver) DeleteSession() (err error) {
|
||||||
if ud.Session.ID == "" {
|
if ud.Session.ID == "" {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if _, err = ud.Session.DELETE("/session", ud.Session.ID); err == nil {
|
urlStr := fmt.Sprintf("/session/%s", ud.Session.ID)
|
||||||
|
if _, err = ud.Session.DELETE(urlStr); err == nil {
|
||||||
ud.Session.ID = ""
|
ud.Session.ID = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,7 +151,8 @@ func (ud *UIA2Driver) Status() (deviceStatus types.DeviceStatus, err error) {
|
||||||
func (ud *UIA2Driver) DeviceInfo() (deviceInfo types.DeviceInfo, err error) {
|
func (ud *UIA2Driver) DeviceInfo() (deviceInfo types.DeviceInfo, err error) {
|
||||||
// register(getHandler, new GetDeviceInfo("/wd/hub/session/:sessionId/appium/device/info"))
|
// register(getHandler, new GetDeviceInfo("/wd/hub/session/:sessionId/appium/device/info"))
|
||||||
var rawResp DriverRawResponse
|
var rawResp DriverRawResponse
|
||||||
if rawResp, err = ud.Session.GET("/session", ud.Session.ID, "appium/device/info"); err != nil {
|
urlStr := fmt.Sprintf("/session/%s/appium/device/info", ud.Session.ID)
|
||||||
|
if rawResp, err = ud.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 } })
|
||||||
|
@ -164,7 +166,8 @@ func (ud *UIA2Driver) DeviceInfo() (deviceInfo types.DeviceInfo, err error) {
|
||||||
func (ud *UIA2Driver) BatteryInfo() (batteryInfo types.BatteryInfo, err error) {
|
func (ud *UIA2Driver) BatteryInfo() (batteryInfo types.BatteryInfo, err error) {
|
||||||
// register(getHandler, new GetBatteryInfo("/wd/hub/session/:sessionId/appium/device/battery_info"))
|
// register(getHandler, new GetBatteryInfo("/wd/hub/session/:sessionId/appium/device/battery_info"))
|
||||||
var rawResp DriverRawResponse
|
var rawResp DriverRawResponse
|
||||||
if rawResp, err = ud.Session.GET("/session", ud.Session.ID, "appium/device/battery_info"); err != nil {
|
urlStr := fmt.Sprintf("/session/%s/appium/device/battery_info", ud.Session.ID)
|
||||||
|
if rawResp, err = ud.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 } })
|
||||||
|
@ -186,7 +189,8 @@ func (ud *UIA2Driver) WindowSize() (size types.Size, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var rawResp DriverRawResponse
|
var rawResp DriverRawResponse
|
||||||
if rawResp, err = ud.Session.GET("/session", ud.Session.ID, "window/:windowHandle/size"); err != nil {
|
urlStr := fmt.Sprintf("/session/%s/window/:windowHandle/size", ud.Session.ID)
|
||||||
|
if rawResp, err = ud.Session.GET(urlStr); err != nil {
|
||||||
return types.Size{}, errors.Wrap(err, "get window size failed by UIA2 request")
|
return types.Size{}, errors.Wrap(err, "get window size failed by UIA2 request")
|
||||||
}
|
}
|
||||||
reply := new(struct{ Value struct{ types.Size } })
|
reply := new(struct{ Value struct{ types.Size } })
|
||||||
|
@ -212,7 +216,8 @@ func (ud *UIA2Driver) WindowSize() (size types.Size, err error) {
|
||||||
// Back simulates a short press on the BACK button.
|
// Back simulates a short press on the BACK button.
|
||||||
func (ud *UIA2Driver) Back() (err error) {
|
func (ud *UIA2Driver) Back() (err error) {
|
||||||
// register(postHandler, new PressBack("/wd/hub/session/:sessionId/back"))
|
// register(postHandler, new PressBack("/wd/hub/session/:sessionId/back"))
|
||||||
_, err = ud.Session.POST(nil, "/session", ud.Session.ID, "back")
|
urlStr := fmt.Sprintf("/session/%s/back", ud.Session.ID)
|
||||||
|
_, err = ud.Session.POST(nil, urlStr)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -227,14 +232,16 @@ func (ud *UIA2Driver) PressKeyCodes(keyCode KeyCode, metaState KeyMeta, flags ..
|
||||||
if len(flags) != 0 {
|
if len(flags) != 0 {
|
||||||
data["flags"] = flags[0]
|
data["flags"] = flags[0]
|
||||||
}
|
}
|
||||||
_, err = ud.Session.POST(data, "/session", ud.Session.ID, "appium/device/press_keycode")
|
urlStr := fmt.Sprintf("/session/%s/appium/device/press_keycode", ud.Session.ID)
|
||||||
|
_, err = ud.Session.POST(data, urlStr)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ud *UIA2Driver) Orientation() (orientation types.Orientation, err error) {
|
func (ud *UIA2Driver) 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
|
||||||
if rawResp, err = ud.Session.GET("/session", ud.Session.ID, "/orientation"); err != nil {
|
urlStr := fmt.Sprintf("/session/%s/orientation", ud.Session.ID)
|
||||||
|
if rawResp, err = ud.Session.GET(urlStr); err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
reply := new(struct{ Value types.Orientation })
|
reply := new(struct{ Value types.Orientation })
|
||||||
|
@ -270,7 +277,8 @@ func (ud *UIA2Driver) DoubleTapXY(x, y float64, opts ...option.ActionOption) err
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = ud.Session.POST(data, "/session", ud.Session.ID, "actions/tap")
|
urlStr := fmt.Sprintf("/session/%s/actions/tap", ud.Session.ID)
|
||||||
|
_, err = ud.Session.POST(data, urlStr)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -309,7 +317,8 @@ func (ud *UIA2Driver) TapAbsXY(x, y float64, opts ...option.ActionOption) error
|
||||||
}
|
}
|
||||||
option.MergeOptions(data, opts...)
|
option.MergeOptions(data, opts...)
|
||||||
|
|
||||||
_, err := ud.Session.POST(data, "/session", ud.Session.ID, "actions/tap")
|
urlStr := fmt.Sprintf("/session/%s/actions/tap", ud.Session.ID)
|
||||||
|
_, err := ud.Session.POST(data, urlStr)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -328,7 +337,8 @@ func (ud *UIA2Driver) TouchAndHold(x, y float64, opts ...option.ActionOption) (e
|
||||||
"duration": int(duration * 1000),
|
"duration": int(duration * 1000),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
_, err = ud.Session.POST(data, "/session", ud.Session.ID, "touch/longclick")
|
urlStr := fmt.Sprintf("/session/%s/touch/longclick", ud.Session.ID)
|
||||||
|
_, err = ud.Session.POST(data, urlStr)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -354,7 +364,8 @@ func (ud *UIA2Driver) Drag(fromX, fromY, toX, toY float64, opts ...option.Action
|
||||||
option.MergeOptions(data, opts...)
|
option.MergeOptions(data, opts...)
|
||||||
|
|
||||||
// register(postHandler, new Drag("/wd/hub/session/:sessionId/touch/drag"))
|
// register(postHandler, new Drag("/wd/hub/session/:sessionId/touch/drag"))
|
||||||
_, err = ud.Session.POST(data, "/session", ud.Session.ID, "touch/drag")
|
urlStr := fmt.Sprintf("/session/%s/touch/drag", ud.Session.ID)
|
||||||
|
_, err = ud.Session.POST(data, urlStr)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -395,7 +406,8 @@ func (ud *UIA2Driver) Swipe(fromX, fromY, toX, toY float64, opts ...option.Actio
|
||||||
}
|
}
|
||||||
option.MergeOptions(data, opts...)
|
option.MergeOptions(data, opts...)
|
||||||
|
|
||||||
_, err = ud.Session.POST(data, "/session", ud.Session.ID, "actions/swipe")
|
urlStr := fmt.Sprintf("/session/%s/actions/swipe", ud.Session.ID)
|
||||||
|
_, err = ud.Session.POST(data, urlStr)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -413,7 +425,8 @@ func (ud *UIA2Driver) SetPasteboard(contentType types.PasteboardType, content st
|
||||||
"content": base64.StdEncoding.EncodeToString([]byte(content)),
|
"content": base64.StdEncoding.EncodeToString([]byte(content)),
|
||||||
}
|
}
|
||||||
// register(postHandler, new SetClipboard("/wd/hub/session/:sessionId/appium/device/set_clipboard"))
|
// register(postHandler, new SetClipboard("/wd/hub/session/:sessionId/appium/device/set_clipboard"))
|
||||||
_, err = ud.Session.POST(data, "/session", ud.Session.ID, "appium/device/set_clipboard")
|
urlStr := fmt.Sprintf("/session/%s/appium/device/set_clipboard", ud.Session.ID)
|
||||||
|
_, err = ud.Session.POST(data, urlStr)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -426,7 +439,8 @@ func (ud *UIA2Driver) GetPasteboard(contentType types.PasteboardType) (raw *byte
|
||||||
"contentType": contentType[0],
|
"contentType": contentType[0],
|
||||||
}
|
}
|
||||||
var rawResp DriverRawResponse
|
var rawResp DriverRawResponse
|
||||||
if rawResp, err = ud.Session.POST(data, "/session", ud.Session.ID, "appium/device/get_clipboard"); err != nil {
|
urlStr := fmt.Sprintf("/session/%s/appium/device/get_clipboard", ud.Session.ID)
|
||||||
|
if rawResp, err = ud.Session.POST(data, urlStr); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
reply := new(struct{ Value string })
|
reply := new(struct{ Value string })
|
||||||
|
@ -455,7 +469,8 @@ func (ud *UIA2Driver) Input(text string, opts ...option.ActionOption) (err error
|
||||||
"text": text,
|
"text": text,
|
||||||
}
|
}
|
||||||
option.MergeOptions(data, opts...)
|
option.MergeOptions(data, opts...)
|
||||||
_, err = ud.Session.POST(data, "/session", ud.Session.ID, "/keys")
|
urlStr := fmt.Sprintf("/session/%s/keys", ud.Session.ID)
|
||||||
|
_, err = ud.Session.POST(data, urlStr)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -510,14 +525,16 @@ func (ud *UIA2Driver) SendActionKey(text string, opts ...option.ActionOption) (e
|
||||||
}
|
}
|
||||||
option.MergeOptions(data, opts...)
|
option.MergeOptions(data, opts...)
|
||||||
|
|
||||||
_, err = ud.Session.POST(data, "/session", ud.Session.ID, "/actions/keys")
|
urlStr := fmt.Sprintf("/session/%s/actions/keys", ud.Session.ID)
|
||||||
|
_, err = ud.Session.POST(data, urlStr)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ud *UIA2Driver) Rotation() (rotation types.Rotation, err error) {
|
func (ud *UIA2Driver) Rotation() (rotation types.Rotation, err error) {
|
||||||
// register(getHandler, new GetRotation("/wd/hub/session/:sessionId/rotation"))
|
// register(getHandler, new GetRotation("/wd/hub/session/:sessionId/rotation"))
|
||||||
var rawResp DriverRawResponse
|
var rawResp DriverRawResponse
|
||||||
if rawResp, err = ud.Session.GET("/session", ud.Session.ID, "rotation"); err != nil {
|
urlStr := fmt.Sprintf("/session/%s/rotation", ud.Session.ID)
|
||||||
|
if rawResp, err = ud.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 })
|
||||||
|
@ -538,7 +555,8 @@ func (ud *UIA2Driver) ScreenShot(opts ...option.ActionOption) (raw *bytes.Buffer
|
||||||
func (ud *UIA2Driver) Source(srcOpt ...option.SourceOption) (source string, err error) {
|
func (ud *UIA2Driver) Source(srcOpt ...option.SourceOption) (source string, err error) {
|
||||||
// register(getHandler, new Source("/wd/hub/session/:sessionId/source"))
|
// register(getHandler, new Source("/wd/hub/session/:sessionId/source"))
|
||||||
var rawResp DriverRawResponse
|
var rawResp DriverRawResponse
|
||||||
if rawResp, err = ud.Session.GET("/session", ud.Session.ID, "source"); err != nil {
|
urlStr := fmt.Sprintf("/session/%s/source", ud.Session.ID)
|
||||||
|
if rawResp, err = ud.Session.GET(urlStr); err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
reply := new(struct{ Value string })
|
reply := new(struct{ Value string })
|
||||||
|
|
|
@ -87,8 +87,8 @@ func (s *DriverSession) History() []*DriverRequests {
|
||||||
return s.requests
|
return s.requests
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DriverSession) concatURL(elem ...string) (string, error) {
|
func (s *DriverSession) concatURL(urlStr string) (string, error) {
|
||||||
if len(elem) == 0 {
|
if urlStr == "" || urlStr == "/" {
|
||||||
if s.baseUrl == "" {
|
if s.baseUrl == "" {
|
||||||
return "", fmt.Errorf("base URL is empty")
|
return "", fmt.Errorf("base URL is empty")
|
||||||
}
|
}
|
||||||
|
@ -96,14 +96,11 @@ func (s *DriverSession) concatURL(elem ...string) (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 处理完整 URL
|
// 处理完整 URL
|
||||||
if strings.HasPrefix(elem[0], "http://") || strings.HasPrefix(elem[0], "https://") {
|
if strings.HasPrefix(urlStr, "http://") || strings.HasPrefix(urlStr, "https://") {
|
||||||
u, err := url.Parse(elem[0])
|
u, err := url.Parse(urlStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("failed to parse URL: %w", err)
|
return "", fmt.Errorf("failed to parse URL: %w", err)
|
||||||
}
|
}
|
||||||
if len(elem) > 1 {
|
|
||||||
u.Path = path.Join(u.Path, path.Join(elem[1:]...))
|
|
||||||
}
|
|
||||||
return u.String(), nil
|
return u.String(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,55 +113,25 @@ func (s *DriverSession) concatURL(elem ...string) (string, error) {
|
||||||
return "", fmt.Errorf("failed to parse base URL: %w", err)
|
return "", fmt.Errorf("failed to parse base URL: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 保存原始查询参数
|
|
||||||
baseQuery := u.Query()
|
|
||||||
|
|
||||||
// 处理路径和查询参数
|
// 处理路径和查询参数
|
||||||
var paths []string
|
parts := strings.SplitN(urlStr, "?", 2)
|
||||||
for i, e := range elem {
|
u.Path = path.Join(u.Path, parts[0])
|
||||||
if i == len(elem)-1 {
|
|
||||||
// 处理最后一个元素的查询参数
|
|
||||||
parts := strings.SplitN(e, "?", 2)
|
|
||||||
paths = append(paths, parts[0])
|
|
||||||
if len(parts) > 1 {
|
if len(parts) > 1 {
|
||||||
newQuery, err := url.ParseQuery(parts[1])
|
query, err := url.ParseQuery(parts[1])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("failed to parse query params: %w", err)
|
return "", fmt.Errorf("failed to parse query params: %w", err)
|
||||||
}
|
}
|
||||||
// 合并查询参数
|
u.RawQuery = query.Encode()
|
||||||
for k, v := range newQuery {
|
|
||||||
baseQuery[k] = v
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
paths = append(paths, e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 合并路径
|
|
||||||
u.Path = path.Join(append([]string{u.Path}, paths...)...)
|
|
||||||
|
|
||||||
// 设置合并后的查询参数
|
|
||||||
if len(baseQuery) > 0 {
|
|
||||||
u.RawQuery = baseQuery.Encode()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return u.String(), nil
|
return u.String(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DriverSession) GET(pathElem ...string) (rawResp DriverRawResponse, err error) {
|
func (s *DriverSession) GET(urlStr string) (rawResp DriverRawResponse, err error) {
|
||||||
urlStr, err := s.concatURL(pathElem...)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return s.RequestWithRetry(http.MethodGet, urlStr, nil)
|
return s.RequestWithRetry(http.MethodGet, urlStr, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DriverSession) POST(data interface{}, pathElem ...string) (rawResp DriverRawResponse, err error) {
|
func (s *DriverSession) POST(data interface{}, urlStr string) (rawResp DriverRawResponse, err error) {
|
||||||
urlStr, err := s.concatURL(pathElem...)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
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 {
|
||||||
|
@ -174,18 +141,14 @@ func (s *DriverSession) POST(data interface{}, pathElem ...string) (rawResp Driv
|
||||||
return s.RequestWithRetry(http.MethodPost, urlStr, bsJSON)
|
return s.RequestWithRetry(http.MethodPost, urlStr, bsJSON)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DriverSession) DELETE(pathElem ...string) (rawResp DriverRawResponse, err error) {
|
func (s *DriverSession) DELETE(urlStr string) (rawResp DriverRawResponse, err error) {
|
||||||
urlStr, err := s.concatURL(pathElem...)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return s.RequestWithRetry(http.MethodDelete, urlStr, nil)
|
return s.RequestWithRetry(http.MethodDelete, urlStr, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DriverSession) RequestWithRetry(method string, rawURL 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, rawURL, rawBody)
|
rawResp, err = s.Request(method, urlStr, rawBody)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -205,8 +168,15 @@ func (s *DriverSession) RequestWithRetry(method string, rawURL string, rawBody [
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DriverSession) Request(method string, rawURL 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
|
||||||
|
rawURL, err := s.concatURL(urlStr)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
driverResult := &DriverRequests{
|
driverResult := &DriverRequests{
|
||||||
RequestMethod: method,
|
RequestMethod: method,
|
||||||
RequestUrl: rawURL,
|
RequestUrl: rawURL,
|
||||||
|
|
|
@ -10,82 +10,101 @@ func TestDriverSession_concatURL(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
baseUrl string
|
baseUrl string
|
||||||
elem []string
|
urlStr string
|
||||||
want string
|
want string
|
||||||
wantErr bool
|
wantErr bool
|
||||||
errMsg string
|
errMsg string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "empty elements with empty base url",
|
name: "empty url with empty base url",
|
||||||
baseUrl: "",
|
baseUrl: "",
|
||||||
elem: []string{},
|
urlStr: "",
|
||||||
wantErr: true,
|
wantErr: true,
|
||||||
errMsg: "base URL is empty",
|
errMsg: "base URL is empty",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "empty elements with valid base url",
|
name: "empty url with valid base url",
|
||||||
baseUrl: "http://localhost:8080",
|
baseUrl: "http://localhost:8080",
|
||||||
elem: []string{},
|
urlStr: "",
|
||||||
want: "http://localhost:8080",
|
want: "http://localhost:8080",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "absolute url in first element",
|
name: "root path with empty base url",
|
||||||
|
baseUrl: "",
|
||||||
|
urlStr: "/",
|
||||||
|
wantErr: true,
|
||||||
|
errMsg: "base URL is empty",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "root path with valid base url",
|
||||||
baseUrl: "http://localhost:8080",
|
baseUrl: "http://localhost:8080",
|
||||||
elem: []string{"https://example.com/api", "users"},
|
urlStr: "/",
|
||||||
want: "https://example.com/api/users",
|
want: "http://localhost:8080",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "absolute http url",
|
||||||
|
baseUrl: "http://localhost:8080",
|
||||||
|
urlStr: "http://example.com/api",
|
||||||
|
want: "http://example.com/api",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "absolute https url",
|
||||||
|
baseUrl: "http://localhost:8080",
|
||||||
|
urlStr: "https://example.com/api",
|
||||||
|
want: "https://example.com/api",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "invalid absolute url",
|
name: "invalid absolute url",
|
||||||
baseUrl: "http://localhost:8080",
|
baseUrl: "http://localhost:8080",
|
||||||
elem: []string{"http://[invalid-url", "users"},
|
urlStr: "http://[invalid-url",
|
||||||
wantErr: true,
|
wantErr: true,
|
||||||
errMsg: "failed to parse URL",
|
errMsg: "failed to parse URL",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "relative path with empty base url",
|
name: "relative path with empty base url",
|
||||||
baseUrl: "",
|
baseUrl: "",
|
||||||
elem: []string{"api", "users"},
|
urlStr: "api/users",
|
||||||
wantErr: true,
|
wantErr: true,
|
||||||
errMsg: "base URL is empty",
|
errMsg: "base URL is empty",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "relative path with invalid base url",
|
name: "relative path with invalid base url",
|
||||||
baseUrl: "http://[invalid-url",
|
baseUrl: "http://[invalid-url",
|
||||||
elem: []string{"api", "users"},
|
urlStr: "api/users",
|
||||||
wantErr: true,
|
wantErr: true,
|
||||||
errMsg: "failed to parse base URL",
|
errMsg: "failed to parse base URL",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "relative path with valid base url",
|
||||||
|
baseUrl: "http://localhost:8080",
|
||||||
|
urlStr: "api/users",
|
||||||
|
want: "http://localhost:8080/api/users",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "relative path with query params",
|
name: "relative path with query params",
|
||||||
baseUrl: "http://localhost:8080",
|
baseUrl: "http://localhost:8080",
|
||||||
elem: []string{"api", "users?id=1&name=test"},
|
urlStr: "api/users?id=1&name=test",
|
||||||
want: "http://localhost:8080/api/users?id=1&name=test",
|
want: "http://localhost:8080/api/users?id=1&name=test",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "base url with query params",
|
name: "base url with query params",
|
||||||
baseUrl: "http://localhost:8080?token=123",
|
baseUrl: "http://localhost:8080?token=123",
|
||||||
elem: []string{"api", "users?id=1"},
|
urlStr: "api/users?id=1",
|
||||||
want: "http://localhost:8080/api/users?id=1&token=123",
|
want: "http://localhost:8080/api/users?id=1",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "invalid query params",
|
name: "invalid query params",
|
||||||
baseUrl: "http://localhost:8080",
|
baseUrl: "http://localhost:8080",
|
||||||
elem: []string{"api", "users?id=%invalid"},
|
urlStr: "api/users?id=%invalid",
|
||||||
wantErr: true,
|
wantErr: true,
|
||||||
errMsg: "failed to parse query params",
|
errMsg: "failed to parse query params",
|
||||||
},
|
},
|
||||||
{
|
|
||||||
name: "multiple path segments",
|
|
||||||
baseUrl: "http://localhost:8080",
|
|
||||||
elem: []string{"api", "v1", "users", "profile"},
|
|
||||||
want: "http://localhost:8080/api/v1/users/profile",
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
s := &DriverSession{baseUrl: tt.baseUrl}
|
s := &DriverSession{baseUrl: tt.baseUrl}
|
||||||
got, err := s.concatURL(tt.elem...)
|
got, err := s.concatURL(tt.urlStr)
|
||||||
|
|
||||||
if tt.wantErr {
|
if tt.wantErr {
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
|
|
|
@ -187,7 +187,8 @@ func (wd *WDADriver) DeleteSession() (err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// [[FBRoute DELETE:@""] respondWithTarget:self action:@selector(handleDeleteSession:)]
|
// [[FBRoute DELETE:@""] respondWithTarget:self action:@selector(handleDeleteSession:)]
|
||||||
_, err = wd.Session.DELETE("/session", wd.Session.ID)
|
urlStr := fmt.Sprintf("/session/%s", wd.Session.ID)
|
||||||
|
_, err = wd.Session.DELETE(urlStr)
|
||||||
wd.Session.ID = ""
|
wd.Session.ID = ""
|
||||||
wd.Session.client.CloseIdleConnections()
|
wd.Session.client.CloseIdleConnections()
|
||||||
return
|
return
|
||||||
|
@ -216,7 +217,8 @@ 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
|
||||||
if rawResp, err = wd.Session.GET("/session", wd.Session.ID, "/wda/device/info"); err != nil {
|
urlStr := fmt.Sprintf("/session/%s/wda/device/info", wd.Session.ID)
|
||||||
|
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 } })
|
||||||
|
@ -231,7 +233,8 @@ 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
|
||||||
if rawResp, err = wd.Session.GET("/session", wd.Session.ID, "/wda/device/location"); err != nil {
|
urlStr := fmt.Sprintf("/session/%s/wda/device/location", wd.Session.ID)
|
||||||
|
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 } })
|
||||||
|
@ -245,7 +248,8 @@ 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
|
||||||
if rawResp, err = wd.Session.GET("/session", wd.Session.ID, "/wda/batteryInfo"); err != nil {
|
urlStr := fmt.Sprintf("/session/%s/wda/batteryInfo", wd.Session.ID)
|
||||||
|
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 } })
|
||||||
|
@ -264,7 +268,8 @@ func (wd *WDADriver) WindowSize() (size types.Size, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var rawResp DriverRawResponse
|
var rawResp DriverRawResponse
|
||||||
if rawResp, err = wd.Session.GET("/session", wd.Session.ID, "/window/size"); err != nil {
|
urlStr := fmt.Sprintf("/session/%s/window/size", wd.Session.ID)
|
||||||
|
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 } })
|
||||||
|
@ -303,7 +308,8 @@ 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
|
||||||
if rawResp, err = wd.Session.GET("/session", wd.Session.ID, "/wda/screen"); err != nil {
|
urlStr := fmt.Sprintf("/session/%s/wda/screen", wd.Session.ID)
|
||||||
|
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 } })
|
||||||
|
@ -317,7 +323,8 @@ 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:)]
|
||||||
rawResp, err := wd.Session.GET("/session", wd.Session.ID, "/screenshot")
|
urlStr := fmt.Sprintf("/session/%s/screenshot", wd.Session.ID)
|
||||||
|
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))
|
||||||
|
@ -350,7 +357,8 @@ 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
|
||||||
if rawResp, err = wd.Session.GET("/session", wd.Session.ID, "/wda/activeAppInfo"); err != nil {
|
urlStr := fmt.Sprintf("/session/%s/wda/activeAppInfo", wd.Session.ID)
|
||||||
|
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 } })
|
||||||
|
@ -364,7 +372,8 @@ 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
|
||||||
if rawResp, err = wd.Session.GET("/session", wd.Session.ID, "/wda/apps/list"); err != nil {
|
urlStr := fmt.Sprintf("/session/%s/wda/apps/list", wd.Session.ID)
|
||||||
|
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,7 +388,8 @@ func (wd *WDADriver) AppState(bundleId string) (runState types.AppState, err err
|
||||||
// [[FBRoute POST:@"/wda/apps/state"] respondWithTarget:self action:@selector(handleSessionAppState:)]
|
// [[FBRoute POST:@"/wda/apps/state"] respondWithTarget:self action:@selector(handleSessionAppState:)]
|
||||||
data := map[string]interface{}{"bundleId": bundleId}
|
data := map[string]interface{}{"bundleId": bundleId}
|
||||||
var rawResp DriverRawResponse
|
var rawResp DriverRawResponse
|
||||||
if rawResp, err = wd.Session.POST(data, "/session", wd.Session.ID, "/wda/apps/state"); err != nil {
|
urlStr := fmt.Sprintf("/session/%s/wda/apps/state", wd.Session.ID)
|
||||||
|
if rawResp, err = wd.Session.POST(data, urlStr); err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
reply := new(struct{ Value types.AppState })
|
reply := new(struct{ Value types.AppState })
|
||||||
|
@ -395,7 +405,8 @@ 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
|
||||||
if rawResp, err = wd.Session.GET("/session", wd.Session.ID, "/wda/locked"); err != nil {
|
urlStr := fmt.Sprintf("/session/%s/wda/locked", wd.Session.ID)
|
||||||
|
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 {
|
||||||
|
@ -407,14 +418,16 @@ func (wd *WDADriver) IsLocked() (locked bool, err error) {
|
||||||
func (wd *WDADriver) Unlock() (err error) {
|
func (wd *WDADriver) Unlock() (err error) {
|
||||||
// [[FBRoute POST:@"/wda/unlock"] respondWithTarget:self action:@selector(handleUnlock:)]
|
// [[FBRoute POST:@"/wda/unlock"] respondWithTarget:self action:@selector(handleUnlock:)]
|
||||||
// [[FBRoute POST:@"/wda/unlock"].withoutSession
|
// [[FBRoute POST:@"/wda/unlock"].withoutSession
|
||||||
_, err = wd.Session.POST(nil, "/session", wd.Session.ID, "/wda/unlock")
|
urlStr := fmt.Sprintf("/session/%s/wda/unlock", wd.Session.ID)
|
||||||
|
_, 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
|
||||||
_, err = wd.Session.POST(nil, "/session", wd.Session.ID, "/wda/lock")
|
urlStr := fmt.Sprintf("/session/%s/wda/lock", wd.Session.ID)
|
||||||
|
_, err = wd.Session.POST(nil, urlStr)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -428,7 +441,8 @@ 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
|
||||||
if rawResp, err = wd.Session.GET("/session", wd.Session.ID, "/alert/text"); err != nil {
|
urlStr := fmt.Sprintf("/session/%s/alert/text", wd.Session.ID)
|
||||||
|
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 {
|
||||||
|
@ -440,7 +454,8 @@ 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
|
||||||
if rawResp, err = wd.Session.GET("/session", wd.Session.ID, "/wda/alert/buttons"); err != nil {
|
urlStr := fmt.Sprintf("/session/%s/wda/alert/buttons", wd.Session.ID)
|
||||||
|
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 })
|
||||||
|
@ -476,7 +491,8 @@ func (wd *WDADriver) AlertDismiss(label ...string) (err error) {
|
||||||
func (wd *WDADriver) AlertSendKeys(text string) (err error) {
|
func (wd *WDADriver) AlertSendKeys(text string) (err error) {
|
||||||
// [[FBRoute POST:@"/alert/text"] respondWithTarget:self action:@selector(handleAlertSetTextCommand:)]
|
// [[FBRoute POST:@"/alert/text"] respondWithTarget:self action:@selector(handleAlertSetTextCommand:)]
|
||||||
data := map[string]interface{}{"value": strings.Split(text, "")}
|
data := map[string]interface{}{"value": strings.Split(text, "")}
|
||||||
_, err = wd.Session.POST(data, "/session", wd.Session.ID, "/alert/text")
|
urlStr := fmt.Sprintf("/session/%s/alert/text", wd.Session.ID)
|
||||||
|
_, err = wd.Session.POST(data, urlStr)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -487,7 +503,8 @@ func (wd *WDADriver) AppLaunch(bundleId string) (err error) {
|
||||||
data["environment"] = map[string]interface{}{
|
data["environment"] = map[string]interface{}{
|
||||||
"SHOW_EXPLORER": "NO",
|
"SHOW_EXPLORER": "NO",
|
||||||
}
|
}
|
||||||
_, err = wd.Session.POST(data, "/session", wd.Session.ID, "/wda/apps/launch")
|
urlStr := fmt.Sprintf("/session/%s/wda/apps/launch", wd.Session.ID)
|
||||||
|
_, 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))
|
||||||
|
@ -510,7 +527,8 @@ 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
|
||||||
if rawResp, err = wd.Session.POST(data, "/session", wd.Session.ID, "/wda/apps/terminate"); err != nil {
|
urlStr := fmt.Sprintf("/session/%s/wda/apps/terminate", wd.Session.ID)
|
||||||
|
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 {
|
||||||
|
@ -522,7 +540,8 @@ func (wd *WDADriver) AppTerminate(bundleId string) (successful bool, err error)
|
||||||
func (wd *WDADriver) AppActivate(bundleId string) (err error) {
|
func (wd *WDADriver) AppActivate(bundleId string) (err error) {
|
||||||
// [[FBRoute POST:@"/wda/apps/activate"] respondWithTarget:self action:@selector(handleSessionAppActivate:)]
|
// [[FBRoute POST:@"/wda/apps/activate"] respondWithTarget:self action:@selector(handleSessionAppActivate:)]
|
||||||
data := map[string]interface{}{"bundleId": bundleId}
|
data := map[string]interface{}{"bundleId": bundleId}
|
||||||
_, err = wd.Session.POST(data, "/session", wd.Session.ID, "/wda/apps/activate")
|
urlStr := fmt.Sprintf("/session/%s/wda/apps/activate", wd.Session.ID)
|
||||||
|
_, err = wd.Session.POST(data, urlStr)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -532,7 +551,8 @@ func (wd *WDADriver) AppDeactivate(second float64) (err error) {
|
||||||
second = 3.0
|
second = 3.0
|
||||||
}
|
}
|
||||||
data := map[string]interface{}{"duration": second}
|
data := map[string]interface{}{"duration": second}
|
||||||
_, err = wd.Session.POST(data, "/session", wd.Session.ID, "/wda/deactivateApp")
|
urlStr := fmt.Sprintf("/session/%s/wda/deactivateApp", wd.Session.ID)
|
||||||
|
_, err = wd.Session.POST(data, urlStr)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -579,7 +599,8 @@ func (wd *WDADriver) TapAbsXY(x, y float64, opts ...option.ActionOption) error {
|
||||||
}
|
}
|
||||||
option.MergeOptions(data, opts...)
|
option.MergeOptions(data, opts...)
|
||||||
|
|
||||||
_, err := wd.Session.POST(data, "/session", wd.Session.ID, "/wda/tap/0")
|
urlStr := fmt.Sprintf("/session/%s/wda/tap/0", wd.Session.ID)
|
||||||
|
_, err := wd.Session.POST(data, urlStr)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -598,7 +619,8 @@ func (wd *WDADriver) DoubleTapXY(x, y float64, opts ...option.ActionOption) erro
|
||||||
"x": x,
|
"x": x,
|
||||||
"y": y,
|
"y": y,
|
||||||
}
|
}
|
||||||
_, err = wd.Session.POST(data, "/session", wd.Session.ID, "/wda/doubleTap")
|
urlStr := fmt.Sprintf("/session/%s/wda/doubleTap", wd.Session.ID)
|
||||||
|
_, err = wd.Session.POST(data, urlStr)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -634,7 +656,8 @@ 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
|
||||||
_, err = wd.Session.POST(data, "/session", wd.Session.ID, "/wda/dragfromtoforduration")
|
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.Session.POST(data, "/session", wd.Session.ID, "/wda/drag")
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -649,7 +672,8 @@ 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)),
|
||||||
}
|
}
|
||||||
_, err = wd.Session.POST(data, "/session", wd.Session.ID, "/wda/setPasteboard")
|
urlStr := fmt.Sprintf("/session/%s/wda/setPasteboard", wd.Session.ID)
|
||||||
|
_, err = wd.Session.POST(data, urlStr)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -657,7 +681,8 @@ 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
|
||||||
if rawResp, err = wd.Session.POST(data, "/session", wd.Session.ID, "/wda/getPasteboard"); err != nil {
|
urlStr := fmt.Sprintf("/session/%s/wda/getPasteboard", wd.Session.ID)
|
||||||
|
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 {
|
||||||
|
@ -674,7 +699,8 @@ 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...)
|
||||||
_, err = wd.Session.POST(data, "/session", wd.Session.ID, "/wda/keys")
|
urlStr := fmt.Sprintf("/session/%s/wda/keys", wd.Session.ID)
|
||||||
|
_, err = wd.Session.POST(data, urlStr)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -694,37 +720,22 @@ func (wd *WDADriver) AppClear(packageName string) error {
|
||||||
|
|
||||||
// Back simulates a short press on the BACK button.
|
// Back simulates a short press on the BACK button.
|
||||||
func (wd *WDADriver) Back() (err error) {
|
func (wd *WDADriver) Back() (err error) {
|
||||||
windowSize, err := wd.WindowSize()
|
return wd.Swipe(0, 0.5, 0.6, 0.5)
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
fromX := wd.toScale(float64(windowSize.Width) * 0)
|
|
||||||
fromY := wd.toScale(float64(windowSize.Height) * 0.5)
|
|
||||||
toX := wd.toScale(float64(windowSize.Width) * 0.6)
|
|
||||||
toY := wd.toScale(float64(windowSize.Height) * 0.5)
|
|
||||||
|
|
||||||
data := map[string]interface{}{
|
|
||||||
"fromX": fromX,
|
|
||||||
"fromY": fromY,
|
|
||||||
"toX": toX,
|
|
||||||
"toY": toY,
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = wd.Session.POST(data, "/session", wd.Session.ID, "/wda/dragfromtoforduration")
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (wd *WDADriver) PressButton(devBtn types.DeviceButton) (err error) {
|
func (wd *WDADriver) PressButton(devBtn types.DeviceButton) (err error) {
|
||||||
// [[FBRoute POST:@"/wda/pressButton"] respondWithTarget:self action:@selector(handlePressButtonCommand:)]
|
// [[FBRoute POST:@"/wda/pressButton"] respondWithTarget:self action:@selector(handlePressButtonCommand:)]
|
||||||
data := map[string]interface{}{"name": devBtn}
|
data := map[string]interface{}{"name": devBtn}
|
||||||
_, err = wd.Session.POST(data, "/session", wd.Session.ID, "/wda/pressButton")
|
urlStr := fmt.Sprintf("/session/%s/wda/pressButton", wd.Session.ID)
|
||||||
|
_, 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
|
||||||
if rawResp, err = wd.Session.GET("/session", wd.Session.ID, "/orientation"); err != nil {
|
urlStr := fmt.Sprintf("/session/%s/orientation", wd.Session.ID)
|
||||||
|
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 })
|
||||||
|
@ -738,14 +749,16 @@ 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}
|
||||||
_, err = wd.Session.POST(data, "/session", wd.Session.ID, "/orientation")
|
urlStr := fmt.Sprintf("/session/%s/orientation", wd.Session.ID)
|
||||||
|
_, 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
|
||||||
if rawResp, err = wd.Session.GET("/session", wd.Session.ID, "/rotation"); err != nil {
|
urlStr := fmt.Sprintf("/session/%s/rotation", wd.Session.ID)
|
||||||
|
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 })
|
||||||
|
@ -758,7 +771,8 @@ 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:)]
|
||||||
_, err = wd.Session.POST(rotation, "/session", wd.Session.ID, "/rotation")
|
urlStr := fmt.Sprintf("/session/%s/rotation", wd.Session.ID)
|
||||||
|
_, err = wd.Session.POST(rotation, urlStr)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -798,7 +812,8 @@ 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
|
||||||
if rawResp, err = wd.Session.GET("/session", wd.Session.ID, "/wda/accessibleSource"); err != nil {
|
urlStr := fmt.Sprintf("/session/%s/wda/accessibleSource", wd.Session.ID)
|
||||||
|
if rawResp, err = wd.Session.GET(urlStr); err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
var jr builtinJSON.RawMessage
|
var jr builtinJSON.RawMessage
|
||||||
|
@ -829,7 +844,8 @@ 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
|
||||||
if rawResp, err = wd.Session.GET("/session", wd.Session.ID, "/appium/settings"); err != nil {
|
urlStr := fmt.Sprintf("/session/%s/appium/settings", wd.Session.ID)
|
||||||
|
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{} })
|
||||||
|
@ -844,7 +860,8 @@ 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
|
||||||
if rawResp, err = wd.Session.POST(data, "/session", wd.Session.ID, "/appium/settings"); err != nil {
|
urlStr := fmt.Sprintf("/session/%s/appium/settings", wd.Session.ID)
|
||||||
|
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{} })
|
||||||
|
|
Loading…
Reference in New Issue