Skip to content

Commit

Permalink
Dumping session state and logs to a file
Browse files Browse the repository at this point in the history
  • Loading branch information
toddtarsi committed Oct 28, 2023
1 parent de83a31 commit 10f9e32
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/selenium-ide/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@seleniumhq/selenium-ide",
"version": "4.0.0-alpha.53",
"version": "4.0.0-alpha.54",
"private": true,
"description": "Selenium IDE electron app",
"author": "Todd <[email protected]>",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { projectEditorCommands } from './projectEditor'
import { testEditorCommands } from './testEditor'
import { projectViewCommands } from './projectView'
import { platform } from 'os'
import helpMenu from './help'

const applicationMenu = (session: Session) => async () =>
Menu.buildFromTemplate([
Expand Down Expand Up @@ -43,6 +44,10 @@ const applicationMenu = (session: Session) => async () =>
label: '&View',
submenu: await projectViewCommands(session)(),
},
{
label: '&Help',
submenu: await helpMenu(session)(),
},
])

export default applicationMenu
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Menu } from 'electron'
import { MenuComponent, Session } from 'main/types'

export const HelpCommands: MenuComponent = (session) => async () =>
[
{
accelerator: 'CommandOrControl+Shift+D',
click: async () => {
await session.system.dumpSession()
},
label: 'Dump Session To File',
},
]

const helpMenu = (session: Session) => async () => {
const menuItems = await HelpCommands(session)()
return Menu.buildFromTemplate(menuItems)
}

export default helpMenu
38 changes: 38 additions & 0 deletions packages/selenium-ide/src/main/session/controllers/System/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,49 @@
import { dialog } from 'electron'
import BaseController from '../Base'
import { isAutomated } from 'main/util'
import { inspect } from 'util'
import { writeFile } from 'fs/promises'

let firstTime = true
export default class SystemController extends BaseController {
constructor(session: any) {
super(session)
this.writeToLog = this.writeToLog.bind(this)
}
isDown = true
shuttingDown = false
logs = ''

async dumpSession() {
const response = await this.session.dialogs.openSave()
if (response.canceled) return
const filePath = response.filePath as string
await writeFile(
filePath,
JSON.stringify(
{
project: this.session.projects.project,
state: this.session.state.state,
logs: this.logs,
},
undefined,
2
)
)
}

async getLogPath() {
return this.session.app.getPath('logs')
}

async getLogs() {
return this.logs
}

async writeToLog(...args: any[]) {
this.logs += args.map((arg) => inspect(arg)).join(' ') + '\n'
}

async startup() {
if (this.isDown) {
await this.session.windows.open('logger')
Expand All @@ -23,6 +57,7 @@ export default class SystemController extends BaseController {
}
}
await this.session.projects.select(firstTime)
await this.session.api.system.onLog.addListener(this.writeToLog)
this.isDown = false
firstTime = false
}
Expand All @@ -39,6 +74,9 @@ export default class SystemController extends BaseController {
}
this.shuttingDown = false
}
try {
await this.session.api.system.onLog.removeListener(this.writeToLog)
} catch (e) {}
}
}

Expand Down

0 comments on commit 10f9e32

Please sign in to comment.