Skip to content

[CUS-10544] added support to shadow dom elements for existing addon.#333

Open
ManojTestsigma wants to merge 1 commit intodevfrom
CUS-10544
Open

[CUS-10544] added support to shadow dom elements for existing addon.#333
ManojTestsigma wants to merge 1 commit intodevfrom
CUS-10544

Conversation

@ManojTestsigma
Copy link
Copy Markdown
Contributor

@ManojTestsigma ManojTestsigma commented Feb 16, 2026

please review this addon and publish as PUBLIC

Addon name : 2d_drawing_in_region
Addon accont: https://jarvis-in.testsigma.com/ui/tenants/3/users
Jira: https://testsigma.atlassian.net/browse/CUS-10544

fix

Summary by CodeRabbit

  • New Features
    • Introduced 2D drawing addon enabling drawing on web elements
    • Draw lines, polygons, and rectangles on both regular and Shadow DOM elements
    • Support percentage-based coordinates for relative positioning within elements

@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Feb 16, 2026

📝 Walkthrough

Walkthrough

Introduces a new Maven-based 2D drawing addon that enables automated drawing of lines, polygons, and rectangles on web elements through relative coordinate specifications. Supports both regular DOM and Shadow DOM elements with consistent action-based architecture and coordinate transformation utilities.

Changes

Cohort / File(s) Summary
Project Configuration
2d_drawing_in_region/pom.xml
Defines Maven project structure with coordinates (groupId: com.testsigma.addons, artifactId: 2d_drawing, version: 1.0.1) and required dependencies including testsigma-java-sdk, Selenium, Appium, TestNG, Lombok, and Jackson. Configures shade and source plugins for packaging.
Drawing Infrastructure
src/main/java/com/testsigma/addons/web/DrawingAction.java, src/main/java/com/testsigma/addons/web/ShadowDomHelper.java
Introduces base DrawingAction class extending WebAction with coordinate conversion utilities (retrieveRelativePoints, getPointFromString) and element bound tracking. Adds ShadowDomHelper utility for locating elements within Shadow DOM using host elements and CSS selectors.
Line Drawing Actions
src/main/java/com/testsigma/addons/web/DrawLineOnElement.java, src/main/java/com/testsigma/addons/web/DrawLineOnShadowElement.java
Implements line drawing via mouse movement and click sequences on regular and shadow DOM elements. Accepts start and end coordinates as percentages relative to element bounds, computes absolute positions, and executes action sequence with comprehensive exception handling.
Polygon Drawing Actions
src/main/java/com/testsigma/addons/web/DrawPolygonOnElement.java, src/main/java/com/testsigma/addons/web/DrawPolygonOnShadowElement.java
Implements polygon drawing by parsing colon-separated coordinate pairs, validating minimum 3 distinct positions, and closing the polygon by appending the first point. Performs sequential mouse clicks through each vertex with support for both DOM types.
Rectangle Drawing Actions
src/main/java/com/testsigma/addons/web/DrawRectangleOnElement.java, src/main/java/com/testsigma/addons/web/DrawRectangleOnShadowElement.java
Implements rectangle drawing using drag-and-drop from calculated start coordinates (as percentages) through computed width and height parameters. Applies to both regular and shadow DOM elements with consistent coordinate transformation.
Configuration
2d_drawing_in_region/src/main/resources/testsigma-sdk.properties
Adds testsigma-sdk.api.key property containing JWT token for SDK authentication.

Sequence Diagram

sequenceDiagram
    participant Test as Test Framework
    participant Action as DrawingAction
    participant WebDriver as Selenium WebDriver
    participant Element as WebElement
    participant Mouse as Actions API

    Test->>Action: execute()
    Action->>WebDriver: findElement(locator)
    WebDriver->>Element: return element reference
    Action->>Element: getRect()
    Element->>Action: return bounds (x, y, width, height)
    Action->>Action: convertPercentageToAbsolute(x%, y%)
    Action->>Mouse: new Actions(driver)
    Mouse->>Element: moveToElement(startX, startY)
    Mouse->>Element: click()
    Mouse->>Element: moveToElement(endX, endY)
    Mouse->>Element: click()
    Mouse->>WebDriver: perform()
    WebDriver->>Action: action complete
    Action->>Test: return Result.SUCCESS
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Suggested reviewers

  • Ganesh-Testsigma
  • vigneshtestsigma

Poem

