Skip to content
This repository was archived by the owner on Jan 30, 2025. It is now read-only.

Commit d72aa0f

Browse files
committed
Add a test to ensure that timeout is propagated
This tests ensures that the timeout that is set in browserContext is propagated to the underlying objects (frame manager and frame).
1 parent 49d3201 commit d72aa0f

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

tests/browser_context_test.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package tests
22

33
import (
4+
"fmt"
45
"net/http"
56
"testing"
67
"time"
@@ -606,3 +607,58 @@ func TestK6Object(t *testing.T) {
606607

607608
assert.False(t, k6ObjGoja.Equals(goja.Null()))
608609
}
610+
611+
func TestBrowserContextTimeout(t *testing.T) {
612+
t.Parallel()
613+
614+
testCases := []struct {
615+
name string
616+
defaultTimeout time.Duration
617+
defaultNavigationTimeout time.Duration
618+
}{
619+
{
620+
name: "fail when timeout exceeds default timeout",
621+
defaultTimeout: 1 * time.Millisecond,
622+
},
623+
{
624+
name: "fail when timeout exceeds default navigation timeout",
625+
defaultNavigationTimeout: 1 * time.Millisecond,
626+
},
627+
{
628+
name: "default navigation timeout supersedes default timeout",
629+
defaultTimeout: 30 * time.Second,
630+
defaultNavigationTimeout: 1 * time.Millisecond,
631+
},
632+
}
633+
634+
for _, tc := range testCases {
635+
tc := tc
636+
t.Run(tc.name, func(t *testing.T) {
637+
t.Parallel()
638+
639+
tb := newTestBrowser(t, withHTTPServer())
640+
641+
tb.withHandler("/slow", func(w http.ResponseWriter, _ *http.Request) {
642+
time.Sleep(1000 * time.Millisecond)
643+
fmt.Fprintf(w, `sorry for being so slow`)
644+
})
645+
646+
bc, err := tb.NewContext(nil)
647+
require.NoError(t, err)
648+
649+
if tc.defaultTimeout != 0 {
650+
bc.SetDefaultTimeout(tc.defaultTimeout.Milliseconds())
651+
}
652+
if tc.defaultNavigationTimeout != 0 {
653+
bc.SetDefaultNavigationTimeout(tc.defaultNavigationTimeout.Milliseconds())
654+
}
655+
656+
p, err := bc.NewPage()
657+
require.NoError(t, err)
658+
659+
res, err := p.Goto(tb.url("/slow"), nil)
660+
require.Nil(t, res)
661+
assert.ErrorContains(t, err, "timed out after")
662+
})
663+
}
664+
}

0 commit comments

Comments
 (0)