// 验证侧栏折叠交互 const { app, BrowserWindow } = require('electron') app.commandLine.appendSwitch('disable-gpu') app.commandLine.appendSwitch('disable-software-rasterizer') app.whenReady().then(async () => { const win = new BrowserWindow({ width: 1280, height: 900, show: false, webPreferences: { offscreen: true } }) await win.loadURL('http://127.0.0.1:4173/') await new Promise((r) => setTimeout(r, 1200)) const found = await win.webContents.executeJavaScript(`document.querySelector('[aria-label="折叠侧栏"]') ? 'found' : 'NOT-FOUND'`) console.log('collapse btn:', found) await win.webContents.executeJavaScript(`document.querySelector('[aria-label="折叠侧栏"]').click()`) await new Promise((r) => setTimeout(r, 600)) console.log( 'after click: collapsed=', await win.webContents.executeJavaScript(`document.querySelector('aside')?.getAttribute('data-sidebar-collapsed')`), 'width=', await win.webContents.executeJavaScript(`document.querySelector('aside')?.style.width`) ) app.exit(0) })