mirror of
https://github.com/priyanshujain/sanderling.git
synced 2026-10-04 12:07:09 +00:00
feat(driver): add EraseText to the device driver surface
This commit is contained in:
1 parent
72055e5d9f
commit
41511a2a32
4 files changed
+49
-13
No files matched your search
@@ -193,6 +193,23 @@ func (d *Driver) InputText(_ context.Context, text string) error {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// EraseText clears the focused field. InputText above already replaces via
|
||||||
|
// select-all, so the character count is not needed to bound the deletion.
|
||||||
|
func (d *Driver) EraseText(_ context.Context, _ int) error {
|
||||||
|
return chromedp.Run(d.tabCtx,
|
||||||
|
chromedp.ActionFunc(func(ctx context.Context) error {
|
||||||
|
if err := chromedp.Evaluate(`
|
||||||
|
(function() {
|
||||||
|
const el = document.activeElement;
|
||||||
|
if (el && typeof el.select === 'function') el.select();
|
||||||
|
})()`, nil).Do(ctx); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return input.InsertText("").Do(ctx)
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
func (d *Driver) Swipe(_ context.Context, fromX, fromY, toX, toY int, duration time.Duration) error {
|
func (d *Driver) Swipe(_ context.Context, fromX, fromY, toX, toY int, duration time.Duration) error {
|
||||||
millis := max(duration.Milliseconds(), 50)
|
millis := max(duration.Milliseconds(), 50)
|
||||||
script := fmt.Sprintf(`
|
script := fmt.Sprintf(`
|
||||||
|
|||||||
@@ -20,6 +20,10 @@ type DeviceDriver interface {
|
|||||||
DoubleTap(ctx context.Context, x, y int) error
|
DoubleTap(ctx context.Context, x, y int) error
|
||||||
DoubleTapSelector(ctx context.Context, selector string) error
|
DoubleTapSelector(ctx context.Context, selector string) error
|
||||||
InputText(ctx context.Context, text string) error
|
InputText(ctx context.Context, text string) error
|
||||||
|
// EraseText deletes characterCount characters from the focused field.
|
||||||
|
// The runner calls it before InputText so the verb replaces existing
|
||||||
|
// content instead of appending to it.
|
||||||
|
EraseText(ctx context.Context, characterCount int) error
|
||||||
Swipe(ctx context.Context, fromX, fromY, toX, toY int, duration time.Duration) error
|
Swipe(ctx context.Context, fromX, fromY, toX, toY int, duration time.Duration) error
|
||||||
PressKey(ctx context.Context, key string) error
|
PressKey(ctx context.Context, key string) error
|
||||||
LongPress(ctx context.Context, x, y int) error
|
LongPress(ctx context.Context, x, y int) error
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ const (
|
|||||||
ActionDoubleTap ActionKind = "double_tap"
|
ActionDoubleTap ActionKind = "double_tap"
|
||||||
ActionDoubleTapSelector ActionKind = "double_tap_selector"
|
ActionDoubleTapSelector ActionKind = "double_tap_selector"
|
||||||
ActionInputText ActionKind = "input_text"
|
ActionInputText ActionKind = "input_text"
|
||||||
|
ActionEraseText ActionKind = "erase_text"
|
||||||
ActionSwipe ActionKind = "swipe"
|
ActionSwipe ActionKind = "swipe"
|
||||||
ActionPressKey ActionKind = "press_key"
|
ActionPressKey ActionKind = "press_key"
|
||||||
ActionLongPress ActionKind = "long_press"
|
ActionLongPress ActionKind = "long_press"
|
||||||
@@ -32,19 +33,20 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Action struct {
|
type Action struct {
|
||||||
Kind ActionKind
|
Kind ActionKind
|
||||||
BundleID string
|
BundleID string
|
||||||
ClearState bool
|
ClearState bool
|
||||||
X, Y int
|
X, Y int
|
||||||
FromX, FromY int
|
FromX, FromY int
|
||||||
ToX, ToY int
|
ToX, ToY int
|
||||||
Duration time.Duration
|
Duration time.Duration
|
||||||
Selector string
|
Selector string
|
||||||
Text string
|
Text string
|
||||||
Key string
|
CharacterCount int
|
||||||
LogLevel string
|
Key string
|
||||||
LogSince time.Time
|
LogLevel string
|
||||||
Idle time.Duration
|
LogSince time.Time
|
||||||
|
Idle time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
// Driver is an in-memory Driver implementation for unit tests.
|
// Driver is an in-memory Driver implementation for unit tests.
|
||||||
@@ -210,6 +212,14 @@ func (d *Driver) InputText(ctx context.Context, text string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d *Driver) EraseText(ctx context.Context, characterCount int) error {
|
||||||
|
if err := d.failure(ActionEraseText); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
d.record(Action{Kind: ActionEraseText, CharacterCount: characterCount})
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (d *Driver) Swipe(ctx context.Context, fromX, fromY, toX, toY int, duration time.Duration) error {
|
func (d *Driver) Swipe(ctx context.Context, fromX, fromY, toX, toY int, duration time.Duration) error {
|
||||||
if err := d.failure(ActionSwipe); err != nil {
|
if err := d.failure(ActionSwipe); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -137,6 +137,11 @@ func (c *Client) InputText(ctx context.Context, text string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Client) EraseText(ctx context.Context, characterCount int) error {
|
||||||
|
_, err := c.stub.EraseText(ctx, &driverpb.EraseTextRequest{CharacterCount: int32(characterCount)})
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Client) Swipe(ctx context.Context, fromX, fromY, toX, toY int, duration time.Duration) error {
|
func (c *Client) Swipe(ctx context.Context, fromX, fromY, toX, toY int, duration time.Duration) error {
|
||||||
_, err := c.stub.Swipe(ctx, &driverpb.SwipeRequest{
|
_, err := c.stub.Swipe(ctx, &driverpb.SwipeRequest{
|
||||||
From: &driverpb.Point{X: int32(fromX), Y: int32(fromY)},
|
From: &driverpb.Point{X: int32(fromX), Y: int32(fromY)},
|
||||||
|
|||||||
Reference in new issue
Block a user