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

Commit 4c7bbf6

Browse files
committed
Add a test for WaitForLoadState networkidle
This test will ensure that when WaitForLoadState with waituntil networkidle is called, that it doesn't block for the lifecycle event if that event has already fired, and so uses the frame's internal state to unblock quickly.
1 parent 0f7aff7 commit 4c7bbf6

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

tests/lifecycle_wait_test.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,56 @@ func TestLifecycleWaitForLoadStateDOMContentLoaded(t *testing.T) {
124124
})
125125
}
126126

127+
func TestLifecycleWaitForLoadStateNetworkIdle(t *testing.T) {
128+
// Test description
129+
//
130+
// 1. goto /home and wait for the networkidle lifecycle event.
131+
// 2. use WaitForLoadState with networkidle to ensure that
132+
// networkidle lifecycle event has already fired.
133+
//
134+
// Success criteria: We wait for all network requests and async
135+
// scripts to complete. We also want to ensure
136+
// that the networkidle event is stored internally,
137+
// and we don't block on WaitForLoadState.
138+
139+
t.Parallel()
140+
141+
tb := newTestBrowser(t, withFileServer())
142+
p := tb.NewPage(nil)
143+
tb.withHandler("/home", func(w http.ResponseWriter, r *http.Request) {
144+
http.Redirect(w, r, tb.staticURL("wait_for_nav_lifecycle.html"), http.StatusMovedPermanently)
145+
})
146+
147+
var counter int64
148+
var counterMu sync.Mutex
149+
tb.withHandler("/ping", func(w http.ResponseWriter, _ *http.Request) {
150+
counterMu.Lock()
151+
defer counterMu.Unlock()
152+
153+
counter++
154+
fmt.Fprintf(w, "pong %d", counter)
155+
})
156+
157+
tb.withHandler("/ping.js", func(w http.ResponseWriter, _ *http.Request) {
158+
fmt.Fprintf(w, `
159+
var pingJSTextOutput = document.getElementById("pingJSText");
160+
pingJSTextOutput.innerText = "ping.js loaded from server";
161+
`)
162+
})
163+
164+
waitUntil := common.LifecycleEventNetworkIdle
165+
assertHome(t, tb, p, waitUntil, func() {
166+
result := p.TextContent("#pingRequestText", nil)
167+
assert.EqualValues(t, "Waiting... pong 10 - for loop complete", result)
168+
169+
result = p.TextContent("#pingJSText", nil)
170+
assert.EqualValues(t, "ping.js loaded from server", result)
171+
172+
// This shouldn't block and return after calling hasLifecycleEventFired.
173+
p.WaitForLoadState(waitUntil.String(), nil)
174+
})
175+
}
176+
127177
func TestLifecycleReloadLoad(t *testing.T) {
128178
t.Parallel()
129179

0 commit comments

Comments
 (0)