Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions devices/wda/press-button.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
2 changes: 1 addition & 1 deletion devices/wda/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
45 changes: 34 additions & 11 deletions devices/wda/tap.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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},
},
},
},
Expand Down
Loading