@@ -174,12 +174,12 @@ test.describe('Simple Page Router (no basePath, no i18n)', () => {
174174 )
175175
176176 if ( fallbackWasServed ) {
177- const loading = await page . textContent ( '[data-testid=" loading"]' )
177+ const loading = await page . getByTestId ( ' loading' ) . textContent ( )
178178 expect ( loading , 'Fallback should be shown' ) . toBe ( 'Loading...' )
179179 }
180180
181- const date1 = await page . textContent ( '[data-testid=" date-now"]' )
182- const h1 = await page . textContent ( 'h1' )
181+ const date1 = await page . getByTestId ( ' date-now' ) . textContent ( )
182+ const h1 = await page . locator ( 'h1' ) . textContent ( )
183183 expect ( h1 ) . toBe ( expectedH1Content )
184184
185185 // check json route
@@ -238,7 +238,7 @@ test.describe('Simple Page Router (no basePath, no i18n)', () => {
238238 )
239239
240240 // the page is cached
241- const date2 = await page . textContent ( '[data-testid=" date-now"]' )
241+ const date2 = await page . getByTestId ( ' date-now' ) . textContent ( )
242242 expect ( date2 ) . toBe ( date1 )
243243
244244 // check json route
@@ -299,7 +299,7 @@ test.describe('Simple Page Router (no basePath, no i18n)', () => {
299299 expect ( headers3 ?. [ 'x-nextjs-cache' ] ) . toBeUndefined ( )
300300
301301 // the page has now an updated date
302- const date3 = await page . textContent ( '[data-testid=" date-now"]' )
302+ const date3 = await page . getByTestId ( ' date-now' ) . textContent ( )
303303 expect ( date3 ) . not . toBe ( date2 )
304304
305305 // check json route
@@ -366,7 +366,7 @@ test.describe('Simple Page Router (no basePath, no i18n)', () => {
366366 } ,
367367 )
368368 expect ( response1 ?. status ( ) ) . toBe ( 200 )
369- const date1 = ( await page . textContent ( '[data-testid=" date-now"]' ) ) ?? ''
369+ const date1 = ( await page . getByTestId ( ' date-now' ) . textContent ( ) ) ?? ''
370370
371371 // ensure response was produced before invocation (served from cache)
372372 expect ( date1 . localeCompare ( beforeFetch ) ) . toBeLessThan ( 0 )
@@ -391,7 +391,7 @@ test.describe('Simple Page Router (no basePath, no i18n)', () => {
391391 } ,
392392 )
393393 expect ( response2 ?. status ( ) ) . toBe ( 200 )
394- const date2 = ( await page . textContent ( '[data-testid=" date-now"]' ) ) ?? ''
394+ const date2 = ( await page . getByTestId ( ' date-now' ) . textContent ( ) ) ?? ''
395395
396396 // ensure response was produced after initial invocation
397397 expect ( beforeFetch . localeCompare ( date2 ) ) . toBeLessThan ( 0 )
@@ -416,7 +416,7 @@ test.describe('Simple Page Router (no basePath, no i18n)', () => {
416416 )
417417
418418 // ensure response was NOT produced before invocation
419- const date1 = ( await page . textContent ( '[data-testid=" date-now"]' ) ) ?? ''
419+ const date1 = ( await page . getByTestId ( ' date-now' ) . textContent ( ) ) ?? ''
420420 expect ( date1 . localeCompare ( beforeFirstFetch ) ) . toBeGreaterThan ( 0 )
421421
422422 // allow page to get stale
@@ -431,7 +431,7 @@ test.describe('Simple Page Router (no basePath, no i18n)', () => {
431431 / s - m a x a g e = 6 0 , s t a l e - w h i l e - r e v a l i d a t e = [ 0 - 9 ] + , d u r a b l e / ,
432432 )
433433
434- const date2 = ( await page . textContent ( '[data-testid=" date-now"]' ) ) ?? ''
434+ const date2 = ( await page . getByTestId ( ' date-now' ) . textContent ( ) ) ?? ''
435435 expect ( date2 ) . toBe ( date1 )
436436
437437 // wait a bit to ensure background work has a chance to finish
@@ -450,7 +450,7 @@ test.describe('Simple Page Router (no basePath, no i18n)', () => {
450450 / s - m a x a g e = 6 0 , s t a l e - w h i l e - r e v a l i d a t e = [ 0 - 9 ] + , d u r a b l e / ,
451451 )
452452
453- const date3 = ( await page . textContent ( '[data-testid=" date-now"]' ) ) ?? ''
453+ const date3 = ( await page . getByTestId ( ' date-now' ) . textContent ( ) ) ?? ''
454454 expect ( date3 . localeCompare ( date2 ) ) . toBeGreaterThan ( 0 )
455455 } )
456456
@@ -469,7 +469,7 @@ test.describe('Simple Page Router (no basePath, no i18n)', () => {
469469 const headers = response ?. headers ( ) || { }
470470 expect ( response ?. status ( ) ) . toBe ( 404 )
471471
472- expect ( await page . textContent ( 'p ') ) . toBe ( 'Custom 404 page' )
472+ await expect ( page . getByTestId ( 'custom-404 ') ) . toHaveText ( 'Custom 404 page' )
473473
474474 // https://github.com/vercel/next.js/pull/69802 made changes to returned cache-control header,
475475 // after that (14.2.10 and canary.147) 404 pages would have `private` directive, before that
@@ -493,7 +493,7 @@ test.describe('Simple Page Router (no basePath, no i18n)', () => {
493493 const headers = response ?. headers ( ) || { }
494494 expect ( response ?. status ( ) ) . toBe ( 404 )
495495
496- expect ( await page . textContent ( 'p ') ) . toBe ( 'Custom 404 page' )
496+ await expect ( page . getByTestId ( 'custom-404 ') ) . toHaveText ( 'Custom 404 page' )
497497
498498 expect ( headers [ 'debug-netlify-cdn-cache-control' ] ) . toBe (
499499 nextVersionSatisfies ( '>=15.0.0-canary.187' )
@@ -748,12 +748,12 @@ test.describe('Page Router with basePath and i18n', () => {
748748 )
749749
750750 if ( fallbackWasServedImplicitLocale ) {
751- const loading = await page . textContent ( '[data-testid=" loading"]' )
751+ const loading = await page . getByTestId ( ' loading' ) . textContent ( )
752752 expect ( loading , 'Fallback should be shown' ) . toBe ( 'Loading...' )
753753 }
754754
755- const date1ImplicitLocale = await page . textContent ( '[data-testid=" date-now"]' )
756- const h1ImplicitLocale = await page . textContent ( 'h1' )
755+ const date1ImplicitLocale = await page . getByTestId ( ' date-now' ) . textContent ( )
756+ const h1ImplicitLocale = await page . locator ( 'h1' ) . textContent ( )
757757 expect ( h1ImplicitLocale ) . toBe ( expectedH1Content )
758758
759759 const response1ExplicitLocale = await pollUntilHeadersMatch (
@@ -790,12 +790,12 @@ test.describe('Page Router with basePath and i18n', () => {
790790 )
791791
792792 if ( fallbackWasServedExplicitLocale ) {
793- const loading = await page . textContent ( '[data-testid=" loading"]' )
793+ const loading = await page . getByTestId ( ' loading' ) . textContent ( )
794794 expect ( loading , 'Fallback should be shown' ) . toBe ( 'Loading...' )
795795 }
796796
797- const date1ExplicitLocale = await page . textContent ( '[data-testid=" date-now"]' )
798- const h1ExplicitLocale = await page . textContent ( 'h1' )
797+ const date1ExplicitLocale = await page . getByTestId ( ' date-now' ) . textContent ( )
798+ const h1ExplicitLocale = await page . locator ( 'h1' ) . textContent ( )
799799 expect ( h1ExplicitLocale ) . toBe ( expectedH1Content )
800800
801801 // implicit and explicit locale paths should be the same (same cached response)
@@ -861,7 +861,7 @@ test.describe('Page Router with basePath and i18n', () => {
861861 )
862862
863863 // the page is cached
864- const date2ImplicitLocale = await page . textContent ( '[data-testid=" date-now"]' )
864+ const date2ImplicitLocale = await page . getByTestId ( ' date-now' ) . textContent ( )
865865 expect ( date2ImplicitLocale ) . toBe ( date1ImplicitLocale )
866866
867867 const response2ExplicitLocale = await pollUntilHeadersMatch (
@@ -893,7 +893,7 @@ test.describe('Page Router with basePath and i18n', () => {
893893 )
894894
895895 // the page is cached
896- const date2ExplicitLocale = await page . textContent ( '[data-testid=" date-now"]' )
896+ const date2ExplicitLocale = await page . getByTestId ( ' date-now' ) . textContent ( )
897897 expect ( date2ExplicitLocale ) . toBe ( date1ExplicitLocale )
898898
899899 // check json route
@@ -961,7 +961,7 @@ test.describe('Page Router with basePath and i18n', () => {
961961 expect ( headers3ImplicitLocale ?. [ 'x-nextjs-cache' ] ) . toBeUndefined ( )
962962
963963 // the page has now an updated date
964- const date3ImplicitLocale = await page . textContent ( '[data-testid=" date-now"]' )
964+ const date3ImplicitLocale = await page . getByTestId ( ' date-now' ) . textContent ( )
965965 expect ( date3ImplicitLocale ) . not . toBe ( date2ImplicitLocale )
966966
967967 const response3ExplicitLocale = await pollUntilHeadersMatch (
@@ -984,7 +984,7 @@ test.describe('Page Router with basePath and i18n', () => {
984984 expect ( headers3ExplicitLocale ?. [ 'x-nextjs-cache' ] ) . toBeUndefined ( )
985985
986986 // the page has now an updated date
987- const date3ExplicitLocale = await page . textContent ( '[data-testid=" date-now"]' )
987+ const date3ExplicitLocale = await page . getByTestId ( ' date-now' ) . textContent ( )
988988 expect ( date3ExplicitLocale ) . not . toBe ( date2ExplicitLocale )
989989
990990 // implicit and explicit locale paths should be the same (same cached response)
@@ -1057,7 +1057,7 @@ test.describe('Page Router with basePath and i18n', () => {
10571057 expect ( headers4ImplicitLocale ?. [ 'x-nextjs-cache' ] ) . toBeUndefined ( )
10581058
10591059 // the page has now an updated date
1060- const date4ImplicitLocale = await page . textContent ( '[data-testid=" date-now"]' )
1060+ const date4ImplicitLocale = await page . getByTestId ( ' date-now' ) . textContent ( )
10611061 expect ( date4ImplicitLocale ) . not . toBe ( date3ImplicitLocale )
10621062
10631063 const response4ExplicitLocale = await pollUntilHeadersMatch (
@@ -1080,7 +1080,7 @@ test.describe('Page Router with basePath and i18n', () => {
10801080 expect ( headers4ExplicitLocale ?. [ 'x-nextjs-cache' ] ) . toBeUndefined ( )
10811081
10821082 // the page has now an updated date
1083- const date4ExplicitLocale = await page . textContent ( '[data-testid=" date-now"]' )
1083+ const date4ExplicitLocale = await page . getByTestId ( ' date-now' ) . textContent ( )
10841084 expect ( date4ExplicitLocale ) . not . toBe ( date3ExplicitLocale )
10851085
10861086 // implicit and explicit locale paths should be the same (same cached response)
@@ -1173,12 +1173,12 @@ test.describe('Page Router with basePath and i18n', () => {
11731173 )
11741174
11751175 if ( fallbackWasServed ) {
1176- const loading = await page . textContent ( '[data-testid=" loading"]' )
1176+ const loading = await page . getByTestId ( ' loading' ) . textContent ( )
11771177 expect ( loading , 'Fallback should be shown' ) . toBe ( 'Loading...' )
11781178 }
11791179
1180- const date1 = await page . textContent ( '[data-testid=" date-now"]' )
1181- const h1 = await page . textContent ( 'h1' )
1180+ const date1 = await page . getByTestId ( ' date-now' ) . textContent ( )
1181+ const h1 = await page . locator ( 'h1' ) . textContent ( )
11821182 expect ( h1 ) . toBe ( expectedH1Content )
11831183
11841184 // check json route
@@ -1241,7 +1241,7 @@ test.describe('Page Router with basePath and i18n', () => {
12411241 )
12421242
12431243 // the page is cached
1244- const date2 = await page . textContent ( '[data-testid=" date-now"]' )
1244+ const date2 = await page . getByTestId ( ' date-now' ) . textContent ( )
12451245 expect ( date2 ) . toBe ( date1 )
12461246
12471247 // check json route
@@ -1309,7 +1309,7 @@ test.describe('Page Router with basePath and i18n', () => {
13091309 expect ( headers3 ?. [ 'x-nextjs-cache' ] ) . toBeUndefined ( )
13101310
13111311 // the page has now an updated date
1312- const date3 = await page . textContent ( '[data-testid=" date-now"]' )
1312+ const date3 = await page . getByTestId ( ' date-now' ) . textContent ( )
13131313 expect ( date3 ) . not . toBe ( date2 )
13141314
13151315 // check json route
@@ -1360,7 +1360,7 @@ test.describe('Page Router with basePath and i18n', () => {
13601360 const headers = response ?. headers ( ) || { }
13611361 expect ( response ?. status ( ) ) . toBe ( 404 )
13621362
1363- expect ( await page . textContent ( 'p ') ) . toBe ( 'Custom 404 page for locale: en' )
1363+ await expect ( page . getByTestId ( 'custom-404 ') ) . toHaveText ( 'Custom 404 page for locale: en' )
13641364
13651365 expect ( headers [ 'debug-netlify-cdn-cache-control' ] ) . toMatch (
13661366 / n o - c a c h e , n o - s t o r e , m a x - a g e = 0 , m u s t - r e v a l i d a t e , d u r a b l e / m,
@@ -1378,7 +1378,7 @@ test.describe('Page Router with basePath and i18n', () => {
13781378 const headers = response ?. headers ( ) || { }
13791379 expect ( response ?. status ( ) ) . toBe ( 404 )
13801380
1381- expect ( await page . textContent ( 'p ') ) . toBe ( 'Custom 404 page for locale: en' )
1381+ await expect ( page . getByTestId ( 'custom-404 ') ) . toHaveText ( 'Custom 404 page for locale: en' )
13821382
13831383 // Prior to v14.2.4 notFound pages are not cacheable
13841384 // https://github.com/vercel/next.js/pull/66674
0 commit comments