Skip to content

playwright Browser Action Operation#4095

Merged
Maheshkale447 merged 7 commits into
Releases/Official-Releasefrom
Feature/PlaywrightPendingOperations
Feb 11, 2025
Merged

playwright Browser Action Operation#4095
Maheshkale447 merged 7 commits into
Releases/Official-Releasefrom
Feature/PlaywrightPendingOperations

Conversation

@GokulBothe99

@GokulBothe99 GokulBothe99 commented Feb 11, 2025

Copy link
Copy Markdown
Contributor

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

  • New Features
    • Introduced enhanced browser interaction capabilities:
      • Script Injection: Enables running custom scripts on web pages.
      • Window Management: Provides a one-click option to maximize the browser window.
      • DOM Context Switching: Allows seamless transition between shadow and default modes.
      • URL Control: Offers options to block or unblock specified URLs.

These updates improve user control over browser sessions, delivering a more dynamic and responsive experience.

@coderabbitai

coderabbitai Bot commented Feb 11, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

The changes extend browser operation functionalities by introducing new asynchronous methods across multiple components. The ActBrowserElementHandler now supports additional browser actions such as JavaScript injection, window maximization, DOM context switching, and URL blocking/unblocking. These functionalities are also reflected in the IBrowserTab interface and its implementation in the PlaywrightBrowserTab class. Error handling improvements have been applied, and the control flow within the HandleAsync method has been updated accordingly.

Changes

Files Change Summary
Ginger/.../Web/ActionHandlers/ActBrowserElementHandler.cs Added new private async methods: HandleInjectJS, HandleMaximizeWindow, HandleSwitchToShadowDOM, HandleSwitchToDefaultDOM, HandleSetBlockedUrls, and HandleUnblockUrls to support additional browser actions.
Ginger/.../Web/IBrowserTab.cs Updated interface by adding new methods: MaximizeWindowAsync(), SetBlockedURLAsync(string), UnblockURLAsync(), SwitchToShadowDomAsync(), and SwitchToDefaultDomAsync().
Ginger/.../Web/Playwright/PlaywrightBrowserTab.cs Implemented new public async methods: MaximizeWindowAsync(), SetBlockedURLAsync(string), UnblockURLAsync(), SwitchToShadowDomAsync(), and SwitchToDefaultDomAsync() to handle browser window management and URL blocking.
Ginger/.../Web/Playwright/PlaywrightDriver.cs Updated IsActionSupported method to include support for ActBrowserElement, allowing it to recognize additional action types.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Handler as ActBrowserElementHandler
    participant BrowserTab as IBrowserTab / PlaywrightBrowserTab

    Client->>Handler: Send browser action request
    Handler->>Handler: Determine action type
    alt InjectJS Action
        Handler->>BrowserTab: HandleInjectJS
    else Maximize Action
        Handler->>BrowserTab: HandleMaximizeWindow / MaximizeWindowAsync
    else Shadow DOM Action
        Handler->>BrowserTab: HandleSwitchToShadowDOM / SwitchToShadowDomAsync
    else Default DOM Action
        Handler->>BrowserTab: HandleSwitchToDefaultDOM / SwitchToDefaultDomAsync
    else URL Blocking Action
        Handler->>BrowserTab: HandleSetBlockedUrls / SetBlockedURLAsync
    else URL Unblocking Action
        Handler->>BrowserTab: HandleUnblockUrls / UnblockURLAsync
    end
    BrowserTab-->>Handler: Response (success/error)
    Handler-->>Client: Return response
Loading

Possibly related PRs

  • Feature - 39263 Playwright New POM Support #3811: The changes in the main PR are related to the modifications in the IBrowserTab interface, specifically the addition of methods for handling browser operations like maximizing windows and managing blocked URLs, which align with the new functionalities introduced in the retrieved PR.
  • Smart sync Action Playwright support #4044: The changes in the main PR are related to the modifications in the retrieved PR as both involve enhancements to browser tab functionalities, specifically with methods for managing window states and URL handling.
  • Enhancement - Playwright Window Explorer And Visual Testing Action Support #3850: The changes in the main PR, which add new methods for browser operations in the ActBrowserElementHandler class, are related to the modifications in the retrieved PR that enhance the PlaywrightBrowserTab class with similar functionalities for managing browser windows and URL handling.

