@@ -2786,3 +2786,81 @@ func TestPageMustUseNativeJavaScriptObjects(t *testing.T) {
2786
2786
_ , err = page .QueryAll ("#textField" )
2787
2787
require .NoErrorf (t , err , "page should not override the native objects, but it did" )
2788
2788
}
2789
+
2790
+ func TestWaitForNavigationWithURL (t * testing.T ) {
2791
+ t .Parallel ()
2792
+
2793
+ tb := newTestBrowser (t , withFileServer ())
2794
+ tb .vu .ActivateVU ()
2795
+ tb .vu .StartIteration (t )
2796
+
2797
+ got := tb .vu .RunPromise (t , `
2798
+ const page = await browser.newPage();
2799
+ const testURL = '%s';
2800
+
2801
+ try {
2802
+ await page.goto(testURL);
2803
+
2804
+ // Test exact URL match
2805
+ await Promise.all([
2806
+ page.waitForNavigation({ url: '%s' }),
2807
+ page.click('#page1')
2808
+ ]);
2809
+ let currentURL = page.url();
2810
+ if (!currentURL.endsWith('page1.html')) {
2811
+ throw new Error('Expected to navigate to page1.html but got ' + currentURL);
2812
+ }
2813
+
2814
+ await page.goto(testURL);
2815
+
2816
+ // Test regex pattern - matches any page with .html extension
2817
+ await Promise.all([
2818
+ page.waitForNavigation({ url: /.*\.html$/ }),
2819
+ page.click('#page2')
2820
+ ]);
2821
+ currentURL = page.url();
2822
+ if (!currentURL.endsWith('.html')) {
2823
+ throw new Error('Expected URL to end with .html but got ' + currentURL);
2824
+ }
2825
+
2826
+ await page.goto(testURL);
2827
+
2828
+ // Test timeout when URL doesn't match
2829
+ let timedOut = false;
2830
+ try {
2831
+ await Promise.all([
2832
+ page.waitForNavigation({ url: /.*nonexistent.html$/, timeout: 500 }),
2833
+ page.click('#page1') // This goes to page1.html, not nonexistent.html
2834
+ ]);
2835
+ } catch (error) {
2836
+ if (error.toString().includes('waiting for navigation')) {
2837
+ timedOut = true;
2838
+ } else {
2839
+ throw error;
2840
+ }
2841
+ }
2842
+ if (!timedOut) {
2843
+ throw new Error('Expected timeout error when URL does not match');
2844
+ }
2845
+
2846
+ await page.goto(testURL);
2847
+
2848
+ // Test empty pattern (matches any navigation)
2849
+ await Promise.all([
2850
+ page.waitForNavigation({ url: '' }),
2851
+ page.click('#page2')
2852
+ ]);
2853
+ currentURL = page.url();
2854
+ if (!currentURL.endsWith('page2.html')) {
2855
+ throw new Error('Expected empty pattern to match any navigation but got ' + currentURL);
2856
+ }
2857
+ } finally {
2858
+ // Must call close() which will clean up the taskqueue.
2859
+ await page.close();
2860
+ }
2861
+ ` ,
2862
+ tb .staticURL ("waitfornavigation_test.html" ),
2863
+ tb .staticURL ("page1.html" ),
2864
+ )
2865
+ assert .Equal (t , sobek .Undefined (), got .Result ())
2866
+ }
0 commit comments