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

Enhancement - Playwright Window Explorer And Visual Testing Action Support #3850

Merged
merged 7 commits into from
Aug 12, 2024

Conversation

IamRanjeetSingh
Copy link
Contributor

@IamRanjeetSingh IamRanjeetSingh commented Jul 23, 2024

For WindowExplorer, currently below features are functional with Playwright Driver

  1. TreeView
  2. LiveSpy
  3. PageSource

For VisualTesting action currently below features are functional with Playwright Driver

  1. Visual Regression Testing
  2. Applitools

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 support for visual testing actions within the Playwright driver, expanding its capabilities.
    • Enhanced element retrieval logic for improved accuracy, especially with nested structures and specific cases like iframes.
    • Added asynchronous fetching of size and position for web elements, enriching the HTMLElementInfo with spatial data.
  • Improvements

    • Updated action recognition to include visual testing, ensuring all relevant actions are supported.
    • Simplified scripts for retrieving elements to enhance performance.
    • Cleaned up code by removing unused directives for better readability and maintainability.

1. TreeView
2. LiveSpy
3. PageSource
For VisualTesting action currently below features are functional,
1. Visual Regression Testing
2. Applitools
Copy link
Contributor

coderabbitai bot commented Jul 23, 2024

Walkthrough

The recent changes to the PlaywrightDriver and GingerWebDriver classes significantly enhance their functionalities. The PlaywrightDriver now supports visual testing actions directly and improves element retrieval with refined XPath generation. Meanwhile, the GingerWebDriver enriches the CreateHtmlElementAsync method by asynchronously retrieving size and position details of browser elements. Together, these updates bolster the capabilities of web automation tools, providing richer context and interaction capabilities.

Changes

File Change Summary
Ginger/.../PlaywrightDriver.cs, Ginger/.../GingerWebDriver.cs Added support for ActVisualTesting in PlaywrightDriver, enhanced element querying, and updated CreateHtmlElementAsync to include size and position data for HTMLElementInfo.

Poem

In the garden of code, where the rabbits play,
New paths are drawn, guiding the way.
Visual tests hop, with a leap and a bound,
While XPath blooms bright, in layers profound.
So let’s dance with delight, in this code we adore,
For every small change opens a door! 🐇✨


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9076eff and 72351b9.

Files selected for processing (1)
  • Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightDriver.cs (4 hunks)
Additional context used
Learnings (1)
Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightDriver.cs (2)
Learnt from: IamRanjeetSingh
PR: Ginger-Automation/Ginger#3783
File: Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightDriver.cs:129-129
Timestamp: 2024-06-24T08:39:59.351Z
Learning: User IamRanjeetSingh has indicated that the `RunAction` method in the `PlaywrightDriver` class should remain synchronous due to current constraints in the codebase.
Learnt from: GokulBothe99
PR: Ginger-Automation/Ginger#3835
File: Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightDriver.cs:1022-1029
Timestamp: 2024-07-18T09:05:15.264Z
Learning: The user prefers readability over concise code in the context of deactivating locators in the `LearnElementInfoDetails` method of the `PlaywrightDriver` class.
Additional comments not posted (4)
Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightDriver.cs (4)

229-232: LGTM!

The new case for ActVisualTesting is correctly implemented in the IsActionSupported method.


741-748: LGTM!

The GetElementChildren method has been correctly updated to use the new GenerateChildrenXPath method.


778-797: LGTM!

The new GenerateChildrenXPath method is correctly implemented and handles specific cases for iframe and frame elements.


164-166: LGTM! But verify the usage of ActVisualTesting.

The new case for ActVisualTesting is correctly implemented.

However, ensure that all instances of ActVisualTesting are correctly handled in the codebase.

Verification successful

LGTM! But verify the usage of ActVisualTesting.

The new case for ActVisualTesting is correctly implemented.

All instances of ActVisualTesting are correctly handled in the codebase.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all instances of `ActVisualTesting` in the codebase.

# Test: Search for the usage of `ActVisualTesting`. Expect: Only valid instances.
rg --type cs -A 5 $'ActVisualTesting'

Length of output: 52539

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 72351b9 and 2413dae.

Files selected for processing (1)
  • Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightDriver.cs (5 hunks)
Additional context used
Learnings (1)
Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightDriver.cs (2)
Learnt from: IamRanjeetSingh
PR: Ginger-Automation/Ginger#3783
File: Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightDriver.cs:129-129
Timestamp: 2024-06-24T08:39:59.351Z
Learning: User IamRanjeetSingh has indicated that the `RunAction` method in the `PlaywrightDriver` class should remain synchronous due to current constraints in the codebase.
Learnt from: GokulBothe99
PR: Ginger-Automation/Ginger#3835
File: Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightDriver.cs:1022-1029
Timestamp: 2024-07-18T09:05:15.264Z
Learning: The user prefers readability over concise code in the context of deactivating locators in the `LearnElementInfoDetails` method of the `PlaywrightDriver` class.
Additional comments not posted (4)
Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightDriver.cs (4)

