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

Commit 760acfa

Browse files
committed
Add tests for goto lifecycle events
1 parent a5d283f commit 760acfa

File tree

1 file changed

+67
-1
lines changed

1 file changed

+67
-1
lines changed

tests/lifecycle_wait_test.go

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,73 @@ func TestLifecycleReload(t *testing.T) {
235235
}
236236
}
237237

238-
func TestLifecycleNetworkIdle(t *testing.T) {
238+
func TestLifecycleGoto(t *testing.T) {
239+
t.Parallel()
240+
241+
// Test description
242+
//
243+
// 1. goto /home and wait for the specified lifecycle event.
244+
//
245+
// Success criteria: The web page is in the expected state once we receive
246+
// the specified lifecycle event from the browser.
247+
248+
tests := []struct {
249+
name string
250+
pingSlowness time.Duration
251+
pingJSSlow bool
252+
waitUntil common.LifecycleEvent
253+
pingRequestTextAssert func(result string)
254+
pingJSTextAssert func(result string)
255+
}{
256+
{
257+
name: "load",
258+
pingSlowness: time.Millisecond * 100,
259+
pingJSSlow: false,
260+
waitUntil: common.LifecycleEventLoad,
261+
pingRequestTextAssert: func(result string) {
262+
assert.NotEqualValues(t, "Waiting... pong 10 - for loop complete", result)
263+
},
264+
pingJSTextAssert: func(result string) {
265+
assert.EqualValues(t, "ping.js loaded from server", result)
266+
},
267+
},
268+
{
269+
name: "domcontentloaded",
270+
pingSlowness: time.Millisecond * 100,
271+
pingJSSlow: true,
272+
waitUntil: common.LifecycleEventDOMContentLoad,
273+
pingRequestTextAssert: func(result string) {
274+
assert.NotEqualValues(t, "Waiting... pong 10 - for loop complete", result)
275+
},
276+
pingJSTextAssert: func(result string) {
277+
assert.EqualValues(t, "Waiting...", result)
278+
},
279+
},
280+
}
281+
282+
for _, tt := range tests {
283+
t.Run(tt.name, func(t *testing.T) {
284+
t.Parallel()
285+
286+
tb := newTestBrowser(t, withFileServer())
287+
p := tb.NewPage(nil)
288+
289+
withHomeHandler(t, tb, "wait_for_nav_lifecycle.html")
290+
withPingHandler(t, tb, tt.pingSlowness, nil)
291+
withPingJSHandler(t, tb, tt.pingJSSlow, nil)
292+
293+
assertHome(t, tb, p, tt.waitUntil, func() {
294+
result := p.TextContent("#pingRequestText", nil)
295+
tt.pingRequestTextAssert(result)
296+
297+
result = p.TextContent("#pingJSText", nil)
298+
tt.pingJSTextAssert(result)
299+
})
300+
})
301+
}
302+
}
303+
304+
func TestLifecycleGotoNetworkIdle(t *testing.T) {
239305
t.Parallel()
240306

241307
t.Run("doesn't timeout waiting for networkIdle", func(t *testing.T) {

0 commit comments

Comments
 (0)