@@ -2,7 +2,7 @@ import { fileURLToPath } from 'url'
22import { dirname , resolve , join } from 'path'
33import { spawn , ChildProcess } from 'child_process'
44import { createRequire } from 'module'
5- import { Builder , WebDriver , By , until } from 'selenium-webdriver'
5+ import { Builder , WebDriver , By , until , logging } from 'selenium-webdriver'
66
77const require = createRequire ( import . meta. url )
88
@@ -89,20 +89,42 @@ async function createDriver(): Promise<WebDriver> {
8989 )
9090 }
9191
92+ // Enable browser logging to capture console output
93+ const prefs = new logging . Preferences ( )
94+ prefs . setLevel ( logging . Type . BROWSER , logging . Level . ALL )
95+
9296 const driver = await new Builder ( )
9397 . usingServer ( `http://localhost:${ CHROMEDRIVER_PORT } ` )
9498 . withCapabilities ( {
9599 'goog:chromeOptions' : {
96100 binary : APP_BINARY ,
97101 args : chromeArgs ,
98102 } ,
103+ 'goog:loggingPrefs' : {
104+ browser : 'ALL' ,
105+ } ,
99106 } )
107+ . setLoggingPrefs ( prefs )
100108 . forBrowser ( 'chrome' )
101109 . build ( )
102110
103111 return driver
104112}
105113
114+ // Flush browser console logs to stdout
115+ async function flushBrowserLogs ( driver : WebDriver ) : Promise < void > {
116+ try {
117+ const logs = await driver . manage ( ) . logs ( ) . get ( logging . Type . BROWSER )
118+ for ( const entry of logs ) {
119+ const level = entry . level . name
120+ const message = entry . message
121+ console . log ( ` [Browser ${ level } ] ${ message } ` )
122+ }
123+ } catch {
124+ // Ignore errors fetching logs
125+ }
126+ }
127+
106128// Utility for case-insensitive XPath text search
107129function textContainsXPath ( text : string , elementType = '*' ) {
108130 const lowerText = text . toLowerCase ( )
@@ -235,13 +257,17 @@ async function runTest(
235257 const duration = Date . now ( ) - start
236258 results . push ( { name, passed : true , duration } )
237259 console . log ( `\r ✓ ${ name } (${ duration } ms)` )
260+ await flushBrowserLogs ( d )
238261 } catch ( e ) {
239262 const duration = Date . now ( ) - start
240263 const error = e instanceof Error ? e . message : String ( e )
241264 results . push ( { name, passed : false , error, duration } )
242265 console . log ( `\r ✗ ${ name } ` )
243266 console . log ( ` Error: ${ error } ` )
244267
268+ // Flush browser logs on failure for debugging
269+ await flushBrowserLogs ( d )
270+
245271 // Capture debug info on failure
246272 try {
247273 const title = await d . getTitle ( )
@@ -1061,8 +1087,13 @@ async function testWorkspaceCopyView(driver: WebDriver): Promise<void> {
10611087async function cleanup ( ) : Promise < void > {
10621088 const { execSync } = await import ( 'child_process' )
10631089 try {
1064- execSync ( 'pkill -f chromedriver || true' , { stdio : 'ignore' } )
1065- execSync ( 'pkill -f jbrowse-desktop || true' , { stdio : 'ignore' } )
1090+ if ( isWindows ) {
1091+ execSync ( 'taskkill /F /IM chromedriver.exe 2>nul' , { stdio : 'ignore' } )
1092+ execSync ( 'taskkill /F /IM "JBrowse 2.exe" 2>nul' , { stdio : 'ignore' } )
1093+ } else {
1094+ execSync ( 'pkill -f chromedriver || true' , { stdio : 'ignore' } )
1095+ execSync ( 'pkill -f jbrowse-desktop || true' , { stdio : 'ignore' } )
1096+ }
10661097 } catch {
10671098 // Ignore errors
10681099 }
@@ -1140,7 +1171,11 @@ async function main(): Promise<void> {
11401171 // Force kill any remaining jbrowse-desktop processes
11411172 const { execSync } = await import ( 'child_process' )
11421173 try {
1143- execSync ( 'pkill -f jbrowse-desktop || true' , { stdio : 'ignore' } )
1174+ if ( isWindows ) {
1175+ execSync ( 'taskkill /F /IM "JBrowse 2.exe" 2>nul' , { stdio : 'ignore' } )
1176+ } else {
1177+ execSync ( 'pkill -f jbrowse-desktop || true' , { stdio : 'ignore' } )
1178+ }
11441179 } catch {
11451180 // Ignore errors
11461181 }
@@ -1163,7 +1198,11 @@ main().catch(async e => {
11631198 // Force kill any remaining jbrowse-desktop processes
11641199 const { execSync } = await import ( 'child_process' )
11651200 try {
1166- execSync ( 'pkill -f jbrowse-desktop || true' , { stdio : 'ignore' } )
1201+ if ( isWindows ) {
1202+ execSync ( 'taskkill /F /IM "JBrowse 2.exe" 2>nul' , { stdio : 'ignore' } )
1203+ } else {
1204+ execSync ( 'pkill -f jbrowse-desktop || true' , { stdio : 'ignore' } )
1205+ }
11671206 } catch {
11681207 // Ignore errors
11691208 }
0 commit comments