Suggested reviewers

  • Maheshkale447

Poem

I'm a hopping rabbit, code sprouting with glee,
Injecting JS and maximizing with key.
Switching between DOMs with a gentle leap,
Blocking URLs like carrots we keep.
In a world of async wonders where logic runs free,
I celebrate these changes. Hop along with me! 🐇


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a61ad09 and 7509ab9.

📒 Files selected for processing (1)
  • Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightDriver.cs (1 hunks)
🔇 Additional comments (1)
Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightDriver.cs (1)

337-337: LGTM! Support added for ActBrowserElement

The addition of ActBrowserElement to the list of supported actions aligns with the PR's objective to extend browser operation functionalities.


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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 13

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 071875a and aacbb0c.

📒 Files selected for processing (3)
  • Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/ActionHandlers/ActBrowserElementHandler.cs (3 hunks)
  • Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/IBrowserTab.cs (2 hunks)
  • Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowserTab.cs (1 hunks)
🔇 Additional comments (4)
Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/IBrowserTab.cs (2)

113-113: LGTM!

The method signature follows async naming conventions and has an appropriate return type.


115-115: LGTM!

The method signature is well-defined with appropriate return type for success/failure feedback.

Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/ActionHandlers/ActBrowserElementHandler.cs (2)

172-189: LGTM!

The new switch cases follow the existing pattern and correctly map to their corresponding handler methods.


303-314: LGTM!

The method is well-structured with appropriate error handling.

Comment thread Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowserTab.cs Outdated
Comment thread Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowserTab.cs Outdated
Comment thread Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowserTab.cs Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 5

♻️ Duplicate comments (1)
Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowserTab.cs (1)

1239-1259: 🛠️ Refactor suggestion

Add error logging in the catch block for consistency.

The catch block in MaximizeWindowAsyncInternal() simply rethrows without logging. For consistency, consider logging the exception similar to other methods:

