mirror of
https://github.com/priyanshujain/sanderling.git
synced 2026-10-02 19:17:10 +00:00
feat(driver): add TapSelector and make mock WaitForIdle honor duration
Real maestro driver will resolve selectors itself rather than forcing the runner to look up coordinates from the hierarchy. Mock now waits the requested duration so tests don't busy-spin and starve the SDK fixture goroutine.
This commit is contained in:
1 parent
abeded0b19
commit
d2fae427f9
2 files changed
+22
-1
No files matched your search
@@ -13,6 +13,7 @@ type Driver interface {
|
|||||||
Terminate(ctx context.Context) error
|
Terminate(ctx context.Context) error
|
||||||
|
|
||||||
Tap(ctx context.Context, x, y int) error
|
Tap(ctx context.Context, x, y int) error
|
||||||
|
TapSelector(ctx context.Context, selector string) error
|
||||||
InputText(ctx context.Context, text string) error
|
InputText(ctx context.Context, text string) error
|
||||||
|
|
||||||
Hierarchy(ctx context.Context) (string, error)
|
Hierarchy(ctx context.Context) (string, error)
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ const (
|
|||||||
ActionLaunch ActionKind = "launch"
|
ActionLaunch ActionKind = "launch"
|
||||||
ActionTerminate ActionKind = "terminate"
|
ActionTerminate ActionKind = "terminate"
|
||||||
ActionTap ActionKind = "tap"
|
ActionTap ActionKind = "tap"
|
||||||
|
ActionTapSelector ActionKind = "tap_selector"
|
||||||
ActionInputText ActionKind = "input_text"
|
ActionInputText ActionKind = "input_text"
|
||||||
ActionHierarchy ActionKind = "hierarchy"
|
ActionHierarchy ActionKind = "hierarchy"
|
||||||
ActionScreenshot ActionKind = "screenshot"
|
ActionScreenshot ActionKind = "screenshot"
|
||||||
@@ -26,6 +27,7 @@ type Action struct {
|
|||||||
BundleID string
|
BundleID string
|
||||||
ClearState bool
|
ClearState bool
|
||||||
X, Y int
|
X, Y int
|
||||||
|
Selector string
|
||||||
Text string
|
Text string
|
||||||
Idle time.Duration
|
Idle time.Duration
|
||||||
}
|
}
|
||||||
@@ -98,6 +100,14 @@ func (d *Driver) Tap(ctx context.Context, x, y int) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d *Driver) TapSelector(ctx context.Context, selector string) error {
|
||||||
|
if err := d.failure(ActionTapSelector); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
d.record(Action{Kind: ActionTapSelector, Selector: selector})
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (d *Driver) InputText(ctx context.Context, text string) error {
|
func (d *Driver) InputText(ctx context.Context, text string) error {
|
||||||
if err := d.failure(ActionInputText); err != nil {
|
if err := d.failure(ActionInputText); err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -131,7 +141,17 @@ func (d *Driver) WaitForIdle(ctx context.Context, duration time.Duration) error
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
d.record(Action{Kind: ActionWaitForIdle, Idle: duration})
|
d.record(Action{Kind: ActionWaitForIdle, Idle: duration})
|
||||||
return nil
|
if duration <= 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
timer := time.NewTimer(duration)
|
||||||
|
defer timer.Stop()
|
||||||
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
return ctx.Err()
|
||||||
|
case <-timer.C:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Driver) Health(ctx context.Context) (driver.Health, error) {
|
func (d *Driver) Health(ctx context.Context) (driver.Health, error) {
|
||||||
|
|||||||
Reference in new issue
Block a user