🐰 Hop! Click! Draw with delight,
Lines and shapes both left and right,
Shadow realms now in our sight,
Coordinates dance, percentages bright,
2D magic, automation's might!

🚥 Pre-merge checks | ✅ 2 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 9.09% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Merge Conflict Detection ⚠️ Warning ⚠️ Unable to check for merge conflicts: Failed to fetch base branch: fatal: refusing to fetch into branch 'refs/heads/dev' checked out at '/home/jailuser/git'
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and clearly describes the main change: adding shadow DOM support to the existing 2d_drawing addon, which aligns with the majority of the new classes (DrawLineOnShadowElement, DrawPolygonOnShadowElement, DrawRectangleOnShadowElement) and the core purpose of this PR.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch CUS-10544
⚔️ Resolve merge conflicts (beta)
  • Auto-commit resolved conflicts to branch CUS-10544
  • Create stacked PR with resolved conflicts
  • Post resolved changes as copyable diffs in a comment

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.

Tip

Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@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: 9

🤖 Fix all issues with AI agents
In
`@2d_drawing_in_region/src/main/java/com/testsigma/addons/web/DrawingAction.java`:
- Around line 48-52: getPointFromString currently builds page-absolute
coordinates by adding elementRect.getX()/getY(), but Actions.moveToLocation
expects viewport-relative coordinates; update getPointFromString (or its caller)
to convert to viewport coordinates by subtracting the page scroll/viewport
offset (e.g., use window scrollX/scrollY or driver.executeScript to get scroll
offsets) from the computed absolute x/y before returning the Point, or
alternatively detect and validate the coordinate system and throw/adjust if the
resulting point is outside the viewport to prevent
MoveTargetOutOfBoundsException; refer to getPointFromString, elementRect.getX(),
elementRect.getY(), elementRect.getWidth()/getHeight(), and
Actions.moveToLocation when making this change.

In
`@2d_drawing_in_region/src/main/java/com/testsigma/addons/web/DrawPolygonOnElement.java`:
- Line 55: Update the error message string in DrawPolygonOnElement to correct
the typo: replace "The positions are not with in the element" with "The
positions are not within the element" (locate the call to setErrorMessage in the
DrawPolygonOnElement class and update the message text).
- Around line 41-44: The size check currently allows two points because it uses
xyPairs.size() < 2; update the validation in DrawPolygonOnElement to require at
least three points by changing the condition to xyPairs.size() < 3, keep the
existing setRuntimeErrorMessage call and RuntimeException throw (or adjust the
exception text to match the "minimum 3 positions" message) so the check and
message are consistent; reference xyPairs, setRuntimeErrorMessage and the
RuntimeException in your change.

In
`@2d_drawing_in_region/src/main/java/com/testsigma/addons/web/DrawPolygonOnShadowElement.java`:
- Around line 46-48: The validation in DrawPolygonOnShadowElement incorrectly
allows only two points by checking if (xyPairs.size() < 2); update the guard to
require at least three points (change the condition to < 3), and keep the
existing runtime error path (setRuntimeErrorMessage and throwing
RuntimeException) so invalid input still logs and fails; look for the
xyPairs.size() check inside the DrawPolygonOnShadowElement class/method and
modify it accordingly.

In
`@2d_drawing_in_region/src/main/java/com/testsigma/addons/web/DrawRectangleOnElement.java`:
- Line 62: Update the typo in the error text passed to setErrorMessage: change
"The positions are not with in the element" to "The positions are not within the
element" in DrawRectangleOnElement (method that calls setErrorMessage) and make
the identical correction in DrawLineOnElement where the same setErrorMessage
string is used; ensure both occurrences use the single-word "within".
- Line 24: The class DrawRectangleOnElement currently extends WebAction (same as
DrawRectangleOnShadowElement) causing duplicated coordinate logic; change its
base class to extend DrawingAction instead of WebAction, migrate or remove any
duplicated coordinate-handling code so it uses the shared logic in
DrawingAction, and ensure any overridden methods (e.g., the coordinate
calculation or draw method) call super where appropriate to reuse DrawingAction
behavior; update class declaration DrawRectangleOnElement and adjust
imports/signature to match DrawingAction contract.

