Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Playwright Defect fix D43161_D43162_D44142_D44141 #4017

Merged
merged 7 commits into from
Dec 4, 2024

Conversation

prashelke
Copy link
Contributor

@prashelke prashelke commented Dec 4, 2024

Thank you for your contribution.
Before submitting this PR, please make sure:

  • PR description and commit message should describe the changes done in this PR
  • Verify the PR is pointing to correct branch i.e. Release or Beta branch if the code fix is for specific release , else point it to master
  • Latest Code from master or specific release branch is merged to your branch
  • No unwanted\commented\junk code is included
  • No new warning upon build solution
  • Code Summary\Comments are added to my code which explains what my code is doing
  • Existing unit test cases are passed
  • New Unit tests are added for your development
  • Sanity Tests are successfully executed for New and Existing Functionality
  • Verify that changes are compatible with all relevant browsers and platforms.
  • After creating pull request there should not be any conflicts
  • Resolve all Codacy comments
  • Builds and checks are passed before PR is sent for review
  • Resolve code review comments
  • Update the Help Library document to match any feature changes

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced dialog handling capabilities, allowing for responsive interactions during asynchronous operations.
    • Added a property to control automatic dismissal of dialogs.
    • Enhanced network log monitoring with new methods for capturing and logging network requests and responses.
    • Added a new control action for setting alert box text in the browser element edit page.
    • Added a new method for asynchronous dialog listening in the browser tab interface.
  • Bug Fixes

    • Improved error handling and logging mechanisms across various components.
  • Refactor

    • Cleaned up unused code and refined logic for handling different action types.
    • Updated URL monitoring conditions for more comprehensive checks.

Copy link
Contributor

coderabbitai bot commented Dec 4, 2024

Walkthrough

The pull request introduces several modifications across multiple files, primarily focusing on enhancing dialog management and network logging capabilities within the Ginger framework. Key changes include refined conditional logic for setting properties in the ControlActionsPage_New class, the addition of dialog listening in the ActUIElementHandler, and improvements to network log handling in the SeleniumDriver. Additionally, new methods and properties for dialog management were added to various classes, ensuring better control over browser interactions and logging mechanisms.

Changes

File Change Summary
Ginger/Ginger/AutomatePageLib/AddActionMenu/WindowExplorer/Common/ControlActionsPage_New.xaml.cs Updated SetPlatformBasedUIUpdates method to conditionally set DefaultAction properties based on type; modified InitOutputValuesGrid to initialize viewCols correctly; removed commented-out code.
Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/ActionHandlers/ActUIElementHandler.cs Added dialog listener initiation in HandleAsync method before JavaScript click operations.
Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/BrowserHelper.cs Updated CreateNetworkLogFile to use Path.DirectorySeparatorChar for file path construction; modified ShouldMonitorUrl for comprehensive URL monitoring.
Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/IBrowserTab.cs Added new method public Task StartListenDialogsAsync(); to interface for dialog management.
Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowserTab.cs Introduced isDialogDismiss property; updated dialog handling methods to utilize this property; added StartListenDialogsAsync method for manual dialog handling; improved network log monitoring methods with error handling.
Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs Enhanced network logging with new methods for monitoring requests and responses; refined browser action handling; improved error handling and logging within various methods.
Ginger/Ginger/Actions/ActionEditPages/ActBrowserElementEditPage.xaml.cs Added new control action SetAlertBoxText in SetVisibleControlsForAction method to manage UI element visibility.

Possibly related PRs

  • Feature - 39263 Playwright New POM Support #3811: The changes in the main PR regarding the ControlActionsPage_New class and its methods for handling UI updates based on action types are related to the enhancements in the PlaywrightDriver class, which also involves handling different actions and improving the overall functionality of the driver.
  • Playwright Extended Support for Network Log ,Alert message and interp… #4010: The updates in the main PR that refine the handling of different action types and improve error handling are connected to the enhancements in the PlaywrightDriver class, which includes new functionalities for managing network logs and alert messages, indicating a broader focus on improving action handling across the board.
  • Enhancement - Playwright Window Explorer And Visual Testing Action Support #3850: The modifications in the PlaywrightDriver class to support visual testing actions align with the changes in the main PR, which also focuses on enhancing the handling of different action types and improving the clarity of the code.
  • Master update post Beta 2 release #3808: The changes in the PlaywrightDriver class regarding the configuration edit page and the handling of various actions are related to the main PR's focus on refining action handling and improving the overall structure of the code.
  • BugFix - 39422 - Implement By Pass Proxy For Playwright #3819: The updates in the PlaywrightDriver class for implementing bypass proxy functionality are relevant to the main PR, as both involve enhancing the capabilities of the driver and improving error handling for various actions.

