Added Video Recording for Playwright#4148
Conversation
WalkthroughThe pull request introduces functionality for video recording configuration within the Changes
Sequence Diagram(s)sequenceDiagram
participant U as User
participant UI as WebAgentConfigEditPage
participant PD as PlaywrightDriver
participant PB as PlaywrightBrowser
participant BC as BrowserContext
participant R as Reporter
U->>UI: Toggle "Enable Video Recording" checkbox
UI->>UI: Invoke xEnableVideoRecordingCheckBox_Click
UI->>PD: Update video recording settings (dir, width, height)
PD->>PB: Build options with video recording parameters
PB->>PB: ExecutePlaywrightInstallation("ffmpeg")
alt Installation fails
PB->>PB: Disable video recording and log error
else Installation succeeds
PB->>BC: Launch browser context with video options
end
BC-->>R: On close, retrieve and log video file path
Possibly related PRs
Suggested reviewers
Poem
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 4
🔭 Outside diff range comments (1)
Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightPersistentBrowser.cs (1)
131-149: 🧹 Nitpick (assertive)Video recording configuration properly implemented.
The implementation initializes default values for
RecordVideoSizeand only overrides them when video recording is enabled. This ensures backward compatibility and prevents null reference exceptions.One minor optimization: The check for
_options != nullon line 134 is redundant as it was already checked on line 126. Consider removing this redundant check.-if (_options != null && _options.EnableVideoRecording) +if (_options.EnableVideoRecording)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (8)
Ginger/Ginger/Drivers/DriversConfigsEditPages/WebAgentConfigEditPage.xaml(1 hunks)Ginger/Ginger/Drivers/DriversConfigsEditPages/WebAgentConfigEditPage.xaml.cs(7 hunks)Ginger/Ginger/ValueExpression/UCValueExpression.xaml.cs(1 hunks)Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowser.cs(3 hunks)Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowserTab.cs(1 hunks)Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightDriver.cs(2 hunks)Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightNonPersistentBrowser.cs(4 hunks)Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightPersistentBrowser.cs(3 hunks)
🧰 Additional context used
🧠 Learnings (1)
Ginger/Ginger/Drivers/DriversConfigsEditPages/WebAgentConfigEditPage.xaml.cs (2)
Learnt from: GokulBothe99
PR: Ginger-Automation/Ginger#4107
File: Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowserElement.cs:763-831
Timestamp: 2025-03-25T06:06:39.942Z
Learning: In the Ginger project, prefer readable implementations with fixed values over configurable approaches when implementing UI automation features like drawing, unless configurability is specifically required.
Learnt from: GokulBothe99
PR: Ginger-Automation/Ginger#4107
File: Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowserElement.cs:664-705
Timestamp: 2025-03-25T06:06:39.942Z
Learning: In the Ginger automation framework, exceptions in lower-level browser element operations are handled by their parent methods, which have more context about the operation being performed. Therefore, catch-and-rethrow without additional context is acceptable in the element-level methods.
🧬 Code Definitions (3)
Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightNonPersistentBrowser.cs (1)
Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowser.cs (1)
ExecutePlaywrightInstallation(80-87)
Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightPersistentBrowser.cs (1)
Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowser.cs (1)
ExecutePlaywrightInstallation(80-87)
Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightDriver.cs (1)
Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowser.cs (3)
PlaywrightBrowser(24-88)PlaywrightBrowser(55-63)Options(29-42)
🔇 Additional comments (13)
Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightNonPersistentBrowser.cs (2)
77-88: Good implementation of dependency handling for video recording.The code correctly adds functionality to install the ffmpeg dependency when video recording is enabled. The error handling is robust - if the installation fails, it appropriately logs the error and falls back by disabling video recording rather than allowing the entire process to fail.
The code appropriately leverages the existing
ExecutePlaywrightInstallationmethod fromPlaywrightBrowser.cs.
144-158:Details
❓ Verification inconclusive
Video recording configuration properly implemented.
This implementation correctly initializes and applies the video recording settings to the browser context options. The conditional check ensures video recording is only configured when enabled.
One suggestion: consider handling the case where
RecordVideoDiris empty but video recording is enabled, as this might cause runtime issues.Run the following script to check if there are any validation checks for empty video directory elsewhere in the codebase:
🏁 Script executed:
#!/bin/bash # Check if there's validation for empty video directory in related files rg -A 3 -B 3 "RecordVideoDir" --glob "*.cs"Length of output: 13609
Video Recording Directory Validation in Non-Persistent Browser
- The video recording settings are correctly wired in the browser context options.
- UI flow in the codebase (e.g., in
WebAgentConfigEditPage.xaml.cs) already ensures that an empty video directory value is replaced with the default (~\Documents\VideoRecordings).- However, since
PlaywrightNonPersistentBrowser.cssimply assigns_options.RecordVideoDirwithout an extra check, please verify that all instantiations of_options(including any programmatic ones outside the UI) always provide a valid non-empty directory. If there's any chance of missing validation, consider adding a safeguard here.Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightPersistentBrowser.cs (1)
85-96: Proper implementation of dependency installation for video recording.The code correctly checks if video recording is enabled, attempts to install the required ffmpeg dependency, and gracefully handles failures by disabling video recording and logging an error. This is a robust implementation that prevents failures in the dependency installation from breaking the entire functionality.
Ginger/Ginger/ValueExpression/UCValueExpression.xaml.cs (2)
121-127: Enhanced folder selection feature with path expansion.The implementation successfully adds the ability to use relative paths starting with
~\when browsing for folders, which is expanded to the solution's directory. This provides better user experience by allowing users to specify relative paths that will be correctly resolved.Good defensive programming with the null check before performing string operations on
ValueTextBox.Text.
132-134: Improved folder browser configuration.The implementation now sets the initial directory based on the user input or the expanded path, which enhances usability by opening the dialog in the expected location. Also, enabling the "New Folder" button is a good addition for scenarios where users need to create directories on the fly.
Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightDriver.cs (2)
114-119: Good implementation of path resolution for video recording directory.The code correctly handles relative paths for video recording by replacing the tilde prefix with the actual solution folder path. This ensures that video files are stored in a consistent location relative to the project, making it more portable across different environments.
126-128: LGTM: Video recording configuration properly set in browser options.These lines correctly configure the video recording settings in the PlaywrightBrowser options object, ensuring that the user's preferences are properly applied when starting the browser.
Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowser.cs (3)
27-27: LGTM: Added helpful error message constant.Adding this constant helps maintain consistency in error messages throughout the codebase.
39-41: LGTM: Well-defined properties for video recording configuration.These properties properly encapsulate the video recording settings needed by the PlaywrightBrowser.
77-86: Good refactoring of installation logic.Extracting the installation logic into a separate static method improves code reusability and readability. The improved error message now includes the component name and exit code, which will help with troubleshooting.
Ginger/Ginger/Drivers/DriversConfigsEditPages/WebAgentConfigEditPage.xaml.cs (3)
68-103: Good implementation of path normalization for video directory.The code effectively handles path normalization, ensuring that paths are represented consistently using the "~" prefix for paths relative to the solution directory. This improves portability and readability.
398-402: LGTM: Proper event handling setup for the video directory textbox.Event handlers are correctly set up to manage the behavior of the video directory text box, and the initial enabled state of controls is set based on the checkbox state.
532-535: LGTM: Good UI responsiveness for the video recording checkbox.The event handler properly enables/disables the video recording controls based on the checkbox state, providing immediate feedback to the user.
There was a problem hiding this comment.
Actionable comments posted: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (2)
Ginger/Ginger/Drivers/DriversConfigsEditPages/WebAgentConfigEditPage.xaml.cs(7 hunks)Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightDriver.cs(2 hunks)
🧰 Additional context used
🧠 Learnings (1)
Ginger/Ginger/Drivers/DriversConfigsEditPages/WebAgentConfigEditPage.xaml.cs (2)
Learnt from: GokulBothe99
PR: Ginger-Automation/Ginger#4107
File: Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowserElement.cs:763-831
Timestamp: 2025-03-25T06:06:39.942Z
Learning: In the Ginger project, prefer readable implementations with fixed values over configurable approaches when implementing UI automation features like drawing, unless configurability is specifically required.
Learnt from: GokulBothe99
PR: Ginger-Automation/Ginger#4107
File: Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowserElement.cs:664-705
Timestamp: 2025-03-25T06:06:39.942Z
Learning: In the Ginger automation framework, exceptions in lower-level browser element operations are handled by their parent methods, which have more context about the operation being performed. Therefore, catch-and-rethrow without additional context is acceptable in the element-level methods.
🧬 Code Definitions (2)
Ginger/Ginger/Drivers/DriversConfigsEditPages/WebAgentConfigEditPage.xaml.cs (2)
Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightDriver.cs (1)
PlaywrightDriver(53-2007)Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs (1)
eBrowserType(504-507)
Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightDriver.cs (1)
Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowser.cs (3)
PlaywrightBrowser(24-88)PlaywrightBrowser(55-63)Options(29-42)
🔇 Additional comments (12)
Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightDriver.cs (1)
649-668: New video recording properties look consistent.These property definitions correctly associate user-configurable attributes, default values, and descriptive text for video recording. The descriptive text for width and height is correct (no mismatch).
Ginger/Ginger/Drivers/DriversConfigsEditPages/WebAgentConfigEditPage.xaml.cs (11)
22-22: Import statement is appropriate.This addition aligns with the usage of
PlaywrightDriverreferences in this file.
50-50: Initialization call is fine.Calling
InitializeComponent()in the constructor is standard practice for WPF pages.
68-71: LostFocus event handler looks good.This method simply delegates to
ReplaceSolutionDirPathInVideoDirPath, which helps maintain relative paths.
72-93: Path normalization logic is sensible.Using
"~\\"as a placeholder for the solution folder and restoring the default path when empty is a good approach. Ensure edge cases around partial matches of solutionFolder remain acceptable.
95-103: TextChanged event smoothly updates the path.Replacing the solution path on larger edits helps maintain consistent relative paths. The condition
(textChange.AddedLength > 1 || textChange.RemovedLength > 1)is a reasonable heuristic.
321-338: Binding video-recording parameters is correct.These additions allow the UI to manage new Playwright-specific properties (
EnableVideoRecording,RecordVideoDir,VideoHeight, andVideoWidth).
387-387: Advanced settings visibility adjustment is aligned with Playwright usage.No concerns here.
389-389: Hiding RemoteWebDriverUrl for Playwright.Makes sense since remote WebDriver setups are more Selenium-centric.
398-403: Displaying video recording panel & attaching events.Enabling the panel only when video recording is checked is a logical UI flow.
404-407: Hiding video panel for non-Playwright drivers is consistent.Collapsing the panel ensures a clean UI for drivers lacking video-recording features.
531-535: Checkbox click toggles video-panel controls.This short method cleanly updates the
IsEnabledstate based on the checkbox.
There was a problem hiding this comment.
Actionable comments posted: 3
♻️ Duplicate comments (2)
Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightDriver.cs (2)
114-119:⚠️ Potential issueFix path replacement not being applied to final options.
The modified
recordVideoDiris never reassigned back to theRecordVideoDirproperty. When you later useRecordVideoDirin the options at line 127, it still contains the original path with the~\prefix if it was present.Add this line after the path replacement:
string recordVideoDir = RecordVideoDir; if (recordVideoDir != null && recordVideoDir.StartsWith(@"~\")) { string solutionFolder = amdocs.ginger.GingerCoreNET.WorkSpace.Instance.Solution.Folder; recordVideoDir = recordVideoDir.Replace(@"~\", solutionFolder, StringComparison.InvariantCultureIgnoreCase); + RecordVideoDir = recordVideoDir; // Ensure the updated path is used in options }
663-667:⚠️ Potential issueFix inconsistency in the VideoWidth property description and add a default value.
The description incorrectly refers to height instead of width. Also, the property has an empty string default value, which is unusual for an integer property.
[UserConfigured] -[UserConfiguredDefault("")] +[UserConfiguredDefault("1280")] -[UserConfiguredDescription("The height in pixels of video recording")] +[UserConfiguredDescription("The width in pixels of video recording")] public int VideoWidth { get; set; }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (1)
Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightDriver.cs(2 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightDriver.cs (1)
Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowser.cs (3)
PlaywrightBrowser(24-88)PlaywrightBrowser(55-63)Options(29-42)
🔇 Additional comments (2)
Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightDriver.cs (2)
126-128: Ensure video recording options are properly configured.The code correctly adds video recording settings to the browser options, including the recording directory, whether recording is enabled, and the video dimensions.
653-657: LGTM! Enable video recording property correctly implemented.The property is properly configured with a default value of "false" which is a safe default requiring explicit opt-in for video recording.
…//github.com/Ginger-Automation/Ginger into Enhancement/AddRecordVideoFeatureToWebAgents
There was a problem hiding this comment.
Actionable comments posted: 2
🔭 Outside diff range comments (1)
Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightDriver.cs (1)
180-188: 🧹 Nitpick (assertive)Log video file paths when browser closes.
Consider adding logging for video file paths when a browser tab is closed. This would help users locate the video recordings more easily, especially if they're using the default path with environment variables.
private Task OnBrowserClose(IBrowser closedBrowser) { if (closedBrowser == _browser) { _browser = null; + if (EnableVideoRecording && !string.IsNullOrEmpty(RecordVideoDir)) + { + Reporter.ToLog(eLogLevel.INFO, $"Video recording saved to: {RecordVideoDir}"); + } } return Task.CompletedTask; }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (1)
Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightDriver.cs(2 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightDriver.cs (1)
Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowser.cs (3)
PlaywrightBrowser(24-88)PlaywrightBrowser(55-63)Options(29-42)
🔇 Additional comments (5)
Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightDriver.cs (5)
114-119: Ensure updated path reflects in final options.Within this block, the local variable
recordVideoDiris changed if it starts with~\, but that updated value is never reassigned back toRecordVideoDir. As a result, the line in the returnedPlaywrightBrowser.Optionsthat setsRecordVideoDir = recordVideoDiris effectively ignoring the transformed path.A possible fix:
string recordVideoDir = RecordVideoDir; if (recordVideoDir != null && recordVideoDir.StartsWith(@"~\")) { string solutionFolder = amdocs.ginger.GingerCoreNET.WorkSpace.Instance.Solution.Folder; recordVideoDir = recordVideoDir.Replace(@"~\", solutionFolder, StringComparison.InvariantCultureIgnoreCase); } + // Reassign the property to capture the updated path + RecordVideoDir = recordVideoDir;
132-134: LGTM - Video recording configuration is correctly set in options.The implementation properly sets the video recording options in the browser options object.
655-658: Consider adding path validation for video directory.The
RecordVideoDiris properly configured with a default path, but there's no validation to ensure the path is accessible and writable. Consider adding runtime validation when video recording is enabled.Example validation:
if (EnableVideoRecording && !string.IsNullOrEmpty(RecordVideoDir)) { string dirPath = RecordVideoDir; if (dirPath.StartsWith(@"~\")) { string solutionFolder = amdocs.ginger.GingerCoreNET.WorkSpace.Instance.Solution.Folder; dirPath = dirPath.Replace(@"~\", solutionFolder, StringComparison.InvariantCultureIgnoreCase); } try { Directory.CreateDirectory(dirPath); } catch (Exception ex) { Reporter.ToLog(eLogLevel.ERROR, $"Failed to create video recording directory: {dirPath}", ex); EnableVideoRecording = false; } }
667-668: Fix inconsistency in the VideoHeight property description.The description for VideoHeight incorrectly states "The height in pixels" instead of "The width in pixels".
-[UserConfiguredDescription("The height in pixels of video recording")] +[UserConfiguredDescription("The height in pixels of video recording")] public int VideoHeight { get; set; }
665-668: Add a default value for VideoHeight.The
VideoHeightproperty has an empty string default value, which is unusual for an integer property. Consider setting a reasonable default dimension like 720p.[UserConfigured] -[UserConfiguredDefault("")] +[UserConfiguredDefault("720")] [UserConfiguredDescription("The height in pixels of video recording")] public int VideoHeight { get; set; }
Added code to enable Video recording in Playwright
Added code open existing selected directory using VE Expression
Thank you for your contribution.
Before submitting this PR, please make sure:
Summary by CodeRabbit
New Features
Bug Fixes