@@ -112,9 +112,13 @@ export class ToolBaseGenUIPage {
112
112
}
113
113
114
114
async checkHaikuDisplay ( page : Page ) : Promise < void > {
115
+ // Wait for both chat and main display to be fully loaded
116
+ await page . waitForTimeout ( 3000 ) ;
117
+
115
118
const chatHaikuContent = await this . extractChatHaikuContent ( page ) ;
116
119
117
- await page . waitForTimeout ( 5000 ) ;
120
+ // Wait a bit more for main display to sync
121
+ await page . waitForTimeout ( 2000 ) ;
118
122
119
123
const mainHaikuContent = await this . extractMainDisplayHaikuContent ( page ) ;
120
124
@@ -123,14 +127,43 @@ export class ToolBaseGenUIPage {
123
127
return ;
124
128
}
125
129
130
+ // Check if contents match exactly
126
131
if ( chatHaikuContent === mainHaikuContent ) {
127
132
expect ( mainHaikuContent ) . toBe ( chatHaikuContent ) ;
133
+ return ;
134
+ }
135
+
136
+ // If they don't match, check if one is a substring of the other (partial loading)
137
+ if ( mainHaikuContent . includes ( chatHaikuContent ) || chatHaikuContent . includes ( mainHaikuContent ) ) {
138
+ console . log ( `Content partially matches - Chat: "${ chatHaikuContent } ", Main: "${ mainHaikuContent } "` ) ;
139
+
140
+ // Wait for content to stabilize and try again
141
+ await page . waitForTimeout ( 5000 ) ;
142
+
143
+ const finalChatContent = await this . extractChatHaikuContent ( page ) ;
144
+ const finalMainContent = await this . extractMainDisplayHaikuContent ( page ) ;
145
+
146
+ // Use the longer content as the expected result (more complete)
147
+ const expectedContent = finalChatContent . length >= finalMainContent . length ? finalChatContent : finalMainContent ;
148
+
149
+ expect ( finalMainContent ) . toBe ( expectedContent ) ;
150
+ expect ( finalChatContent ) . toBe ( expectedContent ) ;
128
151
} else {
129
- await page . waitForTimeout ( 3000 ) ;
152
+ // Contents are completely different - this might indicate an error
153
+ console . log ( `Content mismatch - Chat: "${ chatHaikuContent } ", Main: "${ mainHaikuContent } "` ) ;
154
+
155
+ // Wait longer and try one more time
156
+ await page . waitForTimeout ( 5000 ) ;
157
+
158
+ const retryMainContent = await this . extractMainDisplayHaikuContent ( page ) ;
159
+ const retryChatContent = await this . extractChatHaikuContent ( page ) ;
130
160
131
- const updatedMainContent = await this . extractMainDisplayHaikuContent ( page ) ;
161
+ // At least verify both have content
162
+ expect ( retryChatContent . length ) . toBeGreaterThan ( 0 ) ;
163
+ expect ( retryMainContent . length ) . toBeGreaterThan ( 0 ) ;
132
164
133
- expect ( updatedMainContent ) . toBe ( chatHaikuContent ) ;
165
+ // Try to match again
166
+ expect ( retryMainContent ) . toBe ( retryChatContent ) ;
134
167
}
135
168
}
136
169
}
0 commit comments