@@ -15,17 +15,61 @@ test('Test Add/Remove Elements', async ({ page }) => {
1515 await page . locator ( ".example button:has-text('Add Element')" ) . waitFor ( { state : 'visible' } ) ;
1616 await page . locator ( ".example button:has-text('Add Element')" ) . click ( ) ;
1717 await page . locator ( "#elements button:has-text('Delete')" ) . click ( ) ;
18- await expect ( await page . locator ( ".added-manually" ) . count ( ) ) . toBeGreaterThanOrEqual ( 0 ) ;
18+
19+ const count = await page . locator ( ".added-manually" ) . count ( ) ;
20+ expect ( count ) . toBeGreaterThanOrEqual ( 0 ) ;
21+ } ) ;
22+
23+ test ( 'Test login with basic auth' , async ( { browser } ) => {
24+
25+ // When Loging in with Basic Auth
26+ const context = await browser . newContext ( {
27+ httpCredentials : {
28+ username : 'admin' ,
29+ password : 'admin' ,
30+ }
31+ } ) ;
32+
33+ const page = await context . newPage ( ) ;
34+ await page . goto ( URLs . BASIC_AUTH ) ; // site that triggers basic auth
35+ await expect ( page ) . toHaveURL ( URLs . BASIC_AUTH ) ; // or any assertion
36+ await expect ( page . locator ( '#content p' ) ) . toHaveText ( 'Congratulations! You must have the proper credentials.' ) ;
37+ } ) ;
38+
39+ test ( 'Test cancel on basic auth' , async ( { browser } ) => {
40+ const context = await browser . newContext ( {
41+ httpCredentials : {
42+ username : 'wronguser' ,
43+ password : 'wrongpass' ,
44+ }
45+ } ) ;
46+
47+ const page = await context . newPage ( ) ;
48+ await page . goto ( URLs . BASIC_AUTH ) ;
49+
50+ // The page will show a 401 error or some unauthorized message
51+ await expect ( page . locator ( 'body' ) ) . toContainText ( 'Not authorized' ) ; // Adjust this
1952} ) ;
2053
21- test ( 'Test Basic Auth ' , async ( { page } ) => {
54+ test ( 'Test Broken Images ' , async ( { page } ) => {
2255 await page . goto ( '/' ) ;
23- await page . locator ( "a:has-text('Basic Auth ')" ) . click ( ) ;
24- await expect ( page ) . toHaveURL ( URLs . BASIC_AUTH ) ;
56+ await page . locator ( "a:has-text('Broken Images ')" ) . click ( ) ;
57+ await expect ( page ) . toHaveURL ( URLs . BROKEN_IMAGES ) ;
2558
26- await expect ( page . locator ( ".example button:has-text('Add Element')" ) ) . toBeVisible ( ) ;
27- await page . locator ( ".example button:has-text('Add Element')" ) . waitFor ( { state : 'visible' } ) ;
28- await page . locator ( ".example button:has-text('Add Element')" ) . click ( ) ;
29- await page . locator ( "#elements button:has-text('Delete')" ) . click ( ) ;
30- await expect ( await page . locator ( ".added-manually" ) . count ( ) ) . toBeGreaterThanOrEqual ( 0 ) ;
59+ const images = page . locator ( 'img' ) ;
60+ const count = await images . count ( ) ;
61+
62+ let brokenCount = 0 ;
63+
64+ for ( let i = 0 ; i < count ; i ++ ) {
65+ const img = images . nth ( i ) ;
66+ const isBroken = await img . evaluate ( ( imgEl ) => {
67+ return ( imgEl as HTMLImageElement ) . naturalWidth === 0 ;
68+ } ) ;
69+
70+ console . log ( `Image ${ i + 1 } : ${ isBroken ? 'BROKEN' : 'OK' } ` ) ;
71+ if ( isBroken ) brokenCount ++ ;
72+ }
73+
74+ expect ( brokenCount ) . toBeGreaterThan ( 0 ) ;
3175} ) ;
0 commit comments