catch (Exception ex)
{
+    Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {ex.Message}", ex);
    throw;
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between aacbb0c and 1ce6208.

📒 Files selected for processing (1)
  • Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowserTab.cs (1 hunks)
🔇 Additional comments (2)
Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowserTab.cs (2)

1261-1269: LGTM!

Having a public method that delegates to an internal implementation follows a clean pattern. No issues found here.


1340-1349: Same concern as a previous review comment.

Per earlier feedback, switching to the default DOM might involve more than just setting _currentFrame = _playwrightPage.MainFrame;. If Playwright lacks a direct API for “default DOM,” confirm whether returning to the main frame is appropriate or if additional logic is needed.

Comment thread Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowserTab.cs Outdated
Comment thread Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowserTab.cs Outdated
Comment thread Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowserTab.cs Outdated
Comment thread Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowserTab.cs Outdated
Comment thread Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowserTab.cs Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (1)
Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/IBrowserTab.cs (1)

116-116: ⚠️ Potential issue

Add parameters for shadow root location.

The method should include parameters to locate the shadow host element, similar to other element location methods in the interface.

Apply this diff to add necessary parameters:

-public Task<bool> SwitchToShadowDomAsync();
+public Task<bool> SwitchToShadowDomAsync(eLocateBy locateBy, string locateValue);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1ce6208 and a61ad09.

📒 Files selected for processing (3)
  • Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/ActionHandlers/ActBrowserElementHandler.cs (3 hunks)
  • Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/IBrowserTab.cs (2 hunks)
  • Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowserTab.cs (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/IBrowserTab.cs (1)
Learnt from: GokulBothe99
PR: Ginger-Automation/Ginger#4095
File: Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/IBrowserTab.cs:117-117
Timestamp: 2025-02-11T13:35:40.039Z
Learning: XML documentation is not required for interface methods in the Ginger project as per team preference.
Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowserTab.cs (1)
Learnt from: GokulBothe99
PR: Ginger-Automation/Ginger#4095
File: Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowserTab.cs:1330-1333
Timestamp: 2025-02-11T13:45:38.303Z
Learning: The `SwitchToShadowDomAsync` method in PlaywrightBrowserTab class is intentionally implemented as a placeholder that returns true, with the actual shadow DOM handling logic to be implemented in the future.
🔇 Additional comments (23)
Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowserTab.cs (5)

1239-1263: Proper alignment with prior error-handling recommendations.
It's good to see the new window maximization logic encapsulated under MaximizeWindowAsyncMaximizeWindowInternalAsync, along with consistent exception logging and rethrowing. This matches the previously suggested refactor steps and ensures better maintainability.


1301-1313: Clean approach to split comma-separated URLs.
GetBlockedUrlsArray neatly handles trimming and splitting, avoiding empty entries. No issues spotted.


1314-1339: Complete unblocking functionality.
Calling UnrouteAllAsync() and reloading is straightforward and consistent with the method name, although it unblocks all URLs rather than a subset. The error logging and rethrow approach is commendable.


1341-1349: Placeholder for Shadow DOM switching is intentional.
As noted in your learnings, this method intentionally returns true without real logic. No further action needed at this time.


1350-1359: Placeholder method for returning default DOM.
This method similarly returns true as a placeholder. If future logic is needed, ensure consistent error handling and integrate with _currentFrame = _playwrightPage.MainFrame; or an alternative mechanism.

Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/ActionHandlers/ActBrowserElementHandler.cs (13)

172-174: New InjectJS action looks good.
No issues flagged. The action is properly mapped to the HandleInjectJS method, maintaining clarity and consistency.


175-177: New Maximize action introduced.
The action is properly mapped to the HandleMaximizeWindow method, which helps keep the code organized. No concerns.


178-180: New SwitchToShadowDOM action introduced.
No issues spotted. The action is correctly routed to HandleSwitchToShadowDOM.


181-183: New SwitchToDefaultDOM action introduced.
The mapping to HandleSwitchToDefaultDOM is straightforward and consistent.


184-186: New SetBlockedUrls action introduced.
Mapping to HandleSetBlockedUrls is clear. Good structuring.


187-189: Potential typo in enum name.
The enum value is spelled UnblockeUrls, but the handler method is HandleUnblockUrls(). Consider renaming the enum value for consistency.


202-220: Review of HandleUnblockUrls logic.
Method logic is correct:

  • Checks async call success.
  • Logs and sets the _act.Error on failure.
    Everything appears to align with the codebase’s error-handling pattern.

222-246: Review of HandleSetBlockedUrls logic.
Implementation is robust:

  • Validates the URL string.
  • Invokes the browser API to block URLs.
  • Properly handles exceptions and sets _act.Error.
    No changes needed.

248-266: Review of HandleSwitchToDefaultDOM logic.
Checks the async call return value and sets _act.Error on failure. Clean error handling.


268-293: Review of HandleSwitchToShadowDOM logic.
Ensures locateValue is non-empty and handles the async operation via SwitchToShadowDomAsync(). Logs and sets error if it fails. Looks good.


295-310: Review of HandleMaximizeWindow logic.
Straightforward call to MaximizeWindowAsync. Catches exceptions, sets _act.Error, and logs. Implementation is fine.


312-334: Review of HandleInjectJS logic.
Properly checks that the script is not empty; logs specific errors on exception. This aligns with good error-handling practice.


809-809: StartCaptureNetworkLog call.
Method invocation for capturing network logs is placed in a try/catch block for error handling. Usage appears aligned with the rest of the file.

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

39-39: LGTM!

The formatting change maintains consistency with other method declarations in the interface.


113-113: LGTM!

The method signature follows async naming conventions and provides a standard browser window maximization operation.


114-114: LGTM!

The method signature follows async naming conventions and uses a clear parameter name for URL pattern matching.


117-117: LGTM!

The method signature follows async naming conventions and provides a way to return to the default DOM context.


115-115: Verify unblock behavior.

The method signature looks good. However, please verify if this method unblocks all URLs or only the last blocked URL pattern.

❌ Verification inconclusive

🏁 Script executed:

#!/bin/bash
# Search for the implementation to understand unblock behavior
ast-grep --pattern 'UnblockURLAsync() {
  $$$
}'

Length of output: 50


Verify Unblock Details in Implementations
The interface method’s signature is correct; however, our automated search did not locate its implementation details. Please manually verify—by checking the classes that implement IBrowserTab—whether UnblockURLAsync unblocks all URLs or only the most recent (or last) blocked URL pattern.

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