Skip to content

Commit fe61195

Browse files
committed
adding restart.test.js
1 parent be1d9ca commit fe61195

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

tests/e2e/restart.test.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
const { _electron: electron } = require('playwright');
2+
const { test, expect } = require('@playwright/test');
3+
const { execSync } = require('child_process');
4+
const os = require('os');
5+
6+
function isElectronRunning(pid) {
7+
try {
8+
const platform = os.platform();
9+
let output;
10+
11+
if (platform === 'win32') {
12+
output = execSync(`tasklist /FI "PID eq ${pid}"`).toString();
13+
return output.includes('electron.exe');
14+
} else if (platform === 'darwin' || platform === 'linux') {
15+
output = execSync(`ps -p ${pid}`).toString();
16+
return output.includes('Electron');
17+
}
18+
} catch (error) {
19+
console.error('Error checking for Electron process:', error);
20+
return false;
21+
}
22+
}
23+
24+
test('Launch and close Electron app 10 times', async () => {
25+
for (let i = 0; i < 10; i++) {
26+
console.log(`Iteration ${i + 1}: Launching and closing Electron app.`);
27+
28+
// Launch the Electron app
29+
const app = await electron.launch({ args: ['main.js'] });
30+
const pid = app.process().pid;
31+
const window = await app.firstWindow();
32+
33+
// Selecting the device (MPW1 Gemini)
34+
const deviceDropdown = await window.waitForSelector('#deviceId');
35+
await deviceDropdown.selectOption('MPW1');
36+
37+
38+
// Close the app
39+
await app.close();
40+
41+
// Waiting for a moment to allow for process termination
42+
await new Promise((resolve) => setTimeout(resolve, 3000));
43+
44+
// Check if the Electron app is still running
45+
let running = isElectronRunning(pid);
46+
if (running) {
47+
console.error(`Iteration ${i + 1}: Electron app could not be terminated.`);
48+
break; // Stop further iterations if the app cannot be killed
49+
}
50+
}
51+
});

0 commit comments

Comments
 (0)