164-166: LGTM! Ensure proper testing for the new action type.

The addition of the ActVisualTesting case is correct. Ensure that this new action type is properly tested.


178-178: LGTM!

The addition of ActVisualTesting in the supported actions is correct.


733-734: LGTM!

The usage of the new method GenerateChildrenXPath improves the specificity of element retrieval.


770-789: LGTM!

The method GenerateChildrenXPath is correctly implemented to handle specific cases for iframe and frame elements.

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: 3

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 2413dae and 0cee04d.

Files selected for processing (1)
  • Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightDriver.cs (5 hunks)
Additional context used
Learnings (1)
Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightDriver.cs (2)
Learnt from: IamRanjeetSingh
PR: Ginger-Automation/Ginger#3783
File: Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightDriver.cs:129-129
Timestamp: 2024-06-24T08:39:59.351Z
Learning: User IamRanjeetSingh has indicated that the `RunAction` method in the `PlaywrightDriver` class should remain synchronous due to current constraints in the codebase.
Learnt from: GokulBothe99
PR: Ginger-Automation/Ginger#3835
File: Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightDriver.cs:1022-1029
Timestamp: 2024-07-18T09:05:15.264Z
Learning: The user prefers readability over concise code in the context of deactivating locators in the `LearnElementInfoDetails` method of the `PlaywrightDriver` class.

