11const { _electron : electron } = require ( 'playwright' ) ;
22const { test, expect } = require ( '@playwright/test' ) ;
33const { execSync } = require ( 'child_process' ) ;
4+ const os = require ( 'os' ) ;
45
56function isElectronRunning ( ) {
67 try {
7- // Check if Electron process is running on Windows
8- const output = execSync ( 'tasklist' ) . toString ( ) ;
9- return output . includes ( 'electron.exe' ) ;
8+ const platform = os . platform ( ) ;
9+
10+ // Check if Electron process is running based on the operating system
11+ if ( platform === 'win32' ) {
12+ const output = execSync ( 'tasklist' ) . toString ( ) ;
13+ return output . includes ( 'electron.exe' ) ;
14+ } else if ( platform === 'darwin' ) {
15+ const output = execSync ( 'ps -A' ) . toString ( ) ;
16+ return output . includes ( 'Electron' ) ;
17+ } else if ( platform === 'linux' ) {
18+ const output = execSync ( 'pgrep electron' ) . toString ( ) ;
19+ return output . trim ( ) !== '' ;
20+ }
1021 } catch ( error ) {
1122 console . error ( 'Error checking for Electron process:' , error ) ;
1223 return false ;
@@ -15,7 +26,13 @@ function isElectronRunning() {
1526
1627function forceKillElectron ( ) {
1728 try {
18- execSync ( 'taskkill /F /IM electron.exe' ) ;
29+ const platform = os . platform ( ) ;
30+
31+ if ( platform === 'win32' ) {
32+ execSync ( 'taskkill /F /IM electron.exe' ) ;
33+ } else if ( platform === 'darwin' || platform === 'linux' ) {
34+ execSync ( 'pkill -f Electron' ) ;
35+ }
1936 console . log ( 'Electron process forcefully terminated.' ) ;
2037 } catch ( error ) {
2138 console . error ( 'Error forcefully terminating Electron process:' , error ) ;
@@ -36,7 +53,7 @@ test('Launch and close Electron app 10 times', async () => {
3653 // Wait for a moment to allow for process termination
3754 await new Promise ( ( resolve ) => setTimeout ( resolve , 2000 ) ) ;
3855
39- // Check if the Electron app is still running in the task manager
56+ // Check if the Electron app is still running
4057 let running = isElectronRunning ( ) ;
4158 if ( running ) {
4259 console . warn ( `Iteration ${ i + 1 } : Electron app is still running. Attempting to force kill.` ) ;
0 commit comments