@@ -76,3 +76,53 @@ Then('the Logo should be displayed in the top left corner', async function () {
76
76
throw new Error ( 'Logo (favicon.png) is not displayed in a nav element' ) ;
77
77
}
78
78
} ) ;
79
+
80
+ Then ( 'the recent posts list should be present' , async function ( ) {
81
+ if ( ! page ) {
82
+ throw new Error ( 'Page not initialized. Make sure previous steps are executed first.' ) ;
83
+ }
84
+
85
+ // Check that the recent posts section exists with its heading
86
+ try {
87
+ const recentPostsHeading = await page . locator ( 'h2:has-text("Recent Posts")' ) ;
88
+ await recentPostsHeading . waitFor ( { state : 'visible' , timeout : 10000 } ) ;
89
+
90
+ // Check that the posts list exists
91
+ const postsList = await page . locator ( 'ul.posts' ) ;
92
+ await postsList . waitFor ( { state : 'visible' , timeout : 10000 } ) ;
93
+ } catch ( error ) {
94
+ throw new Error ( 'Recent posts list is not present on the page' ) ;
95
+ }
96
+ } ) ;
97
+
98
+ Then ( 'each recent post should have a picture tag with an img element' , async function ( ) {
99
+ if ( ! page ) {
100
+ throw new Error ( 'Page not initialized. Make sure previous steps are executed first.' ) ;
101
+ }
102
+
103
+ // Find all post items in the recent posts list
104
+ const postItems = await page . locator ( 'ul.posts li.post' ) . all ( ) ;
105
+
106
+ if ( postItems . length === 0 ) {
107
+ throw new Error ( 'No recent posts found in the posts list' ) ;
108
+ }
109
+
110
+ // Check each post item has a picture tag with img element
111
+ for ( let i = 0 ; i < postItems . length ; i ++ ) {
112
+ const postItem = postItems [ i ] ;
113
+
114
+ try {
115
+ // Look for either a picture tag with img, or just an img tag within the media-left link
116
+ const imageElement = await postItem . locator ( 'a.media-left picture img, a.media-left img' ) . first ( ) ;
117
+ await imageElement . waitFor ( { state : 'visible' , timeout : 5000 } ) ;
118
+
119
+ // Verify the img element has a valid src attribute
120
+ const src = await imageElement . getAttribute ( 'src' ) ;
121
+ if ( ! src || src . trim ( ) === '' ) {
122
+ throw new Error ( `Post ${ i + 1 } has an img element but no src attribute` ) ;
123
+ }
124
+ } catch ( error ) {
125
+ throw new Error ( `Post ${ i + 1 } does not have a picture tag with img element: ${ error . message } ` ) ;
126
+ }
127
+ }
128
+ } ) ;
0 commit comments