In
`@2d_drawing_in_region/src/main/java/com/testsigma/addons/web/DrawRectangleOnShadowElement.java`:
- Around line 48-51: The numeric parsing for xPercentage, yPercentage, width,
and height in DrawRectangleOnShadowElement is unvalidated and can throw
NumberFormatException; update this by delegating start-coordinate parsing to
getPointFromString (from DrawingAction) for xPercentage/yPercentage, and wrap
Integer.parseInt for width and height in explicit validation that catches
NumberFormatException and throws or reports a clear, specific error (e.g.,
"Malformed width" / "Malformed height") instead of the generic exception; ensure
the new validation surfaces user-facing messages (or throws a descriptive
IllegalArgumentException) so the existing generic handler no longer hides
malformed-input causes.
- Line 23: The class DrawRectangleOnShadowElement currently extends WebAction
and duplicates coordinate calculation logic; change its inheritance to extend
DrawingAction so it reuses getPointFromString and retrieveRelativePoints
(removing the duplicated coordinate calc), update the class signature to extend
DrawingAction, and replace direct coordinate parsing/validation with calls to
getPointFromString/retrieveRelativePoints to leverage centralized input
validation and error messages (ensure method names DrawRectangleOnShadowElement,
getPointFromString, retrieveRelativePoints are used).

In `@2d_drawing_in_region/src/main/resources/testsigma-sdk.properties`:
- Line 1: Remove the hardcoded credential value under the testsigma-sdk.api.key
property and replace it with an environment-backed placeholder (e.g.,
${TESTSIGMA_SDK_API_KEY}), update any code/config that reads
testsigma-sdk.api.key to load from the environment (or your secret manager)
instead of the file, revoke the exposed JWT immediately and generate a new
secret, and ensure the properties file (or at least the key value) is excluded
from source control by adding it to .gitignore or converting this file to a
template/example version checked into the repo.
🧹 Nitpick comments (2)
2d_drawing_in_region/pom.xml (1)

42-46: TestNG dependency missing <scope>test</scope> and is outdated.

TestNG 6.14.3 (from 2018) lacks <scope>test</scope>, so it will be bundled into the shaded production JAR. If it's only used for tests, scope it accordingly. Also consider upgrading to a maintained version (7.x).

Proposed fix
         <dependency>
             <groupId>org.testng</groupId>
             <artifactId>testng</artifactId>
             <version>6.14.3</version>
+            <scope>test</scope>
         </dependency>
2d_drawing_in_region/src/main/java/com/testsigma/addons/web/DrawPolygonOnShadowElement.java (1)

33-71: Consider extracting shared polygon-drawing logic into the base class.

The execute() body here is nearly identical to DrawPolygonOnElement.execute() — the only difference is how the target element is resolved (direct vs. Shadow DOM). Extracting the shared validation, polygon-closing, and drawing loop into a helper method on DrawingAction (accepting a list of points) would reduce duplication and make future fixes apply in one place (e.g., the off-by-one bug above had to be flagged in both files).

Comment on lines +48 to +52
double y = Double.parseDouble(yStr);
int relativeX = (int) ((x * elementRect.getWidth() / 100) + elementRect.getX());
int relativeY = (int) ((y * elementRect.getHeight() / 100) + elementRect.getY());
logger.info("Retrieved..");
return new Point(relativeX, relativeY);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🌐 Web query:

Selenium 4.14 Actions moveToLocation method documentation absolute coordinates

💡 Result:

In Selenium Java 4.14, Actions.moveToLocation(int xCoordinate, int yCoordinate) moves the mouse to absolute pixel coordinates in the viewport (top-left of the visible page area), not relative to the current pointer position. Coordinates increase right (X) and down (Y). If the target point is outside the viewport, Selenium throws MoveTargetOutOfBoundsException. [1]

This is consistent with Selenium’s W3C Actions “absolute” pointer move concept where the origin is the viewport (e.g., PointerInput.Origin.viewport()). [2]

