From 513775d0b4520efde020f96e23049956e37e5883 Mon Sep 17 00:00:00 2001 From: Rob Stryker Date: Thu, 14 May 2026 14:17:30 -0400 Subject: [PATCH] Fixes #249 - Add retry logic for flaky extension UI test The extension installed UI test was failing ~50% of the time with StaleElementReferenceError when trying to get the extension title. Root cause: Between finding the extension item and calling getTitle(), VS Code can refresh the extensions list DOM, making the element reference stale. Solution: Add retry logic that: - Catches StaleElementReferenceError - Retries the entire operation (find + getTitle) up to 3 times - Waits 500ms between retries to allow DOM to stabilize - Re-throws if it's a different error or retries are exhausted This should eliminate the flakiness while maintaining test reliability. Co-Authored-By: Claude Sonnet 4.5 --- .../test/ui-test/extensionInstalledUITest.ts | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/vscode/test/ui-test/extensionInstalledUITest.ts b/vscode/test/ui-test/extensionInstalledUITest.ts index 361b767..ac21fc8 100644 --- a/vscode/test/ui-test/extensionInstalledUITest.ts +++ b/vscode/test/ui-test/extensionInstalledUITest.ts @@ -21,9 +21,32 @@ export function extensionInstalledUITest(): void { it('RSP server community extension is installed', async function () { this.timeout(20000); - const item = (await section.findItem(`@installed ` + AdaptersConstants.RSP_EXTENSTION_NAME)) as ExtensionsViewItem; - expect(item).not.undefined; - expect(await item.getTitle()).to.equal(AdaptersConstants.RSP_EXTENSTION_NAME); + + // Retry logic to handle StaleElementReferenceError + const maxRetries = 3; + let lastError: Error | undefined; + + for (let attempt = 0; attempt < maxRetries; attempt++) { + try { + const item = (await section.findItem(`@installed ` + AdaptersConstants.RSP_EXTENSTION_NAME)) as ExtensionsViewItem; + expect(item).not.undefined; + const title = await item.getTitle(); + expect(title).to.equal(AdaptersConstants.RSP_EXTENSTION_NAME); + return; // Success, exit the test + } catch (error: any) { + lastError = error; + if (error.name === 'StaleElementReferenceError' && attempt < maxRetries - 1) { + // Wait a bit before retrying + await new Promise(resolve => setTimeout(resolve, 500)); + continue; + } + // If it's not a stale element error, or we're out of retries, throw + throw error; + } + } + + // If we get here, all retries failed + throw lastError!; }); afterEach(async function () {