mirror of
https://github.com/priyanshujain/sanderling.git
synced 2026-10-04 20:17:09 +00:00
feat(driver): add Snapshot to chrome and mock drivers
The chrome tab is single-threaded so its Snapshot pairs the two reads without extra locking. The mock records ActionSnapshot so tests can assert the runner reaches for the paired RPC.
This commit is contained in:
1 parent
c11beb1728
commit
c57be03b69
2 files changed
+30
No files matched your search
@@ -20,6 +20,7 @@ const (
|
||||
ActionPressKey ActionKind = "press_key"
|
||||
ActionHierarchy ActionKind = "hierarchy"
|
||||
ActionScreenshot ActionKind = "screenshot"
|
||||
ActionSnapshot ActionKind = "snapshot"
|
||||
ActionRecentLogs ActionKind = "recent_logs"
|
||||
ActionWaitForIdle ActionKind = "wait_for_idle"
|
||||
ActionHealth ActionKind = "health"
|
||||
@@ -234,6 +235,20 @@ func (d *Driver) Screenshot(ctx context.Context) (driver.Image, error) {
|
||||
return d.ImageData, nil
|
||||
}
|
||||
|
||||
// Snapshot returns the hierarchy + screenshot pair atomically, mirroring
|
||||
// the real driver's contract. It records a single ActionSnapshot so tests
|
||||
// can assert the runner reached for the paired RPC instead of racing the
|
||||
// two reads.
|
||||
func (d *Driver) Snapshot(ctx context.Context) (string, driver.Image, error) {
|
||||
if err := d.failure(ActionSnapshot); err != nil {
|
||||
return "", driver.Image{}, err
|
||||
}
|
||||
d.record(Action{Kind: ActionSnapshot})
|
||||
d.mutex.Lock()
|
||||
defer d.mutex.Unlock()
|
||||
return d.HierarchyJSON, d.ImageData, nil
|
||||
}
|
||||
|
||||
func (d *Driver) WaitForIdle(ctx context.Context, duration time.Duration) error {
|
||||
if err := d.failure(ActionWaitForIdle); err != nil {
|
||||
return err
|
||||
|
||||
Reference in new issue
Block a user