Skip to content

Commit 3a6f18e

Browse files
fix: stablize test
1 parent 37f3fd0 commit 3a6f18e

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed

test/source/browser/controllable.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,29 @@ abstract class ControllableBase {
121121
throw Error(`waiting failed: Elements did not receive the focus: ${selector}`);
122122
};
123123

124+
/**
125+
* Wait for iframes to be present on the page with retry logic.
126+
* This is useful in CI environments where iframe injection can be slower.
127+
* @param maxAttempts - Maximum number of retry attempts (default: 3)
128+
* @param timeoutPerAttempt - Timeout in seconds for each attempt (default: 20)
129+
* @returns Promise that resolves when iframes are found
130+
*/
131+
public waitForIframes = async (maxAttempts = 3, timeoutPerAttempt = 20): Promise<void> => {
132+
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
133+
try {
134+
await this.waitAll('iframe', { timeout: timeoutPerAttempt });
135+
return; // Success - iframes found
136+
} catch {
137+
if (attempt === maxAttempts) {
138+
throw new Error(`Failed to find iframes after ${maxAttempts} attempts with ${timeoutPerAttempt}s timeout each`);
139+
}
140+
// Log and retry
141+
console.log(`Attempt ${attempt}/${maxAttempts}: iframes not found yet, retrying...`);
142+
await Util.sleep(1); // Brief wait before retry
143+
}
144+
}
145+
};
146+
124147
public notPresent = async (selector: string | string[]) => {
125148
return await this.waitTillGone(selector, { timeout: 0 });
126149
};
@@ -404,7 +427,7 @@ abstract class ControllableBase {
404427
}
405428
throw new Error(
406429
`Selector ${selector} was found but did not match "${needle}" within ${timeoutSec}s. ` +
407-
`Observed content history: "${JSON.stringify(observedContentHistory, undefined, 2)}"`
430+
`Observed content history: "${JSON.stringify(observedContentHistory, undefined, 2)}"`
408431
);
409432
};
410433

@@ -716,7 +739,7 @@ class ConsoleEvent {
716739
public constructor(
717740
public type: string,
718741
public text: string
719-
) {}
742+
) { }
720743
}
721744

722745
export class ControllablePage extends ControllableBase {

test/source/tests/decrypt.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1188,7 +1188,7 @@ XZ8r4OC6sguP/yozWlkG+7dDxsgKQVBENeG6Lw==
11881188
testWithBrowser(async (t, browser) => {
11891189
const msgId = '18ecbf57e1dfb9b5';
11901190
const testPrintBlockInPage = async (page: ControllablePage) => {
1191-
await page.waitAll('iframe');
1191+
await page.waitForIframes();
11921192
const pgpBlock = await page.getFrame(['pgp_block.htm']);
11931193
await pgpBlock.waitForSelTestState('ready');
11941194
const expectedPrintDateString = new Date(1712818847000).toLocaleString();

test/source/tests/tooling/browser-recipe.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,6 @@ export class BrowserRecipe {
273273
return { acctEmail, passphrase: key.passphrase, settingsPage };
274274
};
275275

276-
// todo: move to gmail-page-recipe
277276
public static pgpBlockVerifyDecryptedContent = async (
278277
t: AvaContext,
279278
browser: BrowserHandle,
@@ -289,15 +288,16 @@ export class BrowserRecipe {
289288
// todo: move some of these helpers somewhere to page-recipe/...
290289
// gmail or inbox
291290
public static checkDecryptMsgOnPage = async (t: AvaContext, page: ControllablePage, m: TestMessageAndSession) => {
292-
await page.waitAll('iframe');
291+
// Wait for iframes with retry logic to handle slower CI environments
292+
await page.waitForIframes();
293293
if (m.finishSessionBeforeTesting) {
294294
await BrowserRecipe.finishSession(page);
295-
await page.waitAll('iframe');
295+
await page.waitForIframes();
296296
}
297297
await BrowserRecipe.pgpBlockCheck(t, await page.getFrame(['pgp_block.htm']), m);
298298
if (m.finishSessionAfterTesting) {
299299
await BrowserRecipe.finishSession(page);
300-
await page.waitAll('iframe');
300+
await page.waitForIframes();
301301
const pgpBlockFrame = await page.getFrame(['pgp_block.htm']);
302302
await pgpBlockFrame.waitAll('@pgp-block-content');
303303
await pgpBlockFrame.waitForSelTestState('ready');

0 commit comments

Comments
 (0)