Skip to content
This repository was archived by the owner on Jul 2, 2026. It is now read-only.

Commit e359a97

Browse files
committed
fix: add fallback for output view
1 parent 5165182 commit e359a97

1 file changed

Lines changed: 38 additions & 2 deletions

File tree

src/ui-interaction/outputView.ts

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import { Duration, log, pause } from '../core/miscellaneous';
99
import { dismissAllNotifications } from './notifications';
1010
import { executeQuickPick } from './commandPrompt';
11-
import { BottomBarPanel, By, OutputView } from 'vscode-extension-tester';
11+
import { BottomBarPanel, By, Key, OutputView } from 'vscode-extension-tester';
1212
import { expect } from 'chai';
1313
import { retryOperation } from '../retryUtils';
1414

@@ -34,7 +34,43 @@ export async function getOutputViewText(outputChannelName = ''): Promise<string>
3434
// Set focus to the contents in the Output panel.
3535
await executeQuickPick('Output: Focus on Output View', Duration.seconds(2));
3636

37-
return await outputView.getText();
37+
try {
38+
return await outputView.getText();
39+
} catch (error) {
40+
// Fallback when outputView.getText() fails
41+
log(`outputView.getText() failed, trying fallback selector: ${(error as Error).message}`);
42+
43+
const clipboard = (await import('clipboardy')).default;
44+
45+
let originalClipboard = '';
46+
try {
47+
originalClipboard = clipboard.readSync();
48+
} catch (clipboardError) {
49+
// workaround issue when clipboard is empty
50+
}
51+
52+
try {
53+
// Try to find the textarea using the fallback selector
54+
const textarea = await outputView.findElement(By.css('.inputarea.monaco-mouse-cursor-text, .inputarea textarea, .monaco-editor textarea'));
55+
56+
// Select all text and copy to clipboard
57+
await textarea.sendKeys(Key.chord(process.platform === 'darwin' ? Key.META : Key.CONTROL, 'a'));
58+
await textarea.sendKeys(Key.chord(process.platform === 'darwin' ? Key.META : Key.CONTROL, 'c'));
59+
60+
const text = clipboard.readSync();
61+
62+
// Restore original clipboard content
63+
if (originalClipboard.length > 0) {
64+
clipboard.writeSync(originalClipboard);
65+
}
66+
67+
return text;
68+
} catch (fallbackError) {
69+
log(`Fallback getText also failed: ${(fallbackError as Error).message}`);
70+
// If fallback also fails, rethrow the original error
71+
throw error;
72+
}
73+
}
3874
}
3975

4076
/**

0 commit comments

Comments
 (0)