Suggested reviewers

  • Maheshkale447

🐰 In the code where actions flow,
A dialog's whisper now can grow.
With logs that catch each network trace,
Our browser's dance finds a new grace.
So hop along, let's celebrate,
These changes make our work first-rate! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (5)
Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowserTab.cs (3)

75-75: Consider initializing isDialogDismiss in the constructor.

It's generally a good practice to initialize instance variables in the constructor to ensure they have a valid initial state. Consider moving the initialization of isDialogDismiss to the constructor.


845-845: Consider resetting dialog after accepting.

After accepting the dialog, consider setting dialogs to null to indicate that the dialog has been handled and is no longer available for interaction.


869-869: Consider resetting dialog after dismissing.

After dismissing the dialog, consider setting dialogs to null to indicate that the dialog has been handled and is no longer available for interaction.

Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/BrowserHelper.cs (1)

54-54: Use Path.Combine for constructing file paths.

Instead of manually concatenating directory separators, consider using Path.Combine to construct the FullFilePath. This ensures cross-platform compatibility and improves readability.

Apply this diff to use Path.Combine:

-FullFilePath = $"{FullDirectoryPath}{Path.DirectorySeparatorChar}{Filename}_{DateTime.Now.Day.ToString() }_{ DateTime.Now.Month.ToString() }_{ DateTime.Now.Year.ToString() }_{DateTime.Now.Millisecond.ToString()}.har";
+FullFilePath = Path.Combine(FullDirectoryPath, $"{Filename}_{DateTime.Now.ToString("dd_MM_yyyy_fff")}.har");
Ginger/Ginger/AutomatePageLib/AddActionMenu/WindowExplorer/Common/ControlActionsPage_New.xaml.cs (1)

229-237: LGTM! Consider adding error handling for unsupported action types.

The type-specific handling for setting properties is well-structured and improves type safety. However, consider adding an else clause to handle unsupported action types gracefully.

Consider adding error handling:

 if(DefaultAction is ActUIElement)
 {
     (DefaultAction as ActUIElement).ElementData = mElementInfo.GetElementData();
     DefaultAction.Description = string.Format("{0} : {1} - {2}", (DefaultAction as ActUIElement).ElementAction, mElementInfo.ElementTypeEnum.ToString(), mElementInfo.ElementName);
 }
 else if(DefaultAction is ActBrowserElement)
 {
     DefaultAction.Description = string.Format("{0} : {1} - {2}", (DefaultAction as ActBrowserElement).ControlAction, mElementInfo.ElementTypeEnum.ToString(), mElementInfo.ElementName);
 }
+else
+{
+    throw new InvalidOperationException($"Unsupported action type: {DefaultAction.GetType().Name}");
+}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between c56daff and eb343a2.

📒 Files selected for processing (6)
  • Ginger/Ginger/AutomatePageLib/AddActionMenu/WindowExplorer/Common/ControlActionsPage_New.xaml.cs (1 hunks)
  • Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/ActionHandlers/ActUIElementHandler.cs (1 hunks)
  • Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/BrowserHelper.cs (1 hunks)
  • Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/IBrowserTab.cs (1 hunks)
  • Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowserTab.cs (8 hunks)
  • Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs (1 hunks)
🔇 Additional comments (8)
Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowserTab.cs (4)

813-813: LGTM!

The OnPlaywrightDialog method looks good. It handles the dialog based on the isDialogDismiss flag and stores the dialog for later interaction if needed.


920-921: Verify setting isDialogDismiss after accepting dialog.

Setting isDialogDismiss to true after accepting the dialog with custom text looks good. This ensures that subsequent dialogs will be automatically dismissed.


