Adds SetDefaultTimeout(time.Duration) to the InteractiveBrowser interface, delegating to Playwright's Page and BrowserContext SetDefaultTimeout and SetDefaultNavigationTimeout methods. This allows callers to set a timeout so Playwright operations return an error instead of blocking forever when the browser process crashes or the remote server becomes unresponsive. Closes #86 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
60 lines
2.4 KiB
Go
60 lines
2.4 KiB
Go
package extractor
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// mockInteractiveBrowser implements InteractiveBrowser for testing without Playwright.
|
|
type mockInteractiveBrowser struct{}
|
|
|
|
func (m mockInteractiveBrowser) Navigate(string) (string, error) { return "", nil }
|
|
func (m mockInteractiveBrowser) GoBack() (string, error) { return "", nil }
|
|
func (m mockInteractiveBrowser) GoForward() (string, error) { return "", nil }
|
|
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, ...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 }
|
|
func (m mockInteractiveBrowser) KeyboardInsertText(string) error { return nil }
|
|
func (m mockInteractiveBrowser) Screenshot(int) ([]byte, error) { return nil, nil }
|
|
func (m mockInteractiveBrowser) Cookies() ([]Cookie, error) { return nil, nil }
|
|
func (m mockInteractiveBrowser) SetDefaultTimeout(time.Duration) {}
|
|
func (m mockInteractiveBrowser) Close() error { return nil }
|
|
|
|
func TestPromoteToInteractive_NonPromotable(t *testing.T) {
|
|
doc := &mockDocument{}
|
|
_, err := PromoteToInteractive(doc)
|
|
if !errors.Is(err, ErrNotPromotable) {
|
|
t.Fatalf("expected ErrNotPromotable, got: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestPromoteToInteractive_AlreadyDetached(t *testing.T) {
|
|
d := &document{detached: true}
|
|
_, err := PromoteToInteractive(d)
|
|
if !errors.Is(err, ErrAlreadyDetached) {
|
|
t.Fatalf("expected ErrAlreadyDetached, got: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestDemoteToDocument_NonDemotable(t *testing.T) {
|
|
ib := &mockInteractiveBrowser{}
|
|
_, err := DemoteToDocument(ib)
|
|
if !errors.Is(err, ErrNotDemotable) {
|
|
t.Fatalf("expected ErrNotDemotable, got: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestDemoteToDocument_AlreadyDetached(t *testing.T) {
|
|
ib := &interactiveBrowser{detached: true}
|
|
_, err := DemoteToDocument(ib)
|
|
if !errors.Is(err, ErrAlreadyDetached) {
|
|
t.Fatalf("expected ErrAlreadyDetached, got: %v", err)
|
|
}
|
|
}
|