diff --git a/interactive.go b/interactive.go index 8929a8f..8066fa9 100644 --- a/interactive.go +++ b/interactive.go @@ -27,8 +27,9 @@ type InteractiveBrowser interface { MouseDown(x, y float64, button string) error // MouseUp releases the mouse button at the given coordinates. MouseUp(x, y float64, button string) error - // MouseMove moves the mouse to the given coordinates. - MouseMove(x, y float64) error + // MouseMove moves the mouse to the given coordinates. An optional steps parameter + // controls how many intermediate mousemove events are generated (default 1). + MouseMove(x, y float64, steps ...int) error // MouseWheel scrolls by the given delta. MouseWheel(deltaX, deltaY float64) error @@ -192,8 +193,12 @@ func (ib *interactiveBrowser) MouseUp(x, y float64, button string) error { return ib.page.Mouse().Up(playwright.MouseUpOptions{Button: btn}) } -func (ib *interactiveBrowser) MouseMove(x, y float64) error { - return ib.page.Mouse().Move(x, y) +func (ib *interactiveBrowser) MouseMove(x, y float64, steps ...int) error { + var opts playwright.MouseMoveOptions + if len(steps) > 0 && steps[0] > 1 { + opts.Steps = playwright.Int(steps[0]) + } + return ib.page.Mouse().Move(x, y, opts) } func (ib *interactiveBrowser) MouseWheel(deltaX, deltaY float64) error { diff --git a/promote_test.go b/promote_test.go index 3e60725..c5ba28c 100644 --- a/promote_test.go +++ b/promote_test.go @@ -15,7 +15,7 @@ func (m mockInteractiveBrowser) URL() string { return func (m mockInteractiveBrowser) MouseClick(float64, float64, string) error { return nil } func (m mockInteractiveBrowser) MouseDown(float64, float64, string) error { return nil } func (m mockInteractiveBrowser) MouseUp(float64, float64, string) error { return nil } -func (m mockInteractiveBrowser) MouseMove(float64, float64) error { return nil } +func (m mockInteractiveBrowser) MouseMove(float64, float64, ...int) error { return nil } func (m mockInteractiveBrowser) MouseWheel(float64, float64) error { return nil } func (m mockInteractiveBrowser) KeyboardType(string) error { return nil } func (m mockInteractiveBrowser) KeyboardPress(string) error { return nil }