1+ const { test, expect } = require ( "@playwright/test" ) ;
2+
3+ test . describe ( "Check Page Title" , ( ) => {
4+ let page ;
5+
6+ test . beforeAll ( async ( { browser } ) => {
7+ page = await browser . newPage ( ) ;
8+ } ) ;
9+
10+ test ( "has title 'Compare Mortgages - Go.Compare'" , async ( ) => {
11+ const MAX_RETRIES = 3 ; // Retry up to 3 times
12+ let retries = 0 ;
13+ let success = false ;
14+
15+ while ( retries < MAX_RETRIES && ! success ) {
16+ try {
17+ console . log ( `Attempt ${ retries + 1 } : Navigating to the page` ) ;
18+ await page . goto ( "https://mortgage.gocompare.com/?utm_source=monitoring" , {
19+ waitUntil : "networkidle" ,
20+ timeout : 60000 , // Increase timeout to 60 seconds
21+ } ) ;
22+
23+ // Check for the intermediary page
24+ if ( await page . locator ( 'h1:has-text("Pardon Our Interruption")' ) . isVisible ( ) ) {
25+ console . error ( "Blocked by intermediary page. Retrying..." ) ;
26+ retries ++ ;
27+ continue ;
28+ }
29+
30+ // Take a screenshot
31+ await page . screenshot ( { path : `screenshot_attempt_${ retries + 1 } .png` , fullPage : true } ) ;
32+
33+ // Retrieve and validate the title
34+ const title = await page . title ( ) ;
35+ console . log ( `Page Title Retrieved: ${ title } ` ) ;
36+ expect ( title ) . toBe ( "Compare Mortgages - Go.Compare" ) ;
37+ success = true ; // Test passed
38+ } catch ( error ) {
39+ console . error ( `Error on attempt ${ retries + 1 } : ${ error . message } ` ) ;
40+ retries ++ ;
41+ }
42+ }
43+
44+ if ( ! success ) {
45+ throw new Error ( "Failed to load the page or retrieve the correct title after multiple retries." ) ;
46+ }
47+ } ) ;
48+
49+ test . afterAll ( async ( ) => {
50+ await page . close ( ) ;
51+ } ) ;
52+ } ) ;
0 commit comments