diff --git a/common/browser_context.go b/common/browser_context.go index 65df8c117..ff947cb68 100644 --- a/common/browser_context.go +++ b/common/browser_context.go @@ -272,7 +272,7 @@ func (b *BrowserContext) SetDefaultNavigationTimeout(timeout int64) { func (b *BrowserContext) SetDefaultTimeout(timeout int64) { b.logger.Debugf("BrowserContext:SetDefaultTimeout", "bctxid:%v timeout:%d", b.id, timeout) - b.timeoutSettings.setDefaultTimeout(timeout) + b.timeoutSettings.setDefaultTimeout(time.Duration(timeout) * time.Millisecond) } // SetExtraHTTPHeaders is not implemented. diff --git a/common/element_handle.go b/common/element_handle.go index 93b14b376..ae7ca18da 100644 --- a/common/element_handle.go +++ b/common/element_handle.go @@ -249,7 +249,7 @@ func (h *ElementHandle) dblClick(p *Position, opts *MouseClickOptions) error { } func (h *ElementHandle) defaultTimeout() time.Duration { - return time.Duration(h.frame.manager.timeoutSettings.timeout()) * time.Millisecond + return h.frame.manager.timeoutSettings.timeout() } func (h *ElementHandle) dispatchEvent(_ context.Context, typ string, eventInit goja.Value) (any, error) { diff --git a/common/frame.go b/common/frame.go index 3d48de276..e5755f932 100644 --- a/common/frame.go +++ b/common/frame.go @@ -198,7 +198,7 @@ func (f *Frame) detach() { } func (f *Frame) defaultTimeout() time.Duration { - return time.Duration(f.manager.timeoutSettings.timeout()) * time.Millisecond + return f.manager.timeoutSettings.timeout() } func (f *Frame) document() (*ElementHandle, error) { @@ -1738,7 +1738,7 @@ func (f *Frame) WaitForNavigation(opts goja.Value) (api.Response, error) { "fid:%s furl:%s", f.ID(), f.URL()) parsedOpts := NewFrameWaitForNavigationOptions( - time.Duration(f.manager.timeoutSettings.timeout()) * time.Millisecond) + f.manager.timeoutSettings.timeout()) if err := parsedOpts.Parse(f.ctx, opts); err != nil { k6ext.Panic(f.ctx, "parsing wait for navigation options: %w", err) } diff --git a/common/page.go b/common/page.go index 2300edc96..3c38da14f 100644 --- a/common/page.go +++ b/common/page.go @@ -223,7 +223,7 @@ func (p *Page) closeWorker(sessionID target.SessionID) { } func (p *Page) defaultTimeout() time.Duration { - return time.Duration(p.timeoutSettings.timeout()) * time.Millisecond + return p.timeoutSettings.timeout() } func (p *Page) didClose() { @@ -975,7 +975,7 @@ func (p *Page) SetDefaultNavigationTimeout(timeout int64) { func (p *Page) SetDefaultTimeout(timeout int64) { p.logger.Debugf("Page:SetDefaultTimeout", "sid:%v timeout:%d", p.sessionID(), timeout) - p.timeoutSettings.setDefaultTimeout(timeout) + p.timeoutSettings.setDefaultTimeout(time.Duration(timeout) * time.Millisecond) } // SetExtraHTTPHeaders sets default HTTP headers for page and whole frame hierarchy. diff --git a/common/timeout.go b/common/timeout.go index 0291b561e..883a5bbd1 100644 --- a/common/timeout.go +++ b/common/timeout.go @@ -5,7 +5,7 @@ import "time" // TimeoutSettings holds information on timeout settings. type TimeoutSettings struct { parent *TimeoutSettings - defaultTimeout *int64 + defaultTimeout *time.Duration defaultNavigationTimeout *time.Duration } @@ -19,7 +19,7 @@ func NewTimeoutSettings(parent *TimeoutSettings) *TimeoutSettings { return t } -func (t *TimeoutSettings) setDefaultTimeout(timeout int64) { +func (t *TimeoutSettings) setDefaultTimeout(timeout time.Duration) { t.defaultTimeout = &timeout } @@ -32,7 +32,7 @@ func (t *TimeoutSettings) navigationTimeout() time.Duration { return *t.defaultNavigationTimeout } if t.defaultTimeout != nil { - return time.Duration(*t.defaultTimeout * time.Hour.Milliseconds()) + return *t.defaultTimeout } if t.parent != nil { return t.parent.navigationTimeout() @@ -40,12 +40,12 @@ func (t *TimeoutSettings) navigationTimeout() time.Duration { return DefaultTimeout } -func (t *TimeoutSettings) timeout() int64 { +func (t *TimeoutSettings) timeout() time.Duration { if t.defaultTimeout != nil { return *t.defaultTimeout } if t.parent != nil { return t.parent.timeout() } - return int64(DefaultTimeout.Milliseconds()) + return DefaultTimeout } diff --git a/common/timeout_test.go b/common/timeout_test.go index ca54605cb..728bfaabc 100644 --- a/common/timeout_test.go +++ b/common/timeout_test.go @@ -63,8 +63,8 @@ func testTimeoutSettingsSetDefaultTimeout(t *testing.T) { t.Parallel() ts := NewTimeoutSettings(nil) - ts.setDefaultTimeout(100) - assert.Equal(t, int64(100), *ts.defaultTimeout) + ts.setDefaultTimeout(time.Duration(100) * time.Millisecond) + assert.Equal(t, int64(100), ts.defaultTimeout.Milliseconds()) } func testTimeoutSettingsSetDefaultNavigationTimeout(t *testing.T) { @@ -112,11 +112,11 @@ func testTimeoutSettingsTimeout(t *testing.T) { ts := NewTimeoutSettings(nil) // Assert default timeout value is used - assert.Equal(t, int64(DefaultTimeout.Milliseconds()), ts.timeout()) + assert.Equal(t, DefaultTimeout, ts.timeout()) // Assert custom default timeout is used - ts.setDefaultTimeout(100) - assert.Equal(t, int64(100), ts.timeout()) + ts.setDefaultTimeout(time.Duration(100) * time.Millisecond) + assert.Equal(t, int64(100), ts.timeout().Milliseconds()) } func testTimeoutSettingsTimeoutWithParent(t *testing.T) { @@ -126,13 +126,13 @@ func testTimeoutSettingsTimeoutWithParent(t *testing.T) { tsWithParent := NewTimeoutSettings(ts) // Assert default timeout value is used - assert.Equal(t, int64(DefaultTimeout.Milliseconds()), tsWithParent.timeout()) + assert.Equal(t, DefaultTimeout, tsWithParent.timeout()) // Assert custom default timeout from parent is used - ts.setDefaultTimeout(1000) - assert.Equal(t, int64(1000), tsWithParent.timeout()) + ts.setDefaultTimeout(time.Duration(1000) * time.Millisecond) + assert.Equal(t, int64(1000), tsWithParent.timeout().Milliseconds()) // Assert custom default timeout is used (over parent) - tsWithParent.setDefaultTimeout(100) - assert.Equal(t, int64(100), tsWithParent.timeout()) + tsWithParent.setDefaultTimeout(time.Duration(100) * time.Millisecond) + assert.Equal(t, int64(100), tsWithParent.timeout().Milliseconds()) }