Comment on lines 232 to 235
else if (act is ActVisualTesting actVisualTesting)
{
return true;
message = $"{actVisualTesting.VisualTestingAnalyzer} is not supported by Playwright driver, use Selenium driver instead.";
return actVisualTesting.VisualTestingAnalyzer == ActVisualTesting.eVisualTestingAnalyzer.VRT;
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure proper support check for ActVisualTesting.

The check for ActVisualTesting is added, but the error message is hardcoded. Consider using a more dynamic approach to handle unsupported analyzers.

-  message = $"{actVisualTesting.VisualTestingAnalyzer} is not supported by Playwright driver, use Selenium driver instead.";
+  message = $"The Visual Testing Analyzer '{actVisualTesting.VisualTestingAnalyzer}' is not supported by the Playwright driver. Please use the Selenium driver instead.";
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
else if (act is ActVisualTesting actVisualTesting)
{
return true;
message = $"{actVisualTesting.VisualTestingAnalyzer} is not supported by Playwright driver, use Selenium driver instead.";
return actVisualTesting.VisualTestingAnalyzer == ActVisualTesting.eVisualTestingAnalyzer.VRT;
message = $"The Visual Testing Analyzer '{actVisualTesting.VisualTestingAnalyzer}' is not supported by the Playwright driver. Please use the Selenium driver instead.";

Comment on lines 164 to 173
case ActVisualTesting actVisualTesting:
if (actVisualTesting.VisualTestingAnalyzer == ActVisualTesting.eVisualTestingAnalyzer.VRT)
{
actVisualTesting.Execute(this);
}
else
{
act.Error = $"{actVisualTesting.VisualTestingAnalyzer} is not supported by Playwright driver, use Selenium driver instead.";
}
break;
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure proper handling of ActVisualTesting.

The new case for ActVisualTesting is added, but the error message is hardcoded. Consider using a more dynamic approach to handle unsupported analyzers.

-  act.Error = $"{actVisualTesting.VisualTestingAnalyzer} is not supported by Playwright driver, use Selenium driver instead.";
+  act.Error = $"The Visual Testing Analyzer '{actVisualTesting.VisualTestingAnalyzer}' is not supported by the Playwright driver. Please use the Selenium driver instead.";
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
case ActVisualTesting actVisualTesting:
if (actVisualTesting.VisualTestingAnalyzer == ActVisualTesting.eVisualTestingAnalyzer.VRT)
{
actVisualTesting.Execute(this);
}
else
{
act.Error = $"{actVisualTesting.VisualTestingAnalyzer} is not supported by Playwright driver, use Selenium driver instead.";
}
break;
case ActVisualTesting actVisualTesting:
if (actVisualTesting.VisualTestingAnalyzer == ActVisualTesting.eVisualTestingAnalyzer.VRT)
{
actVisualTesting.Execute(this);
}
else
{
act.Error = $"The Visual Testing Analyzer '{actVisualTesting.VisualTestingAnalyzer}' is not supported by the Playwright driver. Please use the Selenium driver instead.";
}
break;

Comment on lines +782 to +801
private string GenerateChildrenXPath(string parentXPath)
{
string[] parentXPathSegments = parentXPath.Split("/", StringSplitOptions.RemoveEmptyEntries);
string elementType = parentXPathSegments[^1];

int index = elementType.IndexOf('[');
if (index != -1)
{
elementType = elementType.AsSpan(0, index).ToString();
}

if (string.Equals(elementType, "iframe") || string.Equals(elementType, "frame"))
{
return "/html/*";
}
else
{
return parentXPath + "/*";
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Optimize the XPath generation logic.

The method generates XPath for child elements but can be optimized for readability and performance.

-  string[] parentXPathSegments = parentXPath.Split("/", StringSplitOptions.RemoveEmptyEntries);
-  string elementType = parentXPathSegments[^1];
-  int index = elementType.IndexOf('[');
-  if (index != -1)
-  {
-    elementType = elementType.AsSpan(0, index).ToString();
-  }
-  if (string.Equals(elementType, "iframe") || string.Equals(elementType, "frame"))
-  {
-    return "/html/*";
-  }
-  else
-  {
-    return parentXPath + "/*";
-  }
+  var elementType = parentXPath.Split("/", StringSplitOptions.RemoveEmptyEntries).Last().Split('[').First();
+  return (elementType.Equals("iframe", StringComparison.OrdinalIgnoreCase) || elementType.Equals("frame", StringComparison.OrdinalIgnoreCase)) 
+    ? "/html/*" 
+    : $"{parentXPath}/*";
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
private string GenerateChildrenXPath(string parentXPath)
{
string[] parentXPathSegments = parentXPath.Split("/", StringSplitOptions.RemoveEmptyEntries);
string elementType = parentXPathSegments[^1];
int index = elementType.IndexOf('[');
if (index != -1)
{
elementType = elementType.AsSpan(0, index).ToString();
}
if (string.Equals(elementType, "iframe") || string.Equals(elementType, "frame"))
{
return "/html/*";
}
else
{
return parentXPath + "/*";
}
}
private string GenerateChildrenXPath(string parentXPath)
{
var elementType = parentXPath.Split("/", StringSplitOptions.RemoveEmptyEntries).Last().Split('[').First();
return (elementType.Equals("iframe", StringComparison.OrdinalIgnoreCase) || elementType.Equals("frame", StringComparison.OrdinalIgnoreCase))
? "/html/*"
: $"{parentXPath}/*";
}

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 0cee04d and 4a69670.

Files selected for processing (2)
  • Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/GingerWebDriver.cs (3 hunks)
  • Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightDriver.cs (6 hunks)
Files skipped from review as they are similar to previous changes (1)
  • Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightDriver.cs
Additional context used
Learnings (1)
Common learnings
Learnt from: GokulBothe99
PR: Ginger-Automation/Ginger#3835
File: Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightDriver.cs:1022-1029
Timestamp: 2024-07-18T09:05:15.264Z
Learning: The user prefers readability over concise code in the context of deactivating locators in the `LearnElementInfoDetails` method of the `PlaywrightDriver` class.
Additional comments not posted (1)
Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/GingerWebDriver.cs (1)

528-531: LGTM!

The new properties Width, Height, X, and Y are correctly incorporated into the HTMLElementInfo object.

Comment on lines +515 to +516
Size size = await browserElement.SizeAsync();
Point position = await browserElement.PositionAsync();
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure proper error handling for asynchronous calls.

The asynchronous calls to SizeAsync and PositionAsync should include error handling to manage potential exceptions that may arise.

-  Size size = await browserElement.SizeAsync();
-  Point position = await browserElement.PositionAsync();
+  Size size;
+  try {
+    size = await browserElement.SizeAsync();
+  } catch (Exception ex) {
+    // Handle or log the exception as needed
+    throw new InvalidOperationException("Failed to retrieve size.", ex);
+  }
+  
+  Point position;
+  try {
+    position = await browserElement.PositionAsync();
+  } catch (Exception ex) {
+    // Handle or log the exception as needed
+    throw new InvalidOperationException("Failed to retrieve position.", ex);
+  }
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
Size size = await browserElement.SizeAsync();
Point position = await browserElement.PositionAsync();
Size size;
try {
size = await browserElement.SizeAsync();
} catch (Exception ex) {
// Handle or log the exception as needed
throw new InvalidOperationException("Failed to retrieve size.", ex);
}
Point position;
try {
position = await browserElement.PositionAsync();
} catch (Exception ex) {
// Handle or log the exception as needed
throw new InvalidOperationException("Failed to retrieve position.", ex);
}

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4a69670 and b863fa9.

Files selected for processing (1)
  • Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightDriver.cs (6 hunks)
Files skipped from review as they are similar to previous changes (1)
  • Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightDriver.cs

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