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
22 changes: 21 additions & 1 deletion pkg/driver/wda/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ type Client struct {
sourceOKAt time.Time
sourceErr error
sourceErrsAt time.Time

// typedClear: clear a field with typed backspaces instead of WebDriverAgent's
// hardware-keyboard Clear key (useClearTextShortcut false). On for a
// simulator only; NewDriver sets it from the device.
typedClear bool
}

// SourceUnreadableSince returns the last page-source error when no read
Expand Down Expand Up @@ -169,7 +174,22 @@ func (c *Client) CreateSession(bundleID string, alertAction string) error {
// even though stock Maestro's XCTest traversal (no such cap) sees them
// (#171). Applied here so every session — the primary one and the one
// launchApp recreates — gets it.
_ = c.UpdateSettings(map[string]interface{}{"snapshotMaxDepth": wdaSnapshotMaxDepth()})
//
// useClearTextShortcut: WebDriverAgent's first try at clearing a field is
// a hardware keyboard's Clear key (an IOHIDEvent). On a simulator iOS then
// takes a hardware keyboard as attached and keeps the software keyboard
// parked below the screen whenever a field has focus, so what an app shows
// with the keyboard (a betslip's stake chips) never appears; there the
// field is cleared with typed backspaces, as Maestro erases. A real
// iPhone keeps its keyboard up after the Clear key, and typed backspaces
// erase only what is left of the cursor: a tap in the middle of a
// one-digit field put the cursor before the digit about half the time,
// and nothing was erased. Sent either way, since WebDriverAgent keeps it
// process-wide.
_ = c.UpdateSettings(map[string]interface{}{
"snapshotMaxDepth": wdaSnapshotMaxDepth(),
"useClearTextShortcut": !c.typedClear,
})

return nil
}
Expand Down
23 changes: 23 additions & 0 deletions pkg/driver/wda/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"net/http/httptest"
"strings"
"testing"

"github.com/devicelab-dev/maestro-runner/pkg/core"
)

// mockWDAServer creates a mock WDA server for testing
Expand Down Expand Up @@ -40,6 +42,7 @@ func TestNewClient(t *testing.T) {
// TestCreateSession tests session creation
func TestCreateSession(t *testing.T) {
var sawSnapshotDepth bool
clearShortcut := map[string]interface{}{}
server := mockWDAServer(func(w http.ResponseWriter, r *http.Request) {
switch {
case r.Method == "POST" && r.URL.Path == "/session":
Expand All @@ -57,6 +60,10 @@ func TestCreateSession(t *testing.T) {
if _, ok := body.Settings["snapshotMaxDepth"]; ok {
sawSnapshotDepth = true
}
// ...and says how a field is cleared.
if v, ok := body.Settings["useClearTextShortcut"]; ok {
clearShortcut["sent"] = v
}
jsonResponse(w, map[string]interface{}{"value": map[string]interface{}{}})
default:
t.Errorf("unexpected request: %s %s", r.Method, r.URL.Path)
Expand All @@ -80,6 +87,22 @@ func TestCreateSession(t *testing.T) {
if !sawSnapshotDepth {
t.Error("CreateSession should raise snapshotMaxDepth so deep RN trees are not clipped")
}
// A real iPhone (the client's default) keeps WDA's hardware-key clear: typed
// backspaces erase only what is left of the cursor.
if clearShortcut["sent"] != true {
t.Errorf("CreateSession on a real device should send useClearTextShortcut true, sent %v", clearShortcut["sent"])
}

// A simulator's driver clears with typed backspaces: the hardware key parks
// the software keyboard there.
delete(clearShortcut, "sent")
NewDriver(client, &core.PlatformInfo{IsSimulator: true}, "SIM")
if err := client.CreateSession("com.example.app", ""); err != nil {
t.Fatalf("CreateSession failed: %v", err)
}
if clearShortcut["sent"] != false {
t.Errorf("CreateSession on a simulator should send useClearTextShortcut false, sent %v", clearShortcut["sent"])
}
}

// TestCreateSessionAlternateFormat tests alternate session response format
Expand Down
3 changes: 3 additions & 0 deletions pkg/driver/wda/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ const (

// NewDriver creates a new WDA driver.
func NewDriver(client *Client, info *core.PlatformInfo, udid string) *Driver {
if client != nil {
client.typedClear = info != nil && info.IsSimulator
}
return &Driver{
client: client,
info: info,
Expand Down
Loading