88import { Duration , log , pause } from '../core/miscellaneous' ;
99import { dismissAllNotifications } from './notifications' ;
1010import { executeQuickPick } from './commandPrompt' ;
11- import { BottomBarPanel , By , OutputView } from 'vscode-extension-tester' ;
11+ import { BottomBarPanel , By , Key , OutputView } from 'vscode-extension-tester' ;
1212import { expect } from 'chai' ;
1313import { 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