Skip to content

Commit 05aa779

Browse files
Add condition to wait for haiku lines equals to 3
Signed-off-by: Luis Valdes <[email protected]>
1 parent 4df8754 commit 05aa779

File tree

1 file changed

+28
-16
lines changed

1 file changed

+28
-16
lines changed

typescript-sdk/apps/dojo/e2e/featurePages/ToolBaseGenUIPage.ts

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,39 +33,51 @@ export class ToolBaseGenUIPage {
3333
}
3434

3535
async extractChatHaikuContent(page: Page): Promise<string> {
36-
await page.waitForTimeout(3000);
37-
await page.locator('[data-testid="haiku-card"]').first().waitFor({ state: 'visible' });
36+
// Wait for haiku cards to be visible
37+
await page.waitForSelector('[data-testid="haiku-card"]', { state: 'visible' });
38+
3839
const allHaikuCards = page.locator('[data-testid="haiku-card"]');
3940
const cardCount = await allHaikuCards.count();
4041
let chatHaikuContainer;
4142
let chatHaikuLines;
4243

44+
// Find the most recent haiku card with lines
4345
for (let cardIndex = cardCount - 1; cardIndex >= 0; cardIndex--) {
4446
chatHaikuContainer = allHaikuCards.nth(cardIndex);
4547
chatHaikuLines = chatHaikuContainer.locator('[data-testid="haiku-line"]');
46-
const linesCount = await chatHaikuLines.count();
47-
48-
if (linesCount > 0) {
49-
try {
50-
await chatHaikuLines.first().waitFor({ state: 'visible', timeout: 5000 });
51-
break;
52-
} catch (error) {
53-
continue;
54-
}
48+
49+
try {
50+
// Wait for at least 3 haiku lines to be present in this card
51+
await page.waitForFunction((cardIdx) => {
52+
const cards = document.querySelectorAll('[data-testid="haiku-card"]');
53+
if (cards[cardIdx]) {
54+
const lines = cards[cardIdx].querySelectorAll('[data-testid="haiku-line"]');
55+
return lines.length >= 3;
56+
}
57+
return false;
58+
}, cardIndex, { timeout: 10000 });
59+
60+
// Verify the lines are visible
61+
await chatHaikuLines.first().waitFor({ state: 'visible', timeout: 5000 });
62+
break;
63+
} catch (error) {
64+
continue;
5565
}
5666
}
5767

5868
if (!chatHaikuLines) {
59-
throw new Error('No haiku cards with visible lines found');
69+
throw new Error('No haiku cards with 3 visible lines found');
6070
}
6171

6272
const count = await chatHaikuLines.count();
6373
const lines: string[] = [];
6474

65-
for (let i = 0; i < count; i++) {
66-
const haikuLine = chatHaikuLines.nth(i);
67-
const japaneseText = await haikuLine.locator('p').first().innerText();
68-
lines.push(japaneseText);
75+
if (count > 0) {
76+
for (let i = 0; i < count; i++) {
77+
const haikuLine = chatHaikuLines.nth(i);
78+
const japaneseText = await haikuLine.locator('p').first().innerText();
79+
lines.push(japaneseText);
80+
}
6981
}
7082

7183
const chatHaikuContent = lines.join('').replace(/\s/g, '');

0 commit comments

Comments
 (0)