|
3 | 3 | * Copyright IBM Corp. 2023, 2026 |
4 | 4 | */ |
5 | 5 | import path = require('path'); |
6 | | -import { Workbench, InputBox, DefaultTreeItem, ModalDialog, VSBrowser, WaitHelper, BottomBarPanel, OutputView, DebugToolbar } from 'vscode-extension-tester'; |
| 6 | +import { Workbench, InputBox, DefaultTreeItem, ModalDialog, VSBrowser, WaitHelper, BottomBarPanel, OutputView, DebugToolbar, SideBarView } from 'vscode-extension-tester'; |
7 | 7 | import * as fs from 'fs'; |
8 | 8 | import { STOP_DASHBOARD_MAC_ACTION } from '../definitions/constants'; |
9 | 9 | import { MapContextMenuforMac } from './macUtils'; |
@@ -198,20 +198,33 @@ export function getGradle9ProjectPath(): string { |
198 | 198 |
|
199 | 199 | export async function getDashboardSection(sidebar: any): Promise<any> { |
200 | 200 | logger.info("Getting Liberty Tools section"); |
201 | | - return await waitForCondition(async () => { |
202 | | - // Get fresh content on each iteration to avoid stale references |
203 | | - const contentPart = sidebar.getContent(); |
204 | | - const sections = await contentPart.getSections(); |
205 | | - |
206 | | - // Find the Liberty Tools section |
207 | | - for (const sec of sections) { |
208 | | - const title = await sec.getTitle(); |
209 | | - if (title === 'Liberty Tools') { |
210 | | - return sec; |
| 201 | + const wait = getWaitHelper(); |
| 202 | + return await wait.forCondition(async () => { |
| 203 | + try { |
| 204 | + // Re-create SideBarView on every iteration — the captured sidebar |
| 205 | + // reference goes stale on workspace transitions and getSections() |
| 206 | + // throws on every call, bypassing the retry loop. |
| 207 | + const freshSidebar = new SideBarView(); |
| 208 | + const sections = await freshSidebar.getContent().getSections(); |
| 209 | + for (const sec of sections) { |
| 210 | + const title = await sec.getTitle(); |
| 211 | + if (title === 'Liberty Tools') { |
| 212 | + return sec; |
| 213 | + } |
| 214 | + } |
| 215 | + } catch (error: any) { |
| 216 | + if (error.name === 'StaleElementReferenceError' || |
| 217 | + error.name === 'ElementNotInteractableError') { |
| 218 | + return; |
211 | 219 | } |
| 220 | + throw error; |
212 | 221 | } |
213 | 222 | return; |
214 | | - }, 30); |
| 223 | + }, { |
| 224 | + timeout: 30000, |
| 225 | + pollInterval: 3000, |
| 226 | + message: 'Liberty Tools section was not found in sidebar within 30 seconds' |
| 227 | + }); |
215 | 228 | } |
216 | 229 |
|
217 | 230 | export async function getDashboardItem(section: any, projectName: string): Promise<DefaultTreeItem> { |
|
0 commit comments