@@ -66,7 +66,8 @@ func TestLifecycleWaitForNavigation(t *testing.T) {
66
66
waitUntil common.LifecycleEvent
67
67
pingRequestTextAssert func (result string , pingCount int )
68
68
pingJSTextAssert func (result string )
69
- assertFunc func (p api.Page )
69
+ assertFunc func (tb * testBrowser , p api.Page ) testPromise
70
+ wantError string
70
71
}{
71
72
{
72
73
name : "load" ,
@@ -104,6 +105,35 @@ func TestLifecycleWaitForNavigation(t *testing.T) {
104
105
assert .EqualValues (t , "ping.js loaded from server" , result )
105
106
},
106
107
},
108
+ {
109
+ // Test description
110
+ //
111
+ // Steps:
112
+ // 1. goto /home and wait for the specified lifecycle event.
113
+ // 2. call WaitForNavigation without clicking on the link.
114
+ // the specified lifecycle event.
115
+ //
116
+ // Success criteria:
117
+ // We want this test to timeout since the navigation has
118
+ // completed, a new one hasn't started but we "accidentally"
119
+ // call WaitForNavigation.
120
+ name : "timeout" ,
121
+ pingSlowness : 0 ,
122
+ pingJSSlow : false ,
123
+ waitUntil : common .LifecycleEventNetworkIdle ,
124
+ assertFunc : func (tb * testBrowser , p api.Page ) testPromise {
125
+ result := p .TextContent ("#pingRequestText" , nil )
126
+ assert .EqualValues (t , "Waiting... pong 10 - for loop complete" , result )
127
+
128
+ waitForNav := p .WaitForNavigation (tb .toGojaValue (& common.FrameWaitForNavigationOptions {
129
+ Timeout : 1000 ,
130
+ WaitUntil : common .LifecycleEventNetworkIdle ,
131
+ }))
132
+
133
+ return tb .promise (waitForNav )
134
+ },
135
+ wantError : "Uncaught (in promise) waiting for navigation: timed out after 1s" ,
136
+ },
107
137
}
108
138
109
139
for _ , tt := range tests {
@@ -119,9 +149,8 @@ func TestLifecycleWaitForNavigation(t *testing.T) {
119
149
120
150
if tt .assertFunc != nil {
121
151
assertHome (t , tb , p , tt .waitUntil , func () testPromise {
122
- tt .assertFunc (p )
123
- return testPromise {}
124
- }, nil )
152
+ return tt .assertFunc (tb , p )
153
+ }, nil , tt .wantError )
125
154
return
126
155
}
127
156
@@ -145,66 +174,11 @@ func TestLifecycleWaitForNavigation(t *testing.T) {
145
174
146
175
result = p .TextContent ("#pingJSText" , nil )
147
176
tt .pingJSTextAssert (result )
148
- })
177
+ }, "" )
149
178
})
150
179
}
151
180
}
152
181
153
- func TestLifecycleWaitForNavigationTimeout (t * testing.T ) {
154
- t .Parallel ()
155
-
156
- // Test description
157
- //
158
- // Steps:
159
- // 1. goto /home and wait for the networkidle lifecycle event.
160
- // 2. use WaitForNavigation with networkidle.
161
- //
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.
167
-
168
- tb := newTestBrowser (t , withFileServer ())
169
- p := tb .NewPage (nil )
170
-
171
- withHomeHandler (t , tb , "lifecycle_no_ping_js.html" )
172
- withPingHandler (t , tb , 0 , nil )
173
-
174
- waitUntil := common .LifecycleEventNetworkIdle
175
- var resolved , rejected bool
176
- err := tb .await (func () error {
177
- opts := tb .toGojaValue (common.FrameGotoOptions {
178
- WaitUntil : waitUntil ,
179
- Timeout : 30 * time .Second ,
180
- })
181
- prm := tb .promise (p .Goto (tb .URL ("/home" ), opts )).then (
182
- func () testPromise {
183
- result := p .TextContent ("#pingRequestText" , nil )
184
- assert .EqualValues (t , "Waiting... pong 10 - for loop complete" , result )
185
-
186
- waitForNav := p .WaitForNavigation (tb .toGojaValue (& common.FrameWaitForNavigationOptions {
187
- Timeout : 1000 ,
188
- WaitUntil : waitUntil ,
189
- }))
190
-
191
- return tb .promise (waitForNav )
192
- },
193
- )
194
- prm .then (func () {
195
- resolved = true
196
- }, func () {
197
- rejected = true
198
- })
199
-
200
- return nil
201
- })
202
- require .NoError (t , err )
203
-
204
- assert .False (t , resolved )
205
- assert .True (t , rejected )
206
- }
207
-
208
182
func TestLifecycleWaitForLoadState (t * testing.T ) {
209
183
t .Parallel ()
210
184
@@ -305,7 +279,7 @@ func TestLifecycleWaitForLoadState(t *testing.T) {
305
279
assertHome (t , tb , p , tt .waitUntil , func () testPromise {
306
280
tt .assertFunc (p )
307
281
return testPromise {}
308
- }, nil )
282
+ }, nil , "" )
309
283
return
310
284
}
311
285
@@ -320,7 +294,7 @@ func TestLifecycleWaitForLoadState(t *testing.T) {
320
294
p .WaitForLoadState (tt .waitUntil .String (), nil )
321
295
322
296
return testPromise {}
323
- }, nil )
297
+ }, nil , "" )
324
298
})
325
299
}
326
300
}
@@ -415,7 +389,7 @@ func TestLifecycleReload(t *testing.T) {
415
389
tt .pingJSTextAssert (result )
416
390
417
391
return testPromise {}
418
- }, nil )
392
+ }, nil , "" )
419
393
})
420
394
}
421
395
}
@@ -499,7 +473,7 @@ func TestLifecycleGotoWithSubFrame(t *testing.T) {
499
473
tt .pingJSTextAssert (result )
500
474
501
475
return testPromise {}
502
- }, nil )
476
+ }, nil , "" )
503
477
})
504
478
}
505
479
}
@@ -569,7 +543,7 @@ func TestLifecycleGoto(t *testing.T) {
569
543
tt .pingJSTextAssert (result )
570
544
571
545
return testPromise {}
572
- }, nil )
546
+ }, nil , "" )
573
547
})
574
548
}
575
549
}
@@ -601,7 +575,7 @@ func TestLifecycleGotoNetworkIdle(t *testing.T) {
601
575
assert .EqualValues (t , "ping.js loaded from server" , result )
602
576
603
577
return testPromise {}
604
- }, nil )
578
+ }, nil , "" )
605
579
})
606
580
607
581
t .Run ("doesn't unblock wait for networkIdle too early" , func (t * testing.T ) {
@@ -623,7 +597,7 @@ func TestLifecycleGotoNetworkIdle(t *testing.T) {
623
597
assert .EqualValues (t , "ping.js loaded from server" , result )
624
598
625
599
return testPromise {}
626
- }, nil )
600
+ }, nil , "" )
627
601
})
628
602
629
603
t .Run ("doesn't unblock wait on networkIdle early when load and domcontentloaded complete at once" , func (t * testing.T ) {
@@ -640,7 +614,7 @@ func TestLifecycleGotoNetworkIdle(t *testing.T) {
640
614
assert .EqualValues (t , "Waiting... pong 10 - for loop complete" , result )
641
615
642
616
return testPromise {}
643
- }, nil )
617
+ }, nil , "" )
644
618
})
645
619
}
646
620
@@ -713,7 +687,7 @@ func assertHome(
713
687
t * testing.T ,
714
688
tb * testBrowser , p api.Page ,
715
689
waitUntil common.LifecycleEvent ,
716
- check func () testPromise , secondCheck func (),
690
+ check func () testPromise , secondCheck func (), wantError string ,
717
691
) {
718
692
t .Helper ()
719
693
@@ -738,6 +712,12 @@ func assertHome(
738
712
739
713
return nil
740
714
})
715
+
716
+ if wantError != "" {
717
+ require .EqualError (t , err , wantError )
718
+ return
719
+ }
720
+
741
721
require .NoError (t , err )
742
722
743
723
assert .True (t , resolved )
0 commit comments