Skip to content

Commit e37b691

Browse files
zhoushawyuyutaotao
andauthored
feat(chrome-recorder): support export all event to document (#973)
* feat(chrome-extension): add export all events functionality and update dependencies - Implemented the ability to export all recorded events to a ZIP file, including screenshots and event details. - Added new utility functions for generating markdown reports and Mermaid mindmaps. - Updated package dependencies: added , , and to handle file exports. - Enhanced the recorder component to include an export button for all events. * feat(chrome-extension): implement AI-powered mindmap generation and enhance export functionality - Added a new function to generate AI-powered mindmaps based on recorded session events, improving visualization of user journeys. - Updated the export functionality to include the AI-generated mindmap in the test report. - Refactored existing mindmap generation logic for better organization and clarity. - Enhanced error handling during the export process to provide user feedback on success or failure. - Improved UI layout for the export button in the RecordList component. * chore(ci): fix unit ai test * fix(tests): change export from 'export const' to 'const' in playwright-generator test files * refactor(chrome-extension): update export button UI in RecordList component - Replaced the existing export button with a more user-friendly design, featuring a bold label and an icon for exporting events. - Improved layout and styling for better visibility and interaction. * refactor(chrome-extension): remove static mindmap generation and enhance event report formatting - Removed the outdated static mindmap generation function to streamline code. - Updated the event report markdown table to include separate columns for before and after screenshots. - Improved the structure of the element description guidelines in the AI model prompt for clarity and precision. * refactor(chrome-extension): improve code formatting in RecordList component - Enhanced code readability by adjusting formatting and indentation in the RecordList component. - Standardized class attribute quotes and improved the layout of JSX elements for better maintainability. * chore: optimize refresh or open new tab click event * refactor(recorder): enhance label click handling and add XPath support - Updated the EventRecorder to include XPath information for label elements, improving the accuracy of event tracking. - Modified the checkLabelClick method to utilize the new XPath feature, allowing for more precise event handling. - Improved the structure of the element description guidelines in the snapshot tests for clarity and consistency. * chore: merge main branch * chore: merge main branch * feat(ai): add callAiFnWithStringResponse for string responses (#989) --------- Co-authored-by: zhouxiao.shaw <[email protected]> * refactor(recorder): streamline ProgressModal code and improve download success messages - Refactored the streaming callback handler for better readability and consistency. - Updated success messages for downloaded Playwright and YAML scripts to clarify the content type. * chore: merge main branch * chore: fix lint error --------- Co-authored-by: yuyutaotao <[email protected]>
1 parent 13c9da2 commit e37b691

File tree

17 files changed

+611
-70
lines changed

17 files changed

+611
-70
lines changed

apps/chrome-extension/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@
1717
"@midscene/shared": "workspace:*",
1818
"@midscene/visualizer": "workspace:*",
1919
"@midscene/web": "workspace:*",
20+
"@types/file-saver": "2.0.7",
2021
"antd": "^5.21.6",
2122
"canvas-confetti": "1.9.3",
2223
"dayjs": "^1.11.11",
24+
"file-saver": "2.0.5",
2325
"highlight.js": "11.11.1",
26+
"jszip": "3.10.1",
2427
"react": "18.3.1",
2528
"react-dom": "18.3.1",
2629
"react-highlight": "0.15.0",

apps/chrome-extension/src/extension/recorder/components/ProgressModal.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ export const ProgressModal: React.FC<ProgressModalProps> = ({
612612

613613
URL.revokeObjectURL(url);
614614
message.success(
615-
`Playwright test for "${downloadSessionName}" downloaded successfully`,
615+
`Playwright script for "${downloadSessionName}" downloaded successfully`,
616616
);
617617
};
618618

@@ -632,7 +632,7 @@ export const ProgressModal: React.FC<ProgressModalProps> = ({
632632

633633
URL.revokeObjectURL(url);
634634
message.success(
635-
`YAML test for "${downloadSessionName}" downloaded successfully`,
635+
`YAML script for "${downloadSessionName}" downloaded successfully`,
636636
);
637637
};
638638

apps/chrome-extension/src/extension/recorder/components/RecordList.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ interface RecordListProps {
3131
onEditSession: (session: RecordingSession) => void;
3232
onDeleteSession: (sessionId: string) => void;
3333
onExportSession: (session: RecordingSession) => void;
34+
onExportAllEvents: () => void;
3435
onViewDetail: (session: RecordingSession) => void;
3536
isExtensionMode: boolean;
3637
handleCreateNewSession: () => void;
@@ -42,19 +43,34 @@ export const RecordList: React.FC<RecordListProps> = ({
4243
onEditSession,
4344
onDeleteSession,
4445
onExportSession,
46+
onExportAllEvents,
4547
onViewDetail,
4648
isExtensionMode,
4749
handleCreateNewSession,
4850
}) => {
4951
const { config } = useEnvConfig();
5052

5153
const runButtonEnabled = Object.keys(config || {}).length >= 1;
54+
const hasEventsToExport = sessions.some(
55+
(session) => session.events.length > 0,
56+
);
5257

5358
return (
5459
<div className="record-list-view relative">
5560
{/* Environment setup reminder */}
5661
<EnvConfigReminder />
5762

63+
{/* Export All Events Button */}
64+
{hasEventsToExport && (
65+
<div className="h-[30px] font-bold text-[14px] p-[5px]">
66+
<span>Record All</span>
67+
<DownloadOutlined
68+
onClick={onExportAllEvents}
69+
className="cursor-pointer float-right"
70+
/>
71+
</div>
72+
)}
73+
5874
{!isExtensionMode && (
5975
<Alert
6076
message="Limited Functionality"

apps/chrome-extension/src/extension/recorder/hooks/useRecordingSession.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ import {
66
useRecordingSessionStore,
77
} from '../../../store';
88
import { recordLogger } from '../logger';
9-
import { exportEventsToFile, generateDefaultSessionName } from '../utils';
9+
import {
10+
exportAllEventsToZip,
11+
exportEventsToFile,
12+
generateDefaultSessionName,
13+
} from '../utils';
1014

1115
export const useRecordingSession = (currentTab: chrome.tabs.Tab | null) => {
1216
const {
@@ -173,6 +177,26 @@ export const useRecordingSession = (currentTab: chrome.tabs.Tab | null) => {
173177
exportEventsToFile(session.events, session.name);
174178
}, []);
175179

180+
// Export all sessions events to ZIP
181+
const handleExportAllEvents = useCallback(async () => {
182+
recordLogger.info('Exporting all events', {
183+
sessionsCount: sessions.length,
184+
});
185+
const hideLoading = message.loading(
186+
'Exporting all events to ZIP file...',
187+
0,
188+
);
189+
try {
190+
await exportAllEventsToZip(sessions);
191+
message.success('Export all events to ZIP file successfully');
192+
} catch (error) {
193+
message.error('Failed to export all events to ZIP file');
194+
throw error;
195+
} finally {
196+
hideLoading();
197+
}
198+
}, [sessions]);
199+
176200
return {
177201
// State
178202
sessions,
@@ -187,5 +211,6 @@ export const useRecordingSession = (currentTab: chrome.tabs.Tab | null) => {
187211
handleDeleteSession,
188212
handleSelectSession,
189213
handleExportSession,
214+
handleExportAllEvents,
190215
};
191216
};

apps/chrome-extension/src/extension/recorder/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ export default function Recorder() {
8888
handleUpdateSession,
8989
handleDeleteSession,
9090
handleExportSession,
91+
handleExportAllEvents,
9192
} = sessionHooks;
9293

9394
// Initialize recording control with currentTab
@@ -235,6 +236,7 @@ export default function Recorder() {
235236
onEditSession={handleEditSession}
236237
onDeleteSession={handleDeleteSessionWrapper}
237238
onExportSession={handleExportSession}
239+
onExportAllEvents={handleExportAllEvents}
238240
onViewDetail={handleViewDetail}
239241
isExtensionMode={isExtensionMode}
240242
handleCreateNewSession={handleCreateNewSession}

0 commit comments

Comments
 (0)