935-938: LGTM!

The StartListenDialogsAsync method implementation is straightforward and sets isDialogDismiss to false, allowing for manual handling of dialogs.


819-827: Verify dialog handling logic.

The dialog handling logic looks correct. It dismisses the dialog if isDialogDismiss is true, otherwise it stores the dialog in the dialogs variable for later interaction.

To verify the dialog handling:

✅ Verification successful

Dialog handling implementation is correct and properly integrated

The dialog handling implementation is well-structured and works as intended:

  • The dialog handler is properly registered/unregistered via _playwrightPage.Dialog += OnPlaywrightDialog
  • The isDialogDismiss flag is a class-level variable that controls dialog behavior
  • When isDialogDismiss is true, dialogs are automatically dismissed using DismissAsync()
  • When isDialogDismiss is false, the dialog is stored in the dialogs variable for later handling
  • The implementation includes proper error handling with try-catch blocks
  • The class provides methods to accept/dismiss dialogs which appropriately reset the isDialogDismiss flag
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify dialog handling based on isDialogDismiss flag

# Test 1: Check if dialog is dismissed when isDialogDismiss is true
isDialogDismiss=true
OnPlaywrightDialog  # Simulate dialog event
# Expected: Dialog should be dismissed

# Test 2: Check if dialog is stored when isDialogDismiss is false 
isDialogDismiss=false 
OnPlaywrightDialog  # Simulate dialog event
# Expected: Dialog should be stored in dialogs variable

Length of output: 307


Script:

#!/bin/bash
# Let's examine the dialog handling implementation and its usage
rg -A 10 "OnPlaywrightDialog" --type cs

# Also check for any dialog-related tests
rg -A 10 "isDialogDismiss" --type cs

# Look for dialog handling patterns
ast-grep --pattern 'async Task OnPlaywrightDialog($_) { $$$ }'

Length of output: 10396

Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs (2)

Line range hint 751-756: LGTM!

The OnNetworkRequestSent method correctly checks if the request URL should be monitored based on the configured criteria and adds the request details to the networkRequestLogList.


Line range hint 11096-11102: LGTM!

The updated OnNetworkRequestSent method looks good. It checks if the request URL should be monitored based on the configured criteria and adds the request details to the networkRequestLogList.

Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/IBrowserTab.cs (1)

95-96: LGTM!

The addition of the StartListenDialogsAsync method to the IBrowserTab interface is a good enhancement for dialog handling functionality.

Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/ActionHandlers/ActUIElementHandler.cs (1)

696-696: 🛠️ Refactor suggestion

Consider adding cleanup for the dialog listener.

While initializing the dialog listener before the async click is good, consider cleaning up the listener after the operation to prevent potential memory leaks or unexpected behavior in subsequent operations.

Consider wrapping the operation in a try-finally block:

 private async Task HandleAsyncClickAsync()
 {
-    await _browserTab.StartListenDialogsAsync();
+    try 
+    {
+        await _browserTab.StartListenDialogsAsync();
+        string script = "element => setTimeout(function() { element.click(); }, 100);";
+        IBrowserElement element = await GetFirstMatchingElementAsync();
+        await element.ExecuteJavascriptAsync(script);
+    }
+    finally
+    {
+        await _browserTab.StopListenDialogsAsync();
+    }
-    string script = "element => setTimeout(function() { element.click(); }, 100);";
-    IBrowserElement element = await GetFirstMatchingElementAsync();
-    await element.ExecuteJavascriptAsync(script);
 }

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (2)
Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs (2)

8665-8665: Initialize _BrowserHelper earlier

The _BrowserHelper field is initialized here during StartMonitoringNetworkLog, but it would be better to initialize it in the constructor or when the driver starts to ensure it's available throughout the lifetime of the driver.

Consider moving the initialization to the constructor:

public class SeleniumDriver : GingerWebDriver, IVirtualDriver, IWindowExplorer, IVisualTestingDriver, IXPath, IPOM, IRecord
{
    protected IWebDriver Driver;
    BrowserHelper _BrowserHelper;
    
    public SeleniumDriver()
    {
+       _BrowserHelper = new BrowserHelper();
    }
}

