Repository navigation
Cus 11221 - #357
Cus 11221#357
Conversation
📝 WalkthroughWalkthroughThis PR enhances the base64_converter module with updated annotations and refined URL-safe Base64 decoding logic featuring automatic detection and fallback mechanisms. It introduces a new mouseover_actions module providing OCR-based mouse-over functionality for web and mobile-web platforms, including text detection at specific occurrences. Changes
Sequence DiagramsequenceDiagram
participant User
participant OCRAction as MouseOver Action
participant WebDriver
participant OCR
participant SeleniumActions as Selenium Actions
User->>OCRAction: Trigger mouse-over on text (with/without occurrence)
OCRAction->>WebDriver: Capture screenshot
WebDriver-->>OCRAction: Screenshot image
OCRAction->>OCR: Run OCR on screenshot
OCR-->>OCRAction: List of OCRTextPoints (text regions)
OCRAction->>OCRAction: Find matching text point<br/>(exact/case-insensitive/contains)
alt Text found
OCRAction->>OCRAction: Calculate center coordinates<br/>of text bounding box
OCRAction->>SeleniumActions: Move mouse to coordinates
SeleniumActions->>WebDriver: Execute mouse action
WebDriver-->>SeleniumActions: Action complete
SeleniumActions-->>OCRAction: Success
OCRAction-->>User: SUCCESS
else Text not found
OCRAction-->>User: FAILED (text not found)
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
📝 Coding Plan
Warning Review ran into problems🔥 ProblemsGit: Failed to clone repository. Please run the 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 Tip CodeRabbit can scan for known vulnerabilities in your dependencies using OSV Scanner.OSV Scanner will automatically detect and report security vulnerabilities in your project's dependencies. No additional configuration is required. |
There was a problem hiding this comment.
Actionable comments posted: 6
🧹 Nitpick comments (3)
mouseover_actions/src/main/java/com/testsigma/addons/mobileweb/MouseOverOnTextAtOccurrence.java (1)
84-94: Redundant condition in text matching.The condition
text.equals(tp.getText()) || text.equalsIgnoreCase(tp.getText())is redundant. Ifequals()returns true,equalsIgnoreCase()will also return true. Simplify to just useequalsIgnoreCase().♻️ Suggested fix
private OCRTextPoint findTextPointAtOccurrence(List<OCRTextPoint> textPoints, String text, int targetOccurrence) { if (textPoints == null) return null; int currentOccurrence = 0; for (OCRTextPoint tp : textPoints) { - if (text.equals(tp.getText()) || text.equalsIgnoreCase(tp.getText())) { + if (text.equalsIgnoreCase(tp.getText())) { currentOccurrence++; if (currentOccurrence == targetOccurrence) return tp; } } return null; }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@mouseover_actions/src/main/java/com/testsigma/addons/mobileweb/MouseOverOnTextAtOccurrence.java` around lines 84 - 94, The loop in findTextPointAtOccurrence redundantly checks text.equals(tp.getText()) || text.equalsIgnoreCase(tp.getText()); replace that compound check with a single case-insensitive comparison (use text.equalsIgnoreCase(tp.getText())) to simplify the logic and avoid redundancy, keeping the rest of the method (null check for textPoints, occurrence counting and return behavior) unchanged.mouseover_actions/src/main/java/com/testsigma/addons/web/MouseOverOnText.java (1)
1-89: Consider extracting shared logic to reduce duplication.The
MouseOverOnTextimplementations for WEB and MOBILE_WEB are nearly identical, differing only inapplicationType. Consider extracting the shared logic (screenshot capture, OCR processing, coordinate calculation, and helper methods) into a common base class or utility to reduce maintenance burden and ensure consistency.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@mouseover_actions/src/main/java/com/testsigma/addons/web/MouseOverOnText.java` around lines 1 - 89, The WEB and MOBILE_WEB action classes duplicate the same OCR+mouse-over logic; extract the shared behavior into a common base class or utility and have both action classes delegate to it. Move the screenshot capture, OCR extraction and parsing, coordinate calculation, and helper methods (currently in execute(), findTextPoint(), logAvailableTextPoints()) into a new abstract class or helper (e.g., AbstractMouseOverOnText.performMouseOver(targetText, driver, ocr) or instance methods findTextPoint(...) and logAvailableTextPoints(...) there), keep only Action-specific annotations and applicationType in the concrete MouseOverOnText and MOBILE_WEB classes, and have their execute() call the shared method and translate results into setSuccessMessage/setErrorMessage as needed.mouseover_actions/src/main/java/com/testsigma/addons/web/MouseOverOnTextAtOccurrence.java (1)
84-94: Simplify redundant matching condition.The condition
text.equals(tp.getText()) || text.equalsIgnoreCase(tp.getText())is redundant. Ifequals()returns true,equalsIgnoreCase()will also return true, so the effective behavior is just case-insensitive matching. Additionally,countMatches(line 100) uses onlyequalsIgnoreCase, creating inconsistency.♻️ Proposed simplification
private OCRTextPoint findTextPointAtOccurrence(List<OCRTextPoint> textPoints, String text, int targetOccurrence) { if (textPoints == null) return null; int currentOccurrence = 0; for (OCRTextPoint tp : textPoints) { - if (text.equals(tp.getText()) || text.equalsIgnoreCase(tp.getText())) { + if (text.equalsIgnoreCase(tp.getText())) { currentOccurrence++; if (currentOccurrence == targetOccurrence) return tp; } } return null; }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@mouseover_actions/src/main/java/com/testsigma/addons/web/MouseOverOnTextAtOccurrence.java` around lines 84 - 94, The matching in findTextPointAtOccurrence uses a redundant check (text.equals(...) || text.equalsIgnoreCase(...)) and is inconsistent with countMatches which uses equalsIgnoreCase; change findTextPointAtOccurrence to perform a single case-insensitive comparison (use equalsIgnoreCase) between text and tp.getText() so both methods consistently use case-insensitive matching; update only the comparison in the findTextPointAtOccurrence method to use equalsIgnoreCase on the same operands (preserve null-safety if needed).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In
`@base64_converter/src/main/java/com/testsigma/addons/generators/DecodeStringToBase64.java`:
- Around line 10-12: Rename the class DecodeStringToBase64 to
DecodeBase64ToString and update the
`@com.testsigma.sdk.annotation.TestDataFunction` annotation on that class to use
displayName = "Decode the input base64 string to plain text" and description =
"Decodes the input base64 string to plain text"; ensure any references to the
old class name (e.g., in tests or registration code) are updated to the new
class name DecodeBase64ToString so the runtime picks up the corrected name and
description.
In
`@mouseover_actions/src/main/java/com/testsigma/addons/mobileweb/MouseOverOnText.java`:
- Around line 56-57: The Actions call in MouseOverOnText (and similarly in
MouseOverOnTextAtOccurrence) uses a non-existent method moveToLocation; replace
it with a valid Selenium Actions API such as moveByOffset or moveToElement with
offsets: obtain the target WebElement (or reference origin) and call
Actions.moveToElement(element, xOffset, yOffset).perform() or
Actions.moveByOffset(x, y).perform() as appropriate, ensuring you compute
offsets from a known element or the current pointer before performing the
action; update the code in class MouseOverOnText to use the correct Actions
method and adjust any coordinate calculations accordingly.
- Around line 68-80: The findTextPoint method can NPE when tp.getText() is null;
update the method (findTextPoint) to null-check tp.getText() before calling
equals/equalsIgnoreCase/toLowerCase or otherwise compare safely (e.g., retrieve
String txt = tp.getText(); if (txt == null) continue; then use
txt.equals(targetText), txt.equalsIgnoreCase(targetText), and
txt.toLowerCase().contains(targetText.toLowerCase())) so all comparisons skip
null text values.
In
`@mouseover_actions/src/main/java/com/testsigma/addons/web/MouseOverOnText.java`:
- Around line 56-57: The call to Actions.moveToLocation is invalid and will
throw at runtime; replace it in MouseOverOnText.java where you create Actions
actions = new Actions(driver) by using a valid Actions API such as
moveByOffset(x, y) or moveToElement(targetElement, xOffset, yOffset) (depending
on whether you have an element to target) and then call perform(); ensure you
import and use org.openqa.selenium.interactions.Actions and pass the correct
offsets or element reference instead of moveToLocation.
In
`@mouseover_actions/src/main/java/com/testsigma/addons/web/MouseOverOnTextAtOccurrence.java`:
- Around line 49-53: The call to ocr.extractTextFromImage(ocrImage) may return
null and cause a NullPointerException when logger.info uses textPoints.size();
update the flow in MouseOverOnTextAtOccurrence (around variables screenshot,
ocrImage, textPoints) to null-guard the result of OCR.extractTextFromImage:
check if textPoints is null and replace it with Collections.emptyList() (or
handle the null case explicitly), then log using the safe list size and proceed
so downstream code never dereferences a null textPoints.
In `@mouseover_actions/src/main/resources/testsigma-sdk.properties`:
- Line 1: The committed API secret value for the property key
testsigma-sdk.api.key must be removed from source control; delete the secret
from this file and replace its usage by loading the key from a secure source
(e.g., environment variable or secrets manager) where your runtime reads
process.env.TESTSIGMA_SDK_API_KEY (or equivalent) instead of the file, add this
properties file to .gitignore so it isn't committed, and notify ops/security to
rotate the leaked key immediately if it is real; ensure any code that referenced
testsigma-sdk.api.key is updated to read the new secure configuration source.
---
Nitpick comments:
In
`@mouseover_actions/src/main/java/com/testsigma/addons/mobileweb/MouseOverOnTextAtOccurrence.java`:
- Around line 84-94: The loop in findTextPointAtOccurrence redundantly checks
text.equals(tp.getText()) || text.equalsIgnoreCase(tp.getText()); replace that
compound check with a single case-insensitive comparison (use
text.equalsIgnoreCase(tp.getText())) to simplify the logic and avoid redundancy,
keeping the rest of the method (null check for textPoints, occurrence counting
and return behavior) unchanged.
In
`@mouseover_actions/src/main/java/com/testsigma/addons/web/MouseOverOnText.java`:
- Around line 1-89: The WEB and MOBILE_WEB action classes duplicate the same
OCR+mouse-over logic; extract the shared behavior into a common base class or
utility and have both action classes delegate to it. Move the screenshot
capture, OCR extraction and parsing, coordinate calculation, and helper methods
(currently in execute(), findTextPoint(), logAvailableTextPoints()) into a new
abstract class or helper (e.g.,
AbstractMouseOverOnText.performMouseOver(targetText, driver, ocr) or instance
methods findTextPoint(...) and logAvailableTextPoints(...) there), keep only
Action-specific annotations and applicationType in the concrete MouseOverOnText
and MOBILE_WEB classes, and have their execute() call the shared method and
translate results into setSuccessMessage/setErrorMessage as needed.
In
`@mouseover_actions/src/main/java/com/testsigma/addons/web/MouseOverOnTextAtOccurrence.java`:
- Around line 84-94: The matching in findTextPointAtOccurrence uses a redundant
check (text.equals(...) || text.equalsIgnoreCase(...)) and is inconsistent with
countMatches which uses equalsIgnoreCase; change findTextPointAtOccurrence to
perform a single case-insensitive comparison (use equalsIgnoreCase) between text
and tp.getText() so both methods consistently use case-insensitive matching;
update only the comparison in the findTextPointAtOccurrence method to use
equalsIgnoreCase on the same operands (preserve null-safety if needed).
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: c777a35f-58b9-43d9-9465-7d3b56dba72a
📒 Files selected for processing (9)
base64_converter/pom.xmlbase64_converter/src/main/java/com/testsigma/addons/generators/Base64Converter.javabase64_converter/src/main/java/com/testsigma/addons/generators/DecodeStringToBase64.javamouseover_actions/pom.xmlmouseover_actions/src/main/java/com/testsigma/addons/mobileweb/MouseOverOnText.javamouseover_actions/src/main/java/com/testsigma/addons/mobileweb/MouseOverOnTextAtOccurrence.javamouseover_actions/src/main/java/com/testsigma/addons/web/MouseOverOnText.javamouseover_actions/src/main/java/com/testsigma/addons/web/MouseOverOnTextAtOccurrence.javamouseover_actions/src/main/resources/testsigma-sdk.properties
| @com.testsigma.sdk.annotation.TestDataFunction(displayName = "Decode the input string to base64", | ||
| description = "Decodes the input string to base64") | ||
| public class DecodeStringToBase64 extends TestDataFunction { |
There was a problem hiding this comment.
Misleading class name and description.
The class name DecodeStringToBase64 and description "Decode the input string to base64" are backwards. This function decodes from Base64, not to Base64. Consider renaming to DecodeBase64ToString and updating the description to "Decodes the input base64 string to plain text."
📝 Suggested annotation fix
-@com.testsigma.sdk.annotation.TestDataFunction(displayName = "Decode the input string to base64",
- description = "Decodes the input string to base64")
-public class DecodeStringToBase64 extends TestDataFunction {
+@com.testsigma.sdk.annotation.TestDataFunction(displayName = "Decode the input base64 string to plain text",
+ description = "Decodes the input base64 string to plain text")
+public class DecodeBase64ToString extends TestDataFunction {🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In
`@base64_converter/src/main/java/com/testsigma/addons/generators/DecodeStringToBase64.java`
around lines 10 - 12, Rename the class DecodeStringToBase64 to
DecodeBase64ToString and update the
`@com.testsigma.sdk.annotation.TestDataFunction` annotation on that class to use
displayName = "Decode the input base64 string to plain text" and description =
"Decodes the input base64 string to plain text"; ensure any references to the
old class name (e.g., in tests or registration code) are updated to the new
class name DecodeBase64ToString so the runtime picks up the corrected name and
description.
| Actions actions = new Actions(driver); | ||
| actions.moveToLocation(x, y).perform(); |
There was a problem hiding this comment.
moveToLocation is not a standard Selenium Actions method.
Same issue as in MouseOverOnTextAtOccurrence - this method does not exist in Selenium's Actions class and will fail at runtime.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In
`@mouseover_actions/src/main/java/com/testsigma/addons/mobileweb/MouseOverOnText.java`
around lines 56 - 57, The Actions call in MouseOverOnText (and similarly in
MouseOverOnTextAtOccurrence) uses a non-existent method moveToLocation; replace
it with a valid Selenium Actions API such as moveByOffset or moveToElement with
offsets: obtain the target WebElement (or reference origin) and call
Actions.moveToElement(element, xOffset, yOffset).perform() or
Actions.moveByOffset(x, y).perform() as appropriate, ensuring you compute
offsets from a known element or the current pointer before performing the
action; update the code in class MouseOverOnText to use the correct Actions
method and adjust any coordinate calculations accordingly.
| private OCRTextPoint findTextPoint(List<OCRTextPoint> textPoints, String targetText) { | ||
| if (textPoints == null) return null; | ||
| for (OCRTextPoint tp : textPoints) { | ||
| if (targetText.equals(tp.getText())) return tp; | ||
| } | ||
| for (OCRTextPoint tp : textPoints) { | ||
| if (targetText.equalsIgnoreCase(tp.getText())) return tp; | ||
| } | ||
| for (OCRTextPoint tp : textPoints) { | ||
| if (tp.getText().toLowerCase().contains(targetText.toLowerCase())) return tp; | ||
| } | ||
| return null; | ||
| } |
There was a problem hiding this comment.
Potential NPE if OCR returns null text.
The findTextPoint method does not guard against tp.getText() being null. If OCR returns a text point with null text, this will throw a NullPointerException on line 77 when calling tp.getText().toLowerCase().
🛡️ Suggested null guard
private OCRTextPoint findTextPoint(List<OCRTextPoint> textPoints, String targetText) {
if (textPoints == null) return null;
for (OCRTextPoint tp : textPoints) {
+ if (tp.getText() == null) continue;
if (targetText.equals(tp.getText())) return tp;
}
for (OCRTextPoint tp : textPoints) {
+ if (tp.getText() == null) continue;
if (targetText.equalsIgnoreCase(tp.getText())) return tp;
}
for (OCRTextPoint tp : textPoints) {
+ if (tp.getText() == null) continue;
if (tp.getText().toLowerCase().contains(targetText.toLowerCase())) return tp;
}
return null;
}🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In
`@mouseover_actions/src/main/java/com/testsigma/addons/mobileweb/MouseOverOnText.java`
around lines 68 - 80, The findTextPoint method can NPE when tp.getText() is
null; update the method (findTextPoint) to null-check tp.getText() before
calling equals/equalsIgnoreCase/toLowerCase or otherwise compare safely (e.g.,
retrieve String txt = tp.getText(); if (txt == null) continue; then use
txt.equals(targetText), txt.equalsIgnoreCase(targetText), and
txt.toLowerCase().contains(targetText.toLowerCase())) so all comparisons skip
null text values.
| Actions actions = new Actions(driver); | ||
| actions.moveToLocation(x, y).perform(); |
There was a problem hiding this comment.
moveToLocation is not a standard Selenium Actions method.
Same issue as in the mobile web variants - this method does not exist and will cause runtime failure.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In
`@mouseover_actions/src/main/java/com/testsigma/addons/web/MouseOverOnText.java`
around lines 56 - 57, The call to Actions.moveToLocation is invalid and will
throw at runtime; replace it in MouseOverOnText.java where you create Actions
actions = new Actions(driver) by using a valid Actions API such as
moveByOffset(x, y) or moveToElement(targetElement, xOffset, yOffset) (depending
on whether you have an element to target) and then call perform(); ensure you
import and use org.openqa.selenium.interactions.Actions and pass the correct
offsets or element reference instead of moveToLocation.
| File screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); | ||
| OCRImage ocrImage = new OCRImage(); | ||
| ocrImage.setOcrImageFile(screenshot); | ||
| List<OCRTextPoint> textPoints = ocr.extractTextFromImage(ocrImage); | ||
| logger.info("Extracted " + textPoints.size() + " text points from screenshot"); |
There was a problem hiding this comment.
Potential NullPointerException if OCR returns null.
If ocr.extractTextFromImage() returns null, line 53 will throw NPE when calling textPoints.size(). The helper methods have null guards, but the main flow fails before reaching them.
🛡️ Proposed fix to add null check
File screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
OCRImage ocrImage = new OCRImage();
ocrImage.setOcrImageFile(screenshot);
List<OCRTextPoint> textPoints = ocr.extractTextFromImage(ocrImage);
+ if (textPoints == null) {
+ setErrorMessage("OCR extraction returned no results");
+ return Result.FAILED;
+ }
logger.info("Extracted " + textPoints.size() + " text points from screenshot");🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In
`@mouseover_actions/src/main/java/com/testsigma/addons/web/MouseOverOnTextAtOccurrence.java`
around lines 49 - 53, The call to ocr.extractTextFromImage(ocrImage) may return
null and cause a NullPointerException when logger.info uses textPoints.size();
update the flow in MouseOverOnTextAtOccurrence (around variables screenshot,
ocrImage, textPoints) to null-guard the result of OCR.extractTextFromImage:
check if textPoints is null and replace it with Collections.emptyList() (or
handle the null case explicitly), then log using the safe list size and proceed
so downstream code never dereferences a null textPoints.
| @@ -0,0 +1 @@ | |||
| testsigma-sdk.api.key=eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIyNDBkMjhiNS0xNmUwLThlNmYtOWQ0ZS05MjYxMGNiZTcyYzciLCJ1bmlxdWVJZCI6IjYwODEiLCJpZGVudGl0eUFjY291bnRVVUlkIjoiMzUifQ.7_DxrELh3EoBszb2A3GC_EoKr5hPXIK9lqBudKbr4nT3r2lPmnyXqpckh3dfUUA2gPk3f8f_sN2-FtCbx7xQ7A No newline at end of file | |||
There was a problem hiding this comment.
Critical: Remove API key from source control.
Committing API keys or secrets to version control is a security risk. This key will persist in git history even if removed later. Use environment variables or a secrets manager instead, and add this file to .gitignore.
If this key is real, rotate it immediately after removing from the repository.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@mouseover_actions/src/main/resources/testsigma-sdk.properties` at line 1, The
committed API secret value for the property key testsigma-sdk.api.key must be
removed from source control; delete the secret from this file and replace its
usage by loading the key from a secure source (e.g., environment variable or
secrets manager) where your runtime reads process.env.TESTSIGMA_SDK_API_KEY (or
equivalent) instead of the file, add this properties file to .gitignore so it
isn't committed, and notify ops/security to rotate the leaked key immediately if
it is real; ensure any code that referenced testsigma-sdk.api.key is updated to
read the new secure configuration source.
please review this addon and publish as PUBLIC
Addon name : mouseover_actions
Addon accont: https://jarvis.testsigma.com/ui/tenants/2817/addons
Jira: https://testsigma.atlassian.net/browse/CUS-11221
fix
Mouse overs on the given target text based on occurence position..
Summary by CodeRabbit
New Features
Bug Fixes
Chores