[CUS-10544] added support to shadow dom elements for existing addon.#333
[CUS-10544] added support to shadow dom elements for existing addon.#333ManojTestsigma wants to merge 1 commit intodevfrom
Conversation
|
|
📝 WalkthroughWalkthroughIntroduces 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
Sequence DiagramsequenceDiagram
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
⚔️ Resolve merge conflicts (beta)
Warning Review ran into problems🔥 ProblemsGit: Failed to clone repository. Please run the 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. Comment |
There was a problem hiding this comment.
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 toDrawPolygonOnElement.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 onDrawingAction(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).
| 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); |
There was a problem hiding this comment.
🧩 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 -60Repository: 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.
| 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"); |
There was a problem hiding this comment.
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.
| 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"); |
There was a problem hiding this comment.
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.
| 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).
| 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"); |
There was a problem hiding this comment.
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.
| 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 { |
There was a problem hiding this comment.
🛠️ 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.
| 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"); |
There was a problem hiding this comment.
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.
| 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 { |
There was a problem hiding this comment.
🛠️ 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.
| 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).
| 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()); |
There was a problem hiding this comment.
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 | |||
There was a problem hiding this comment.
🚨 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.
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