diff --git a/devices/wda/press-button.go b/devices/wda/press-button.go index f8e5de0..5667258 100644 --- a/devices/wda/press-button.go +++ b/devices/wda/press-button.go @@ -7,9 +7,9 @@ import ( func PressButton(key string) error { buttonMap := map[string]string{ - "volume_up": "volumeup", - "volume_down": "volumedown", - "home": "home", + "VOLUME_UP": "volumeup", + "VOLUME_DOWN": "volumedown", + "HOME": "home", } if key == "enter" { diff --git a/devices/wda/requests.go b/devices/wda/requests.go index c2c3765..824224a 100644 --- a/devices/wda/requests.go +++ b/devices/wda/requests.go @@ -47,7 +47,7 @@ func GetWebDriverAgentEndpoint(endpoint string) (map[string]interface{}, error) return result, nil } -func PostWebDriverAgentEndpoint(endpoint string, data map[string]interface{}) (map[string]interface{}, error) { +func PostWebDriverAgentEndpoint(endpoint string, data interface{}) (map[string]interface{}, error) { client := &http.Client{ Timeout: 5 * time.Second, } diff --git a/devices/wda/tap.go b/devices/wda/tap.go index a434cdc..fc5f28f 100644 --- a/devices/wda/tap.go +++ b/devices/wda/tap.go @@ -4,6 +4,29 @@ import ( "fmt" ) +type TapAction struct { + Type string `json:"type"` + Duration int `json:"duration,omitempty"` + X int `json:"x,omitempty"` + Y int `json:"y,omitempty"` + Button int `json:"button,omitempty"` +} + +type PointerParameters struct { + PointerType string `json:"pointerType"` +} + +type Pointer struct { + Type string `json:"type"` + ID string `json:"id"` + Parameters PointerParameters `json:"parameters"` + Actions []TapAction `json:"actions"` +} + +type ActionsRequest struct { + Actions []Pointer `json:"actions"` +} + func Tap(x, y int) error { sessionId, err := CreateSession() @@ -13,19 +36,19 @@ func Tap(x, y int) error { defer DeleteSession(sessionId) - data := map[string]interface{}{ - "actions": []map[string]interface{}{ + data := ActionsRequest{ + Actions: []Pointer{ { - "type": "pointer", - "id": "finger1", - "parameters": map[string]interface{}{ - "pointerType": "touch", + Type: "pointer", + ID: "finger1", + Parameters: PointerParameters{ + PointerType: "touch", }, - "actions": []map[string]interface{}{ - {"type": "pointerMove", "duration": 0, "x": x, "y": y}, - {"type": "pointerDown", "button": 0}, - {"type": "pause", "duration": 100}, - {"type": "pointerUp", "button": 0}, + Actions: []TapAction{ + {Type: "pointerMove", Duration: 0, X: x, Y: y}, + {Type: "pointerDown", Button: 0}, + {Type: "pause", Duration: 100}, + {Type: "pointerUp", Button: 0}, }, }, },