Skip to content

Commit 10f9e32

Browse files
committed
Dumping session state and logs to a file
1 parent de83a31 commit 10f9e32

File tree

4 files changed

+64
-1
lines changed

4 files changed

+64
-1
lines changed

packages/selenium-ide/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@seleniumhq/selenium-ide",
3-
"version": "4.0.0-alpha.53",
3+
"version": "4.0.0-alpha.54",
44
"private": true,
55
"description": "Selenium IDE electron app",
66
"author": "Todd <[email protected]>",

packages/selenium-ide/src/main/session/controllers/Menu/menus/application.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { projectEditorCommands } from './projectEditor'
55
import { testEditorCommands } from './testEditor'
66
import { projectViewCommands } from './projectView'
77
import { platform } from 'os'
8+
import helpMenu from './help'
89

910
const applicationMenu = (session: Session) => async () =>
1011
Menu.buildFromTemplate([
@@ -43,6 +44,10 @@ const applicationMenu = (session: Session) => async () =>
4344
label: '&View',
4445
submenu: await projectViewCommands(session)(),
4546
},
47+
{
48+
label: '&Help',
49+
submenu: await helpMenu(session)(),
50+
},
4651
])
4752

4853
export default applicationMenu
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { Menu } from 'electron'
2+
import { MenuComponent, Session } from 'main/types'
3+
4+
export const HelpCommands: MenuComponent = (session) => async () =>
5+
[
6+
{
7+
accelerator: 'CommandOrControl+Shift+D',
8+
click: async () => {
9+
await session.system.dumpSession()
10+
},
11+
label: 'Dump Session To File',
12+
},
13+
]
14+
15+
const helpMenu = (session: Session) => async () => {
16+
const menuItems = await HelpCommands(session)()
17+
return Menu.buildFromTemplate(menuItems)
18+
}
19+
20+
export default helpMenu

packages/selenium-ide/src/main/session/controllers/System/index.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,49 @@
11
import { dialog } from 'electron'
22
import BaseController from '../Base'
33
import { isAutomated } from 'main/util'
4+
import { inspect } from 'util'
5+
import { writeFile } from 'fs/promises'
46

57
let firstTime = true
68
export default class SystemController extends BaseController {
9+
constructor(session: any) {
10+
super(session)
11+
this.writeToLog = this.writeToLog.bind(this)
12+
}
713
isDown = true
814
shuttingDown = false
15+
logs = ''
16+
17+
async dumpSession() {
18+
const response = await this.session.dialogs.openSave()
19+
if (response.canceled) return
20+
const filePath = response.filePath as string
21+
await writeFile(
22+
filePath,
23+
JSON.stringify(
24+
{
25+
project: this.session.projects.project,
26+
state: this.session.state.state,
27+
logs: this.logs,
28+
},
29+
undefined,
30+
2
31+
)
32+
)
33+
}
934

1035
async getLogPath() {
1136
return this.session.app.getPath('logs')
1237
}
38+
39+
async getLogs() {
40+
return this.logs
41+
}
42+
43+
async writeToLog(...args: any[]) {
44+
this.logs += args.map((arg) => inspect(arg)).join(' ') + '\n'
45+
}
46+
1347
async startup() {
1448
if (this.isDown) {
1549
await this.session.windows.open('logger')
@@ -23,6 +57,7 @@ export default class SystemController extends BaseController {
2357
}
2458
}
2559
await this.session.projects.select(firstTime)
60+
await this.session.api.system.onLog.addListener(this.writeToLog)
2661
this.isDown = false
2762
firstTime = false
2863
}
@@ -39,6 +74,9 @@ export default class SystemController extends BaseController {
3974
}
4075
this.shuttingDown = false
4176
}
77+
try {
78+
await this.session.api.system.onLog.removeListener(this.writeToLog)
79+
} catch (e) {}
4280
}
4381
}
4482

0 commit comments

Comments
 (0)