Line range hint 1-11500: Consider splitting large class into smaller components

The SeleniumDriver class is quite large (over 11k lines) which makes it hard to maintain. Consider splitting it into smaller, focused components using composition.

Suggested refactoring:

  1. Extract network monitoring functionality into a separate NetworkMonitor class
  2. Extract browser configuration logic into a BrowserConfigurator class
  3. Extract element location logic into an ElementLocator class
  4. Use composition to combine these components in SeleniumDriver

This would improve:

  • Code organization and readability
  • Testability of individual components
  • Separation of concerns
  • Maintainability
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between eb343a2 and f5a845b.

📒 Files selected for processing (2)
  • Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/BrowserHelper.cs (2 hunks)
  • Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/BrowserHelper.cs

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (2)
Ginger/Ginger/Actions/ActionEditPages/ActBrowserElementEditPage.xaml.cs (2)

192-197: LGTM! Consider removing extra blank line

The implementation for SetAlertBoxText follows the established pattern and correctly configures the UI elements. However, there's an unnecessary blank line at line 196 that could be removed for better readability.

 else if(mAct.ControlAction == ActBrowserElement.eControlAction.SetAlertBoxText)
 {
     xValueGrid.Visibility = System.Windows.Visibility.Visible;
     xValueLabel.Content = "Value:";
-     
 }

211-211: Remove unnecessary blank line

This blank line doesn't serve any purpose and should be removed to maintain consistent formatting.

-            
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between f5a845b and 1057254.

📒 Files selected for processing (1)
  • Ginger/Ginger/Actions/ActionEditPages/ActBrowserElementEditPage.xaml.cs (2 hunks)
🔇 Additional comments (1)
Ginger/Ginger/Actions/ActionEditPages/ActBrowserElementEditPage.xaml.cs (1)

192-197: Verify integration with ActUIElementHandler

The UI changes for SetAlertBoxText look good, but let's ensure proper integration with the dialog handling system.

Let's verify the implementation:

✅ Verification successful

SetAlertBoxText action is properly integrated

The implementation is complete and properly integrated across the codebase:

  1. The enum value is properly declared in ActBrowserElement.eControlAction
  2. The action is handled in multiple browser drivers:
    • Selenium implementation in SeleniumDriver.cs using Driver.SwitchTo().Alert().SendKeys()
    • Playwright implementation referenced in PlaywrightDriver.cs
    • Generic handler in ActBrowserElementHandler.cs via HandleSetMessageBoxTextOperation
  3. UI integration is correctly implemented in ActBrowserElementEditPage.xaml.cs
  4. Basic test coverage exists in WebDriverUnitTestCase.cs

The implementation follows the same pattern as other alert-related actions (AcceptMessageBox, DismissMessageBox, GetMessageBoxText) and is properly integrated into the browser action handling system.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the SetAlertBoxText action implementation and test coverage

# Check for the enum declaration
echo "Checking for SetAlertBoxText enum declaration..."
rg -p "enum.*eControlAction" -A 30

# Check for handler implementation
echo "Checking for SetAlertBoxText handler implementation..."
rg -p "SetAlertBoxText.*case" -A 5

# Check for test coverage
echo "Checking for test coverage..."
fd -e cs -e vb --exec rg -p "SetAlertBoxText.*Test"

Length of output: 10492


Script:

#!/bin/bash
# Let's check for the implementation of SetAlertBoxText handling in browser-related files

# Check for SetAlertBoxText implementation in browser handlers
echo "Checking for SetAlertBoxText implementation..."
rg -p "SetAlertBoxText" -B 5 -A 10

# Check for alert-related methods that might handle this action
echo "Checking for alert handling methods..."
rg -p "Alert.*handle|handle.*Alert" -B 5 -A 10

# Look for any alert-related test files
echo "Looking for alert-related test files..."
fd -e cs --exec rg -l "Alert.*Test|Test.*Alert"

Length of output: 11850

@Maheshkale447 Maheshkale447 merged commit 1beff0d into Releases/Official-Release Dec 4, 2024
8 checks passed
@Maheshkale447 Maheshkale447 deleted the BugFix/PlayWrightFix branch December 4, 2024 13:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants