|
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'; |
@@ -246,7 +246,6 @@ export async function getDashboardSection(sidebar: any): Promise<any> { |
246 | 246 | return await wait.forCondition(async () => { |
247 | 247 | try { |
248 | 248 | // Re-create SideBarView on every iteration — on mac Previous the sidebar object goes stale during workspace transitions and getSections() returns dead nodes on every call. |
249 | | - const { SideBarView } = require('vscode-extension-tester'); |
250 | 249 | const freshSidebar = new SideBarView(); |
251 | 250 | const contentPart = freshSidebar.getContent(); |
252 | 251 | const sections = await contentPart.getSections(); |
@@ -285,7 +284,6 @@ export async function getDashboardItem(section: any, projectName: string): Promi |
285 | 284 | // stale. Getting a fresh section + fresh sidebar each time breaks that loop. |
286 | 285 | return (await wait.forCondition(async () => { |
287 | 286 | try { |
288 | | - const { SideBarView } = require('vscode-extension-tester'); |
289 | 287 | const freshSection = await getDashboardSection(new SideBarView()); |
290 | 288 | await freshSection.expand(); |
291 | 289 | await wait.sleep(1000); |
@@ -526,34 +524,33 @@ export async function clearCommandPalette() { |
526 | 524 | export async function waitForDashboardToLoad(section: any): Promise<void> { |
527 | 525 | const wait = getWaitHelper(); |
528 | 526 | logger.info('Waiting for Liberty Dashboard to load'); |
529 | | - |
530 | | - // Expand the section |
531 | | - await waitForSuccess(async () => { |
532 | | - await section.expand(); |
533 | | - }); |
534 | | - |
535 | | - // Wait for section container to become stable after expansion |
536 | | - await wait.sleep(2000); |
537 | | - |
538 | | - // Wait for items to appear with retry on ElementNotInteractableError |
| 527 | + |
| 528 | + // Re-fetch a fresh section on every poll iteration. The section reference |
| 529 | + // passed in (or obtained just before this call) goes stale on cold runners |
| 530 | + // once VS Code rebuilds the sidebar DOM after workspace activation. |
| 531 | + // Using a stale reference causes ElementNotInteractableError on every |
| 532 | + // getVisibleItems() call, looping forever until timeout. |
539 | 533 | await wait.forCondition(async () => { |
540 | 534 | try { |
541 | | - const items = await section.getVisibleItems(); |
| 535 | + const freshSection = await getDashboardSection(new SideBarView()); |
| 536 | + await freshSection.expand(); |
| 537 | + await wait.sleep(500); |
| 538 | + const items = await freshSection.getVisibleItems(); |
542 | 539 | if (items && items.length > 0) { |
543 | 540 | logger.info(`Dashboard loaded with ${items.length} items`); |
544 | 541 | return true; |
545 | 542 | } |
546 | 543 | } catch (error: any) { |
547 | | - // Retry on ElementNotInteractableError |
548 | | - if (error.name === 'ElementNotInteractableError') { |
| 544 | + if (error.name === 'ElementNotInteractableError' || |
| 545 | + error.name === 'StaleElementReferenceError') { |
549 | 546 | logger.info('Container not yet interactable, retrying...'); |
550 | 547 | return; |
551 | 548 | } |
552 | 549 | throw error; |
553 | 550 | } |
554 | 551 | return; |
555 | 552 | }, { |
556 | | - timeout: 120000, // 2 minutes max |
| 553 | + timeout: 240000, // 4 minutes — matches the 275 s Mocha cap on "Liberty Tools shows items" |
557 | 554 | pollInterval: 5000, // check every 5 seconds |
558 | 555 | message: 'Dashboard items did not load' |
559 | 556 | }); |
@@ -745,7 +742,6 @@ export async function closeWorkspace(): Promise<void> { |
745 | 742 | try { |
746 | 743 | await wait.forCondition(async () => { |
747 | 744 | try { |
748 | | - const { SideBarView } = require('vscode-extension-tester'); |
749 | 745 | const sidebar = new SideBarView(); |
750 | 746 | const sections = await sidebar.getContent().getSections(); |
751 | 747 | for (const sec of sections) { |
|
0 commit comments