Docs:

  • Javadoc (Actions#moveToLocation) [1]
  • Actions API “Mouse actions” (viewport-origin pointer moves) [2]

Sources
[1] Selenium Javadoc – org.openqa.selenium.interactions.Actions#moveToLocation https://www.selenium.dev/selenium/docs/api/java/org/openqa/selenium/interactions/Actions.html
[2] Selenium Documentation – Mouse actions (Actions API) https://www.selenium.dev/documentation/webdriver/actions_api/mouse/


🏁 Script executed:

# Check if moveToLocation is called in the codebase
rg "moveToLocation" -A 2 -B 2

# Also check the imports and overall structure of DrawingAction.java
cat -n 2d_drawing_in_region/src/main/java/com/testsigma/addons/web/DrawingAction.java | head -60

Repository: testsigmahq/testsigma-addons

Length of output: 1722


Fix coordinate system mismatch in getPointFromString.

The code computes absolute page coordinates by adding elementRect.getX() and elementRect.getY(), but Actions.moveToLocation(int x, int y) expects viewport-relative coordinates (origin at top-left of the visible area), not page-absolute coordinates. If the element is scrolled beyond the visible viewport, these coordinates will target the wrong position on-screen. The method will also throw MoveTargetOutOfBoundsException if coordinates fall outside the viewport.

Either adjust coordinates to be viewport-relative (by subtracting scroll offsets) or verify that the coordinates are already in the correct system before being passed to moveToLocation.

🤖 Prompt for AI Agents
In
`@2d_drawing_in_region/src/main/java/com/testsigma/addons/web/DrawingAction.java`
around lines 48 - 52, getPointFromString currently builds page-absolute
coordinates by adding elementRect.getX()/getY(), but Actions.moveToLocation
expects viewport-relative coordinates; update getPointFromString (or its caller)
to convert to viewport coordinates by subtracting the page scroll/viewport
offset (e.g., use window scrollX/scrollY or driver.executeScript to get scroll
offsets) from the computed absolute x/y before returning the Point, or
alternatively detect and validate the coordinate system and throw/adjust if the
resulting point is outside the viewport to prevent
MoveTargetOutOfBoundsException; refer to getPointFromString, elementRect.getX(),
elementRect.getY(), elementRect.getWidth()/getHeight(), and
Actions.moveToLocation when making this change.

Comment on lines +41 to +44
if (xyPairs.size() < 2) {
setRuntimeErrorMessage(String.format("Provided positions are %s, minimum 3 positions are" +
" required to draw polygon", xyPairs.size()));
throw new RuntimeException("Invalid no of positions");
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Off-by-one: polygon requires at least 3 points, but check allows 2.

The condition xyPairs.size() < 2 permits 2 points through, yet the error message correctly states "minimum 3 positions are required to draw polygon." A polygon by definition needs ≥ 3 vertices.

🐛 Proposed fix
-            if (xyPairs.size() < 2) {
+            if (xyPairs.size() < 3) {
📝 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
if (xyPairs.size() < 2) {
setRuntimeErrorMessage(String.format("Provided positions are %s, minimum 3 positions are" +
" required to draw polygon", xyPairs.size()));
throw new RuntimeException("Invalid no of positions");
if (xyPairs.size() < 3) {
setRuntimeErrorMessage(String.format("Provided positions are %s, minimum 3 positions are" +
" required to draw polygon", xyPairs.size()));
throw new RuntimeException("Invalid no of positions");
🤖 Prompt for AI Agents
In
`@2d_drawing_in_region/src/main/java/com/testsigma/addons/web/DrawPolygonOnElement.java`
around lines 41 - 44, The size check currently allows two points because it uses
xyPairs.size() < 2; update the validation in DrawPolygonOnElement to require at
least three points by changing the condition to xyPairs.size() < 3, keep the
existing setRuntimeErrorMessage call and RuntimeException throw (or adjust the
exception text to match the "minimum 3 positions" message) so the check and
message are consistent; reference xyPairs, setRuntimeErrorMessage and the
RuntimeException in your change.

setSuccessMessage("Successfully drawn the polygon using the given positions on the element");
} catch (MoveTargetOutOfBoundsException e) {
logger.info("Invalid locations raised :" + ExceptionUtils.getStackTrace(e));
setErrorMessage("The positions are not with in the element");
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Typo: "not with in" → "not within".

Proposed fix
-            setErrorMessage("The positions are not with in the element");
+            setErrorMessage("The positions are not within the element");
📝 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
setErrorMessage("The positions are not with in the element");
setErrorMessage("The positions are not within the element");
🤖 Prompt for AI Agents
In
`@2d_drawing_in_region/src/main/java/com/testsigma/addons/web/DrawPolygonOnElement.java`
at line 55, Update the error message string in DrawPolygonOnElement to correct
the typo: replace "The positions are not with in the element" with "The
positions are not within the element" (locate the call to setErrorMessage in the
DrawPolygonOnElement class and update the message text).

Comment on lines +46 to +48
if (xyPairs.size() < 2) {
setRuntimeErrorMessage(String.format("Provided positions are %s, minimum 3 positions are required to draw polygon", xyPairs.size()));
throw new RuntimeException("Invalid no of positions");
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Same off-by-one bug: polygon requires at least 3 points, but check allows 2.

Identical to DrawPolygonOnElement — the condition should be < 3.

🐛 Proposed fix
-            if (xyPairs.size() < 2) {
+            if (xyPairs.size() < 3) {
📝 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
if (xyPairs.size() < 2) {
setRuntimeErrorMessage(String.format("Provided positions are %s, minimum 3 positions are required to draw polygon", xyPairs.size()));
throw new RuntimeException("Invalid no of positions");
if (xyPairs.size() < 3) {
setRuntimeErrorMessage(String.format("Provided positions are %s, minimum 3 positions are required to draw polygon", xyPairs.size()));
throw new RuntimeException("Invalid no of positions");
🤖 Prompt for AI Agents
In
`@2d_drawing_in_region/src/main/java/com/testsigma/addons/web/DrawPolygonOnShadowElement.java`
around lines 46 - 48, The validation in DrawPolygonOnShadowElement incorrectly
allows only two points by checking if (xyPairs.size() < 2); update the guard to
require at least three points (change the condition to < 3), and keep the
existing runtime error path (setRuntimeErrorMessage and throwing
RuntimeException) so invalid input still logs and fails; look for the
xyPairs.size() check inside the DrawPolygonOnShadowElement class/method and
modify it accordingly.

applicationType = ApplicationType.WEB

)
public class DrawRectangleOnElement extends WebAction {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major

Same inconsistency: extends WebAction instead of DrawingAction.

Same issue as DrawRectangleOnShadowElement — this duplicates coordinate logic. Extend DrawingAction for consistency.

Proposed fix
-public class DrawRectangleOnElement extends WebAction {
+public class DrawRectangleOnElement extends DrawingAction {
📝 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
public class DrawRectangleOnElement extends WebAction {
public class DrawRectangleOnElement extends DrawingAction {
🤖 Prompt for AI Agents
In
`@2d_drawing_in_region/src/main/java/com/testsigma/addons/web/DrawRectangleOnElement.java`
at line 24, The class DrawRectangleOnElement currently extends WebAction (same
as DrawRectangleOnShadowElement) causing duplicated coordinate logic; change its
base class to extend DrawingAction instead of WebAction, migrate or remove any
duplicated coordinate-handling code so it uses the shared logic in
DrawingAction, and ensure any overridden methods (e.g., the coordinate
calculation or draw method) call super where appropriate to reuse DrawingAction
behavior; update class declaration DrawRectangleOnElement and adjust
imports/signature to match DrawingAction contract.

" x: %s, y:%s", startX, startY));
} catch (MoveTargetOutOfBoundsException e) {
logger.info("Invalid locations raised :" + ExceptionUtils.getStackTrace(e));
setErrorMessage("The positions are not with in the element");
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Typo in error message: "not with in" → "not within".

This same typo also appears in DrawLineOnElement (line 54).

Proposed fix
-            setErrorMessage("The positions are not with in the element");
+            setErrorMessage("The positions are not within the element");
📝 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
setErrorMessage("The positions are not with in the element");
setErrorMessage("The positions are not within the element");
🤖 Prompt for AI Agents
In
`@2d_drawing_in_region/src/main/java/com/testsigma/addons/web/DrawRectangleOnElement.java`
at line 62, Update the typo in the error text passed to setErrorMessage: change
"The positions are not with in the element" to "The positions are not within the
element" in DrawRectangleOnElement (method that calls setErrorMessage) and make
the identical correction in DrawLineOnElement where the same setErrorMessage
string is used; ensure both occurrences use the single-word "within".

@Action(actionText = "Drawing: Draw a Rectangle on the shadow DOM element with host element-locator and shadow DOM CSS locator shadow-dom-css-locator with dimensions Length: Test-Data1 , Breadth: Test-Data2 and start position (x1, y1) (Position Format: Percentage of element width, Percentage of element height, Ex: 40,60)",
description = "Drawing a rectangle on the element inside Shadow DOM: use host element and shadow DOM CSS locator to find the target, then draw based on dimensions and position",
applicationType = ApplicationType.WEB)
public class DrawRectangleOnShadowElement extends WebAction {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major

Inconsistent inheritance: extends WebAction instead of DrawingAction.

DrawLineOnShadowElement and DrawPolygonOnShadowElement extend DrawingAction, but this class extends WebAction directly, duplicating the coordinate calculation logic (lines 48–55). This should extend DrawingAction for consistency and to reuse getPointFromString / retrieveRelativePoints, which also provide better input-validation error messages.

Proposed fix
-public class DrawRectangleOnShadowElement extends WebAction {
+public class DrawRectangleOnShadowElement extends DrawingAction {
📝 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
public class DrawRectangleOnShadowElement extends WebAction {
public class DrawRectangleOnShadowElement extends DrawingAction {
🤖 Prompt for AI Agents
In
`@2d_drawing_in_region/src/main/java/com/testsigma/addons/web/DrawRectangleOnShadowElement.java`
at line 23, The class DrawRectangleOnShadowElement currently extends WebAction
and duplicates coordinate calculation logic; change its inheritance to extend
DrawingAction so it reuses getPointFromString and retrieveRelativePoints
(removing the duplicated coordinate calc), update the class signature to extend
DrawingAction, and replace direct coordinate parsing/validation with calls to
getPointFromString/retrieveRelativePoints to leverage centralized input
validation and error messages (ensure method names DrawRectangleOnShadowElement,
getPointFromString, retrieveRelativePoints are used).

Comment on lines +48 to +51
double x = Double.parseDouble(xPercentage.getValue().toString());
double y = Double.parseDouble(yPercentage.getValue().toString());
int boxWidth = Integer.parseInt(width.getValue().toString());
int boxHeight = Integer.parseInt(height.getValue().toString());
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Missing input validation for numeric parsing.

Double.parseDouble and Integer.parseInt will throw NumberFormatException if the user supplies non-numeric values. This is only caught by the generic Exception handler (line 66), which gives the vague message "Unable to generate the rectangle on shadow DOM element" instead of telling the user about malformed input. If you extend DrawingAction, you can delegate to getPointFromString for the start coordinates and add similar validation for width/height.

🤖 Prompt for AI Agents
In
`@2d_drawing_in_region/src/main/java/com/testsigma/addons/web/DrawRectangleOnShadowElement.java`
around lines 48 - 51, The numeric parsing for xPercentage, yPercentage, width,
and height in DrawRectangleOnShadowElement is unvalidated and can throw
NumberFormatException; update this by delegating start-coordinate parsing to
getPointFromString (from DrawingAction) for xPercentage/yPercentage, and wrap
Integer.parseInt for width and height in explicit validation that catches
NumberFormatException and throws or reports a clear, specific error (e.g.,
"Malformed width" / "Malformed height") instead of the generic exception; ensure
the new validation surfaces user-facing messages (or throws a descriptive
IllegalArgumentException) so the existing generic handler no longer hides
malformed-input causes.

@@ -0,0 +1 @@
testsigma-sdk.api.key=eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIzMmYwYTg1MC02NjMyLWIyN2ItOTBhYS1jZDkwMDcwNzRlMWUiLCJ1bmlxdWVJZCI6Ijc4IiwiaWRlbnRpdHlBY2NvdW50VVVJZCI6ImZlMmEzOGNiLThiODktNzdhNC04OTRiLTgwZjNiOWEzNzEzZSJ9.dlqB2YZsrCLNXozVRaubJ_ate5dx6JriR6DSaIgVAKwAdmJklmmSqbBFjohQyKlxNNRgTDWgQTIMbJa9_MXbBQ No newline at end of file
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🚨 API key / secret committed to a public repository.

This JWT is a credential (testsigma-sdk.api.key) that grants access to the Testsigma platform. Committing it to a public repo exposes the associated account to unauthorized use. The key should be revoked immediately and replaced with an environment variable or secret-management mechanism (e.g., ${TESTSIGMA_SDK_API_KEY}). Add this file (or at minimum the key value) to .gitignore or use a template file instead.

🤖 Prompt for AI Agents
In `@2d_drawing_in_region/src/main/resources/testsigma-sdk.properties` at line 1,
Remove the hardcoded credential value under the testsigma-sdk.api.key property
and replace it with an environment-backed placeholder (e.g.,
${TESTSIGMA_SDK_API_KEY}), update any code/config that reads
testsigma-sdk.api.key to load from the environment (or your secret manager)
instead of the file, revoke the exposed JWT immediately and generate a new
secret, and ensure the properties file (or at least the key value) is excluded
from source control by adding it to .gitignore or converting this file to a
template/example version checked into the repo.

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.

4 participants