@@ -16,34 +16,46 @@ import (
16
16
17
17
// General guidelines on lifecycle events:
18
18
//
19
- // - load: This lifecycle event is emitted by the browser once:
20
- // 1. The HTML is loaded;
21
- // 2. The async scripts have loaded;
22
- // It does not wait for the other network requests to
23
- // complete.
19
+ // load
24
20
//
25
- // - domcontentloaded: This lifecycle event is emitted by the
26
- // browser once:
27
- // 1. The HTML is loaded;
28
- // It does not wait for the async scripts or
29
- // the other network requests to complete.
21
+ // The load event is fired when the initial HTML document has been completely
22
+ // loaded. It does not wait for the other network requests to complete.
30
23
//
31
- // - networkidle: This lifecycle event is emitted by the browser once:
32
- // 1. The HTML is loaded;
33
- // 2. The async scripts have loaded;
34
- // 3. All other network requests have completed;
24
+ // Emitted by the browser once:
25
+ // 1. The HTML is loaded.
26
+ // 2. The async scripts have loaded.
27
+ //
28
+ // domcontentloaded
29
+ //
30
+ // The DOMContentLoaded event is fired when the initial HTML document has been
31
+ // completely loaded and parsed. It does not wait for the async scripts or the
32
+ // other network requests to complete.
33
+ //
34
+ // Emitted by the browser once:
35
+ // 1. The HTML is loaded.
36
+ //
37
+ // networkidle
38
+ //
39
+ // The networkidle event is fired when there are no network connections for at
40
+ // least 500ms.
41
+ //
42
+ // Emitted by the browser once:
43
+ // 1. The HTML is loaded.
44
+ // 2. The async scripts have loaded.
45
+ // 3. All other network requests have completed.
35
46
36
47
func TestLifecycleWaitForNavigation (t * testing.T ) {
37
48
// Test description
38
49
//
39
- // 1. goto /home and wait for the specified lifecycle event.
40
- // 2. click on a link that navigates to a page, and wait on
50
+ // Steps:
51
+ // 1. goto /home and wait for the specified lifecycle event.
52
+ // 2. click on a link that navigates to a page, and wait on
41
53
// the specified lifecycle event.
42
54
//
43
- // Success criteria: The click will perform a navigation away
44
- // from the current page, it should wait for
45
- // the specified lifecycle event and the result
46
- // of the page should match the original nav.
55
+ // Success criteria:
56
+ // The click will perform a navigation away from the current page,
57
+ // it should wait for the specified lifecycle event and the result
58
+ // of the page should match the original nav.
47
59
48
60
t .Parallel ()
49
61
@@ -143,13 +155,15 @@ func TestLifecycleWaitForNavigationTimeout(t *testing.T) {
143
155
144
156
// Test description
145
157
//
146
- // 1. goto /home and wait for the networkidle lifecycle event.
147
- // 2. use WaitForNavigation with networkidle.
158
+ // Steps:
159
+ // 1. goto /home and wait for the networkidle lifecycle event.
160
+ // 2. use WaitForNavigation with networkidle.
148
161
//
149
- // Success criteria: Time out reached after navigation completed and
150
- // wait for lifecycle event set, to signify that
151
- // WaitForNavigation must be set before we navigate
152
- // to a new page.
162
+ // Success criteria:
163
+ // Time out reached after navigation completed and
164
+ // wait for lifecycle event set, to signify that
165
+ // WaitForNavigation must be set before we navigate
166
+ // to a new page.
153
167
154
168
tb := newTestBrowser (t , withFileServer ())
155
169
p := tb .NewPage (nil )
@@ -177,14 +191,11 @@ func TestLifecycleWaitForNavigationTimeout(t *testing.T) {
177
191
return tb .promise (waitForNav )
178
192
},
179
193
)
180
- prm .then (
181
- func () {
182
- resolved = true
183
- },
184
- func () {
185
- rejected = true
186
- },
187
- )
194
+ prm .then (func () {
195
+ resolved = true
196
+ }, func () {
197
+ rejected = true
198
+ })
188
199
189
200
return nil
190
201
})
@@ -199,11 +210,13 @@ func TestLifecycleWaitForLoadState(t *testing.T) {
199
210
200
211
// Test description
201
212
//
202
- // 1. goto /home and wait for the specified lifecycle event.
203
- // 2. use WaitForLoadState with the same specified lifecycle event.
213
+ // Steps:
214
+ // 1. goto /home and wait for the specified lifecycle event.
215
+ // 2. use WaitForLoadState with the same specified lifecycle event.
204
216
//
205
- // Success criteria: We want to ensure that the specified event is persisted in
206
- // memory, and we don't block on WaitForLoadState.
217
+ // Success criteria:
218
+ // We want to ensure that the specified event is persisted in
219
+ // memory, and we don't block on WaitForLoadState.
207
220
208
221
tests := []struct {
209
222
name string
@@ -253,12 +266,14 @@ func TestLifecycleWaitForLoadState(t *testing.T) {
253
266
{
254
267
// Test description
255
268
//
256
- // 1. goto /home and wait for the domcontentloaded lifecycle event.
257
- // 2. use WaitForLoadState with networkidle.
269
+ // Steps:
270
+ // 1. goto /home and wait for the domcontentloaded lifecycle event.
271
+ // 2. use WaitForLoadState with networkidle.
258
272
//
259
- // Success criteria: We want to quickly move to calling WaitForLoadState
260
- // so that we wait until networkidle is received from
261
- // the browser -- not relying on the persisted state in memory.
273
+ // Success criteria:
274
+ // We want to quickly move to calling WaitForLoadState
275
+ // so that we wait until networkidle is received from
276
+ // the browser -- not relying on the persisted state in memory.
262
277
name : "domcontentloaded then networkidle" ,
263
278
pingSlowness : 100 * time .Millisecond ,
264
279
pingJSSlow : false ,
@@ -315,11 +330,13 @@ func TestLifecycleReload(t *testing.T) {
315
330
316
331
// Test description
317
332
//
318
- // 1. goto /home and wait for the specified lifecycle event.
319
- // 2. reload the page and wait for the specified lifecycle event.
333
+ // Steps:
334
+ // 1. goto /home and wait for the specified lifecycle event.
335
+ // 2. reload the page and wait for the specified lifecycle event.
320
336
//
321
- // Success criteria: The resulting page after reload is the same as
322
- // the initial navigation with goto.
337
+ // Success criteria:
338
+ // The resulting page after reload is the same as
339
+ // the initial navigation with goto.
323
340
324
341
tests := []struct {
325
342
name string
@@ -408,11 +425,13 @@ func TestLifecycleGotoWithSubFrame(t *testing.T) {
408
425
409
426
// Test description
410
427
//
411
- // 1. goto /home (with iframe to /sub) and wait for the specified lifecycle event.
428
+ // Steps:
429
+ // 1. goto /home (with iframe to /sub) and wait for the specified lifecycle event.
412
430
//
413
- // Success criteria: The web page (all frames) is in the expected state
414
- // once we receive the specified lifecycle event from
415
- // the browser.
431
+ // Success criteria:
432
+ // The web page (all frames) is in the expected state
433
+ // once we receive the specified lifecycle event from
434
+ // the browser.
416
435
417
436
tests := []struct {
418
437
name string
@@ -490,10 +509,12 @@ func TestLifecycleGoto(t *testing.T) {
490
509
491
510
// Test description
492
511
//
493
- // 1. goto /home and wait for the specified lifecycle event.
512
+ // Steps:
513
+ // 1. goto /home and wait for the specified lifecycle event.
494
514
//
495
- // Success criteria: The web page is in the expected state once we receive
496
- // the specified lifecycle event from the browser.
515
+ // Success criteria:
516
+ // The web page is in the expected state once we receive
517
+ // the specified lifecycle event from the browser.
497
518
498
519
tests := []struct {
499
520
name string
@@ -712,9 +733,7 @@ func assertHome(
712
733
},
713
734
)
714
735
if secondCheck != nil {
715
- prm .then (func () {
716
- secondCheck ()
717
- })
736
+ prm .then (secondCheck )
718
737
}
719
738
720
739
return nil
0 commit comments